diff options
Diffstat (limited to 'testerrors.lua')
-rw-r--r-- | testerrors.lua | 38 |
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 | ||
18 | end | 24 | end |
19 | 25 | ||
20 | testerror([[~]], [[ | 26 | testerror([[~]], [[ |
@@ -483,16 +489,10 @@ testerror([[ | |||
483 | A <- 'and again' | 489 | A <- 'and again' |
484 | ]], [[ | 490 | ]], [[ |
485 | name 'nosuch' undefined | 491 | name 'nosuch' undefined |
486 | name 'def' undefined | ||
487 | 'A' already defined as a rule | ||
488 | 'A' already defined as a rule | ||
489 | ]]) | 492 | ]]) |
490 | 493 | ||
491 | testerror([[names not in grammar]], [[ | 494 | testerror([[names not in grammar]], [[ |
492 | rule 'names' used outside a grammar | 495 | rule 'names' used outside a grammar |
493 | rule 'not' used outside a grammar | ||
494 | rule 'in' used outside a grammar | ||
495 | rule 'grammar' used outside a grammar | ||
496 | ]]) | 496 | ]]) |
497 | 497 | ||
498 | testerror([[ | 498 | testerror([[ |
@@ -501,16 +501,12 @@ testerror([[ | |||
501 | A <- 'and again' | 501 | A <- 'and again' |
502 | ]], [[ | 502 | ]], [[ |
503 | name 'nosuch' undefined | 503 | name 'nosuch' undefined |
504 | name 'def' undefined | ||
505 | 'A' already defined as a rule | ||
506 | 'A' already defined as a rule | ||
507 | ]]) | 504 | ]]) |
508 | 505 | ||
509 | testerror([[ A <- %nosuch ('error' ]], [[ | 506 | testerror([[ A <- %nosuch ('error' ]], [[ |
510 | L1:C23: missing closing ')' | 507 | L1:C23: missing closing ')' |
511 | A <- %nosuch ('error' | 508 | A <- %nosuch ('error' |
512 | ^ | 509 | ^ |
513 | name 'nosuch' undefined | ||
514 | ]]) | 510 | ]]) |
515 | 511 | ||
516 | testerror([['a' / &@ ('c' / 'd')]], [[ | 512 | testerror([['a' / &@ ('c' / 'd')]], [[ |