Fix (and rename) parser smoke test

This commit is contained in:
Henri DF 2016-05-04 17:07:52 -07:00
parent 9dd4e799cb
commit f6c8c4cb84
2 changed files with 6 additions and 30 deletions

View File

@ -15,16 +15,15 @@ function error_exit_bad
function good function good
{ {
lua5.1 test.lua "a: x.y=1; b: a and z.x exists; c: b; $1" 2> /dev/null || error_exit_good "$1" lua5.1 test.lua "$1" 2> /dev/null || error_exit_good "$1"
} }
function bad function bad
{ {
lua5.1 test.lua "a: x.y=1; b: a and z.x exists; c: b; $1" 2> /dev/null && error_exit_bad "$1" lua5.1 test.lua "$1" 2> /dev/null && error_exit_bad "$1"
} }
# Filters # Filters
good " "
good " a" good " a"
good "a and b" good "a and b"
good "#a and b; a and b" good "#a and b; a and b"
@ -45,7 +44,7 @@ good "not not a"
good "(not not a)" good "(not not a)"
good "not a.b=1" good "not a.b=1"
good "not a.a exists" good "not a.a exists"
good "notz: a and b; notz" good "notz and a and b"
good "a.b = bla" good "a.b = bla"
good "a.b = 'bla'" good "a.b = 'bla'"
good "a.b = not" good "a.b = not"
@ -62,33 +61,10 @@ good "evt.arg[0] contains /bin"
bad "evt.arg[a] contains /bin" bad "evt.arg[a] contains /bin"
bad "evt.arg[] contains /bin" bad "evt.arg[] contains /bin"
bad "a.g in ()"
bad "a.b = b = 1" bad "a.b = b = 1"
bad "(a.b = 1" bad "(a.b = 1"
# Macros
good "a: a.b exists"
good "a: b and c"
good "a: b"
good "a : b"
good "a : evt.dir=>"
good "inbound: (syscall.type=listen and evt.dir='>') or (syscall.type=accept and evt.dir='<')"
bad "a:"
bad "b and d"
# Outputs
good "a.b = a.a |"
good "a.b = a.a | %evt.type %fd.num blabla"
good "a.b = a.a | blabla (%evt.type %fd.num)"
good "a.b = a.a | f(evt)"
good "a.b = a.a | f()"
bad "a.b = a.a | f() evt"
bad "a : b | bla"
bad " | %a.b"
echo echo
echo "All tests passed." echo "All tests passed."
exit 0 exit 0

View File

@ -1,4 +1,4 @@
local compiler = require "compiler" local parser = require "parser"
if #arg ~= 1 then if #arg ~= 1 then
print("Usage: test.lua <string>") print("Usage: test.lua <string>")
@ -9,7 +9,7 @@ local macros = {}
local ast local ast
local function doit(line) local function doit(line)
ast = compiler.compile_line(line, macros) ast = parser.parse_filter(line)
if not ast then if not ast then
print("error", error_msg) print("error", error_msg)
@ -22,7 +22,7 @@ for str in string.gmatch(arg[1], "([^;]+)") do
end end
if (ast and ast.type) then if (ast and ast.type) then
compiler.parser.print_ast(ast) parser.print_ast(ast)
end end
os.exit(0) os.exit(0)