aboutsummaryrefslogtreecommitdiff
path: root/testerrors.lua
diff options
context:
space:
mode:
Diffstat (limited to 'testerrors.lua')
-rw-r--r--testerrors.lua38
1 files changed, 17 insertions, 21 deletions
diff --git a/testerrors.lua b/testerrors.lua
index 010f111..d39b8b9 100644
--- a/testerrors.lua
+++ b/testerrors.lua
@@ -4,17 +4,23 @@ function testerror(repatt, msg)
4 msg = msg:match("^%s*(.-)%s*$") -- trim 4 msg = msg:match("^%s*(.-)%s*$") -- trim
5 local ok, err = pcall(function () re.compile(repatt) end) 5 local ok, err = pcall(function () re.compile(repatt) end)
6 assert(not ok) 6 assert(not ok)
7 err = err:match("^[^\n]*\n(.-)$") -- remove first line (filename) 7 if msg:match("^[^\n]*\n(.-)$") then
8 err = err:gsub("[ \t]*\n", "\n") -- remove trailing spaces 8 -- expecting a syntax error
9 -- if err ~= msg then 9 err = err:match("^[^\n]*\n(.-)$") -- remove first line (filename)
10 -- print(#err, #msg) 10 err = err:gsub("[ \t]*\n", "\n") -- remove trailing spaces
11 -- print('--') 11 -- if err ~= msg then
12 -- print(err) 12 -- print(#err, #msg)
13 -- print('--') 13 -- print('--')
14 -- print(msg) 14 -- print(err)
15 -- print('--') 15 -- print('--')
16 -- end 16 -- print(msg)
17 assert(err == msg) 17 -- print('--')
18 -- end
19 assert(err == msg)
20 else
21 -- expecting a non-syntax error
22 assert(err:match(msg))
23 end
18end 24end
19 25
20testerror([[~]], [[ 26testerror([[~]], [[
@@ -483,16 +489,10 @@ testerror([[
483 A <- 'and again' 489 A <- 'and again'
484]], [[ 490]], [[
485name 'nosuch' undefined 491name 'nosuch' undefined
486name 'def' undefined
487'A' already defined as a rule
488'A' already defined as a rule
489]]) 492]])
490 493
491testerror([[names not in grammar]], [[ 494testerror([[names not in grammar]], [[
492rule 'names' used outside a grammar 495rule 'names' used outside a grammar
493rule 'not' used outside a grammar
494rule 'in' used outside a grammar
495rule 'grammar' used outside a grammar
496]]) 496]])
497 497
498testerror([[ 498testerror([[
@@ -501,16 +501,12 @@ testerror([[
501 A <- 'and again' 501 A <- 'and again'
502]], [[ 502]], [[
503name 'nosuch' undefined 503name 'nosuch' undefined
504name 'def' undefined
505'A' already defined as a rule
506'A' already defined as a rule
507]]) 504]])
508 505
509testerror([[ A <- %nosuch ('error' ]], [[ 506testerror([[ A <- %nosuch ('error' ]], [[
510L1:C23: missing closing ')' 507L1:C23: missing closing ')'
511 A <- %nosuch ('error' 508 A <- %nosuch ('error'
512 ^ 509 ^
513name 'nosuch' undefined
514]]) 510]])
515 511
516testerror([['a' / &@ ('c' / 'd')]], [[ 512testerror([['a' / &@ ('c' / 'd')]], [[