aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUndecidable Robot <undecidabot@gmail.com>2016-05-07 17:40:18 +0800
committerUndecidable Robot <undecidabot@gmail.com>2016-05-07 21:26:19 +0800
commit15bc429d1ca206131537dad8132b460f66e6ae89 (patch)
tree7876126ef42d629aaf7be827ab668134e74afa82
parent49fa2fc52c6913abfce7d0cd5fac24b2c88bce05 (diff)
downloadlpeglabel-15bc429d1ca206131537dad8132b460f66e6ae89.tar.gz
lpeglabel-15bc429d1ca206131537dad8132b460f66e6ae89.tar.bz2
lpeglabel-15bc429d1ca206131537dad8132b460f66e6ae89.zip
Adding tests for relabel compile errors
-rw-r--r--testerrors.lua112
1 files changed, 112 insertions, 0 deletions
diff --git a/testerrors.lua b/testerrors.lua
new file mode 100644
index 0000000..07bbaef
--- /dev/null
+++ b/testerrors.lua
@@ -0,0 +1,112 @@
1local re = require 'relabel'
2
3local npass, ntests = 0, 0
4
5function testerror(repatt)
6 ntests = ntests + 1
7 local ok, err = pcall(function () re.compile(repatt) end)
8
9 if ok then
10 print("FAIL", ntests)
11 else
12 npass = npass + 1
13 print("PASS", ntests, err)
14 end
15end
16
17local patterns = {
18 -- 1-5
19 [[~]],
20 [[???]],
21 [['p'~]],
22 [['p'?$?]],
23 [['p' /{1}]],
24 -- 6-10
25 [['p' /{1} /{2} 'q']],
26 [['p' /]],
27 [['p' / / 'q']],
28 [[&]],
29 [[& / 'p']],
30 -- 11-15
31 [['p' &]],
32 [['p' / & / 'q']],
33 [[&&]],
34 [[!&]],
35 [[!]],
36 -- 16-20
37 [[! / 'p']],
38 [['p' !]],
39 [['p' / ! / 'q']],
40 [[!!]],
41 [[&!]],
42 -- 21-25
43 [['p' ^ n]],
44 [['p'^+(+1)]],
45 [['p'^-/'q']],
46 [['p' -> {]],
47 [['p' -> {'q'}]],
48 -- 26-30
49 [['p' -> / 'q']],
50 [['p' -> [0-9] ]],
51 [['p' =>]],
52 [['p' => 'q']],
53 [[()]],
54 -- 31-35
55 [[($$$)]],
56 [[('p' ('q' / 'r')]],
57 [[% s]],
58 [[% {1}]],
59 [[{: *** :}]],
60 -- 36-40
61 [[{:group: *** :}]],
62 [[{: group: 'p' :}]],
63 [[S <- {: 'p' T <- 'q']],
64 [['<' {:tag: [a-z]+ :} '>' '<' = '>']],
65 [['<' {:tag: [a-z]+ :} '>' '<' = tag '>']],
66 -- 41-45
67 [[{~~}]],
68 [[{ {~ } ~}]],
69 [[{~ ^_^ ~}]],
70 [['p' {~ ('q' 'r') / 's']],
71 [[{0}]],
72 -- 46-50
73 [[{ :'p': }]],
74 [[{ 'p' ]],
75 [[<>]],
76 [[<123>]],
77 [[< hello >]],
78 -- 51-55
79 [[<<S>>]],
80 [[<patt]],
81 [[<insert your name here>]],
82 [[S <-]],
83 [[S <- 'p' T <-]],
84 -- 55-60
85 [[[]],
86 [[[^]],
87 [[[] ]],
88 [[[^] ]],
89 [[[_-___-_|]],
90 -- 60-65
91 [['p' /{} 'q']],
92 [[%{ 'label' }]],
93 [['p' /{1,2,3,} 'q']],
94 [[%{ a,,b,,c }]],
95 [['{' %{ a, b '}']],
96 -- 65-70
97 [[Q <- "To be or not to be...]],
98 [['That is the question...]],
99 [[{||}]],
100 [[{|@|}]],
101 [['p' {| 'q' / 'r' }]],
102 -- 71-72
103 [['a'/{1}'b'/'c']],
104 [[x <- {:x:}]],
105}
106
107for i, patt in ipairs(patterns) do
108 testerror(patt)
109end
110
111print()
112print("Tests passed: " .. npass .. "/" .. ntests)