diff options
author | David Walter Seikel | 2014-04-21 20:59:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-04-21 20:59:39 +1000 |
commit | 9621add2918cc4943e6693b74ae85d51dd264fcf (patch) | |
tree | fff1edf2c69d7a08a0e12885eecc9b96ed847a6a /LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk4.lua | |
parent | LuaSL_test's window doesn't need to be so huge. (diff) | |
download | SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.zip SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.tar.gz SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.tar.bz2 SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.tar.xz |
We don't need the testlua directory any more.
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk4.lua')
-rw-r--r-- | LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk4.lua | 499 |
1 files changed, 0 insertions, 499 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk4.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk4.lua deleted file mode 100644 index 316a9bf..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_llex_mk4.lua +++ /dev/null | |||
@@ -1,499 +0,0 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | test_llex.lua | ||
4 | Test for llex.lua | ||
5 | This file is part of Yueliang. | ||
6 | |||
7 | Copyright (c) 2006 Kein-Hong Man <khman@users.sf.net> | ||
8 | The COPYRIGHT file describes the conditions | ||
9 | under which this software may be distributed. | ||
10 | |||
11 | See the ChangeLog for more information. | ||
12 | |||
13 | ----------------------------------------------------------------------]] | ||
14 | |||
15 | ------------------------------------------------------------------------ | ||
16 | -- if BRIEF is not set to false, auto-test will silently succeed | ||
17 | ------------------------------------------------------------------------ | ||
18 | BRIEF = true -- if set to true, messages are less verbose | ||
19 | |||
20 | local zio_init = require("../lzio_mk4") | ||
21 | local lex_init = require("../llex_mk4") | ||
22 | |||
23 | ------------------------------------------------------------------------ | ||
24 | -- simple manual tests | ||
25 | ------------------------------------------------------------------------ | ||
26 | |||
27 | --[[ | ||
28 | local function dump(z, source) | ||
29 | local luaX = lex_init(z, source) | ||
30 | while true do | ||
31 | local tok, seminfo = luaX:lex() | ||
32 | if tok == "<name>" then | ||
33 | seminfo = " "..seminfo | ||
34 | elseif tok == "<number>" then | ||
35 | seminfo = " "..seminfo | ||
36 | elseif tok == "<string>" then | ||
37 | seminfo = " '"..seminfo.."'" | ||
38 | else | ||
39 | seminfo = "" | ||
40 | end | ||
41 | io.stdout:write(tok..seminfo.."\n") | ||
42 | if tok == "<eof>" then break end | ||
43 | end | ||
44 | end | ||
45 | |||
46 | local function try_string(chunk) | ||
47 | dump(zio_init(chunk), "=string") | ||
48 | end | ||
49 | local function try_file(filename) | ||
50 | local f = "@"..filename | ||
51 | dump(zio_init(f), f) | ||
52 | end | ||
53 | |||
54 | z = try_string("local c = z:getc()") | ||
55 | z = try_file("test_lzio_mk2.lua") | ||
56 | z = try_file("test_llex_mk2.lua") | ||
57 | os.exit() | ||
58 | --]] | ||
59 | |||
60 | ------------------------------------------------------------------------ | ||
61 | -- auto-testing of simple test cases to validate lexer behaviour: | ||
62 | -- * NOTE coverage has not been checked; not comprehensive | ||
63 | -- * only test cases with non-empty comments are processed | ||
64 | -- * if no result, then the output is displayed for manual decision | ||
65 | -- (output may be used to set expected success or fail text) | ||
66 | -- * cases expected to be successful may be a partial match | ||
67 | -- * cases expected to fail may also be a partial match | ||
68 | ------------------------------------------------------------------------ | ||
69 | |||
70 | -- [[ | ||
71 | local function auto_test() | ||
72 | local PASS, FAIL = true, false | ||
73 | ------------------------------------------------------------------ | ||
74 | -- table of test cases | ||
75 | ------------------------------------------------------------------ | ||
76 | local test_cases = | ||
77 | { | ||
78 | ------------------------------------------------------------- | ||
79 | --{ "comment", -- comment about the test | ||
80 | -- "chunk", -- chunk to test | ||
81 | -- PASS, -- PASS or FAIL outcome | ||
82 | -- "output", -- output to compare against | ||
83 | --}, | ||
84 | ------------------------------------------------------------- | ||
85 | { "empty chunk string, test EOS", | ||
86 | "", | ||
87 | PASS, "1 <eof>", | ||
88 | }, | ||
89 | ------------------------------------------------------------- | ||
90 | { "line number counting", | ||
91 | "\n\n\r\n", | ||
92 | PASS, "4 <eof>", | ||
93 | }, | ||
94 | ------------------------------------------------------------- | ||
95 | { "various whitespaces", | ||
96 | " \n\t\t\n \t \t \n\n", | ||
97 | PASS, "5 <eof>", | ||
98 | }, | ||
99 | ------------------------------------------------------------- | ||
100 | { "short comment ending in EOS", | ||
101 | "-- moo moo", | ||
102 | PASS, "1 <eof>", | ||
103 | }, | ||
104 | ------------------------------------------------------------- | ||
105 | { "short comment ending in newline", | ||
106 | "-- moo moo\n", | ||
107 | PASS, "2 <eof>", | ||
108 | }, | ||
109 | ------------------------------------------------------------- | ||
110 | { "several lines of short comments", | ||
111 | "--moo\n-- moo moo\n\n--\tmoo\n", | ||
112 | PASS, "5 <eof>", | ||
113 | }, | ||
114 | ------------------------------------------------------------- | ||
115 | { "basic block comment", | ||
116 | "--[[bovine]]", | ||
117 | PASS, "1 <eof>", | ||
118 | }, | ||
119 | ------------------------------------------------------------- | ||
120 | { "unterminated block comment 1", | ||
121 | "--[[bovine", | ||
122 | FAIL, ":1: unfinished long comment", | ||
123 | }, | ||
124 | ------------------------------------------------------------- | ||
125 | { "unterminated block comment 2", | ||
126 | "--[[bovine]", | ||
127 | FAIL, ":1: unfinished long comment", | ||
128 | }, | ||
129 | ------------------------------------------------------------- | ||
130 | { "unterminated block comment 3", | ||
131 | "--[[bovine\nmoo moo\nwoof", | ||
132 | FAIL, ":3: unfinished long comment", | ||
133 | }, | ||
134 | ------------------------------------------------------------- | ||
135 | { "basic long string", | ||
136 | "\n[[bovine]]\n", | ||
137 | PASS, "2 <string> = bovine\n3 <eof>", | ||
138 | }, | ||
139 | ------------------------------------------------------------- | ||
140 | { "first newline consumed in long string", | ||
141 | "[[\nmoo]]", | ||
142 | PASS, "2 <string> = moo\n2 <eof>", | ||
143 | }, | ||
144 | ------------------------------------------------------------- | ||
145 | { "multiline long string", | ||
146 | "[[moo\nmoo moo\n]]", | ||
147 | PASS, "3 <string> = moo\nmoo moo\n\n3 <eof>", | ||
148 | }, | ||
149 | ------------------------------------------------------------- | ||
150 | { "unterminated long string 1", | ||
151 | "\n[[\nbovine", | ||
152 | FAIL, ":3: unfinished long string", | ||
153 | }, | ||
154 | ------------------------------------------------------------- | ||
155 | { "unterminated long string 2", | ||
156 | "[[bovine]", | ||
157 | FAIL, ":1: unfinished long string", | ||
158 | }, | ||
159 | ------------------------------------------------------------- | ||
160 | { "unterminated long string 3", | ||
161 | "[[[[ \n", | ||
162 | FAIL, ":2: unfinished long string", | ||
163 | }, | ||
164 | ------------------------------------------------------------- | ||
165 | { "nested long string 1", | ||
166 | "[[moo[[moo]]moo]]", | ||
167 | PASS, "moo[[moo]]moo", | ||
168 | }, | ||
169 | ------------------------------------------------------------- | ||
170 | { "nested long string 2", | ||
171 | "[[moo[[moo[[[[]]]]moo]]moo]]", | ||
172 | PASS, "moo[[moo[[[[]]]]moo]]moo", | ||
173 | }, | ||
174 | ------------------------------------------------------------- | ||
175 | { "nested long string 3", | ||
176 | "[[[[[[]]]][[[[]]]]]]", | ||
177 | PASS, "[[[[]]]][[[[]]]]", | ||
178 | }, | ||
179 | ------------------------------------------------------------- | ||
180 | { "brackets in long strings 1", | ||
181 | "[[moo[moo]]", | ||
182 | PASS, "moo[moo", | ||
183 | }, | ||
184 | ------------------------------------------------------------- | ||
185 | { "brackets in long strings 2", | ||
186 | "[[moo[[moo]moo]]moo]]", | ||
187 | PASS, "moo[[moo]moo]]moo", | ||
188 | }, | ||
189 | ------------------------------------------------------------- | ||
190 | { "unprocessed escapes in long strings", | ||
191 | [[ [[\a\b\f\n\r\t\v\123]] ]], | ||
192 | PASS, [[\a\b\f\n\r\t\v\123]], | ||
193 | }, | ||
194 | ------------------------------------------------------------- | ||
195 | { "unbalanced long string", | ||
196 | "[[moo]]moo]]", | ||
197 | PASS, "1 <string> = moo\n1 <name> = moo\n1 CHAR = ']'\n1 CHAR = ']'\n1 <eof>", | ||
198 | }, | ||
199 | ------------------------------------------------------------- | ||
200 | { "keywords 1", | ||
201 | "and break do else", | ||
202 | PASS, "1 and\n1 break\n1 do\n1 else\n1 <eof>", | ||
203 | }, | ||
204 | ------------------------------------------------------------- | ||
205 | { "keywords 2", | ||
206 | "elseif end false for", | ||
207 | PASS, "1 elseif\n1 end\n1 false\n1 for\n1 <eof>", | ||
208 | }, | ||
209 | ------------------------------------------------------------- | ||
210 | { "keywords 3", | ||
211 | "function if in local nil", | ||
212 | PASS, "1 function\n1 if\n1 in\n1 local\n1 nil\n1 <eof>", | ||
213 | }, | ||
214 | ------------------------------------------------------------- | ||
215 | { "keywords 4", | ||
216 | "not or repeat return", | ||
217 | PASS, "1 not\n1 or\n1 repeat\n1 return\n1 <eof>", | ||
218 | }, | ||
219 | ------------------------------------------------------------- | ||
220 | { "keywords 5", | ||
221 | "then true until while", | ||
222 | PASS, "1 then\n1 true\n1 until\n1 while\n1 <eof>", | ||
223 | }, | ||
224 | ------------------------------------------------------------- | ||
225 | { "concat and dots", | ||
226 | ".. ...", | ||
227 | PASS, "1 ..\n1 ...\n1 <eof>", | ||
228 | }, | ||
229 | ------------------------------------------------------------- | ||
230 | { "shbang handling 1", | ||
231 | "#blahblah", | ||
232 | PASS, "1 <eof>", | ||
233 | }, | ||
234 | ------------------------------------------------------------- | ||
235 | { "shbang handling 2", | ||
236 | "#blahblah\nmoo moo\n", | ||
237 | PASS, "2 <name> = moo\n2 <name> = moo\n3 <eof>", | ||
238 | }, | ||
239 | ------------------------------------------------------------- | ||
240 | { "empty string", | ||
241 | [['']], | ||
242 | PASS, "1 <string> = \n1 <eof>", | ||
243 | }, | ||
244 | ------------------------------------------------------------- | ||
245 | { "single-quoted string", | ||
246 | [['bovine']], | ||
247 | PASS, "1 <string> = bovine\n1 <eof>", | ||
248 | }, | ||
249 | ------------------------------------------------------------- | ||
250 | { "double-quoted string", | ||
251 | [["bovine"]], | ||
252 | PASS, "1 <string> = bovine\n1 <eof>", | ||
253 | }, | ||
254 | ------------------------------------------------------------- | ||
255 | { "unterminated string 1", | ||
256 | [['moo ]], | ||
257 | FAIL, ":1: unfinished string", | ||
258 | }, | ||
259 | ------------------------------------------------------------- | ||
260 | { "unterminated string 2", | ||
261 | [["moo \n]], | ||
262 | FAIL, ":1: unfinished string", | ||
263 | }, | ||
264 | ------------------------------------------------------------- | ||
265 | { "escaped newline in string, line number counted", | ||
266 | "\"moo\\\nmoo\\\nmoo\"", | ||
267 | PASS, "3 <string> = moo\nmoo\nmoo\n3 <eof>", | ||
268 | }, | ||
269 | ------------------------------------------------------------- | ||
270 | { "escaped characters in string 1", | ||
271 | [["moo\amoo"]], | ||
272 | PASS, "1 <string> = moo\amoo", | ||
273 | }, | ||
274 | ------------------------------------------------------------- | ||
275 | { "escaped characters in string 2", | ||
276 | [["moo\bmoo"]], | ||
277 | PASS, "1 <string> = moo\bmoo", | ||
278 | }, | ||
279 | ------------------------------------------------------------- | ||
280 | { "escaped characters in string 3", | ||
281 | [["moo\f\n\r\t\vmoo"]], | ||
282 | PASS, "1 <string> = moo\f\n\r\t\vmoo", | ||
283 | }, | ||
284 | ------------------------------------------------------------- | ||
285 | { "escaped characters in string 4", | ||
286 | [["\\ \" \' \? \[ \]"]], | ||
287 | PASS, "1 <string> = \\ \" \' \? \[ \]", | ||
288 | }, | ||
289 | ------------------------------------------------------------- | ||
290 | { "escaped characters in string 5", | ||
291 | [["\z \k \: \;"]], | ||
292 | PASS, "1 <string> = z k : ;", | ||
293 | }, | ||
294 | ------------------------------------------------------------- | ||
295 | { "escaped characters in string 6", | ||
296 | [["\8 \65 \160 \180K \097097"]], | ||
297 | PASS, "1 <string> = \8 \65 \160 \180K \097097\n", | ||
298 | }, | ||
299 | ------------------------------------------------------------- | ||
300 | { "escaped characters in string 7", | ||
301 | [["\666"]], | ||
302 | FAIL, ":1: escape sequence too large", | ||
303 | }, | ||
304 | ------------------------------------------------------------- | ||
305 | { "simple numbers", | ||
306 | "123 123+", | ||
307 | PASS, "1 <number> = 123\n1 <number> = 123\n1 CHAR = '+'\n1 <eof>", | ||
308 | }, | ||
309 | ------------------------------------------------------------- | ||
310 | { "longer numbers", | ||
311 | "1234567890 12345678901234567890", | ||
312 | PASS, "1 <number> = 1234567890\n1 <number> = 1.2345678901235e+19\n", | ||
313 | }, | ||
314 | ------------------------------------------------------------- | ||
315 | { "fractional numbers", | ||
316 | ".123 .12345678901234567890", | ||
317 | PASS, "1 <number> = 0.123\n1 <number> = 0.12345678901235\n", | ||
318 | }, | ||
319 | ------------------------------------------------------------- | ||
320 | { "more numbers with decimal points", | ||
321 | "12345.67890 1.1.", | ||
322 | PASS, "1 <number> = 12345.6789\n1 <number> = 1.1\n1 CHAR = '.'\n", | ||
323 | }, | ||
324 | ------------------------------------------------------------- | ||
325 | { "double decimal points", | ||
326 | ".1.1", | ||
327 | FAIL, ":1: malformed number", | ||
328 | }, | ||
329 | ------------------------------------------------------------- | ||
330 | { "double dots within numbers", | ||
331 | "1..1", | ||
332 | FAIL, ":1: ambiguous syntax (dots follows digits)", | ||
333 | }, | ||
334 | ------------------------------------------------------------- | ||
335 | { "incomplete exponential numbers", | ||
336 | "123e", | ||
337 | FAIL, ":1: malformed number", | ||
338 | }, | ||
339 | ------------------------------------------------------------- | ||
340 | { "exponential numbers 1", | ||
341 | "1234e5 1234e5.", | ||
342 | PASS, "1 <number> = 123400000\n1 <number> = 123400000\n1 CHAR = '.'", | ||
343 | }, | ||
344 | ------------------------------------------------------------- | ||
345 | { "exponential numbers 2", | ||
346 | "1234e56 1.23e123", | ||
347 | PASS, "1 <number> = 1.234e+59\n1 <number> = 1.23e+123\n", | ||
348 | }, | ||
349 | ------------------------------------------------------------- | ||
350 | { "exponential numbers 3", | ||
351 | "12.34e+", | ||
352 | FAIL, ":1: malformed number", | ||
353 | }, | ||
354 | ------------------------------------------------------------- | ||
355 | { "exponential numbers 4", | ||
356 | "12.34e+5 123.4e-5 1234.E+5", | ||
357 | PASS, "1 <number> = 1234000\n1 <number> = 0.001234\n1 <number> = 123400000\n", | ||
358 | }, | ||
359 | ------------------------------------------------------------- | ||
360 | { "single character symbols 1", | ||
361 | "= > < ~", | ||
362 | PASS, "1 CHAR = '='\n1 CHAR = '>'\n1 CHAR = '<'\n1 CHAR = '~'\n", | ||
363 | }, | ||
364 | ------------------------------------------------------------- | ||
365 | { "double character symbols", | ||
366 | "== >= <= ~=", | ||
367 | PASS, "1 ==\n1 >=\n1 <=\n1 ~=\n", | ||
368 | }, | ||
369 | ------------------------------------------------------------- | ||
370 | { "simple identifiers", | ||
371 | "abc ABC", | ||
372 | PASS, "1 <name> = abc\n1 <name> = ABC\n1 <eof>", | ||
373 | }, | ||
374 | ------------------------------------------------------------- | ||
375 | { "more identifiers", | ||
376 | "_abc _ABC", | ||
377 | PASS, "1 <name> = _abc\n1 <name> = _ABC\n1 <eof>", | ||
378 | }, | ||
379 | ------------------------------------------------------------- | ||
380 | { "still more identifiers", | ||
381 | "_aB_ _123", | ||
382 | PASS, "1 <name> = _aB_\n1 <name> = _123\n1 <eof>", | ||
383 | }, | ||
384 | ------------------------------------------------------------- | ||
385 | { "invalid control character", | ||
386 | "\4", | ||
387 | FAIL, ":1: invalid control char", | ||
388 | }, | ||
389 | ------------------------------------------------------------- | ||
390 | { "single character symbols 2", | ||
391 | "` ! @ $ %", | ||
392 | PASS, "1 CHAR = '`'\n1 CHAR = '!'\n1 CHAR = '@'\n1 CHAR = '$'\n1 CHAR = '%'\n", | ||
393 | }, | ||
394 | ------------------------------------------------------------- | ||
395 | { "single character symbols 3", | ||
396 | "^ & * ( )", | ||
397 | PASS, "1 CHAR = '^'\n1 CHAR = '&'\n1 CHAR = '*'\n1 CHAR = '('\n1 CHAR = ')'\n", | ||
398 | }, | ||
399 | ------------------------------------------------------------- | ||
400 | { "single character symbols 4", | ||
401 | "_ - + \\ |", | ||
402 | PASS, "1 <name> = _\n1 CHAR = '-'\n1 CHAR = '+'\n1 CHAR = '\\'\n1 CHAR = '|'\n", | ||
403 | }, | ||
404 | ------------------------------------------------------------- | ||
405 | { "single character symbols 5", | ||
406 | "{ } [ ] :", | ||
407 | PASS, "1 CHAR = '{'\n1 CHAR = '}'\n1 CHAR = '['\n1 CHAR = ']'\n1 CHAR = ':'\n", | ||
408 | }, | ||
409 | ------------------------------------------------------------- | ||
410 | { "single character symbols 6", | ||
411 | "; , . / ?", | ||
412 | PASS, "1 CHAR = ';'\n1 CHAR = ','\n1 CHAR = '.'\n1 CHAR = '/'\n1 CHAR = '?'\n", | ||
413 | }, | ||
414 | ------------------------------------------------------------- | ||
415 | } | ||
416 | ------------------------------------------------------------------ | ||
417 | -- perform a test case | ||
418 | ------------------------------------------------------------------ | ||
419 | function do_test_case(count, test_case) | ||
420 | if comment == "" then return end -- skip empty entries | ||
421 | local comment, chunk, outcome, matcher = unpack(test_case) | ||
422 | local result = PASS | ||
423 | local output = "" | ||
424 | -- initialize lexer | ||
425 | local z = zio_init(chunk) | ||
426 | local luaX = lex_init(z, "=test") | ||
427 | -- lexer test loop | ||
428 | local status, token, seminfo | ||
429 | repeat | ||
430 | -- protected call | ||
431 | status, token, seminfo = pcall(luaX.lex, luaX) | ||
432 | output = output..luaX.ln.." " | ||
433 | if status then | ||
434 | -- successful call | ||
435 | if string.len(token) > 1 then | ||
436 | if token == "<name>" | ||
437 | or token == "<number>" | ||
438 | or token == "<string>" then | ||
439 | token = token.." = "..seminfo | ||
440 | end | ||
441 | elseif string.byte(token) >= 32 then -- displayable chars | ||
442 | token = "CHAR = '"..token.."'" | ||
443 | else -- control characters | ||
444 | token = "CHAR = (".. string.byte(token)..")" | ||
445 | end | ||
446 | output = output..token.."\n" | ||
447 | else | ||
448 | -- failed call | ||
449 | output = output..token -- token is the error message | ||
450 | result = FAIL | ||
451 | break | ||
452 | end | ||
453 | until token == "<eof>" | ||
454 | -- decision making and reporting | ||
455 | local head = "Test "..count..": "..comment | ||
456 | if matcher == "" then | ||
457 | -- nothing to check against, display for manual check | ||
458 | print(head.."\nMANUAL please check manually".. | ||
459 | "\n--chunk---------------------------------\n"..chunk.. | ||
460 | "\n--actual--------------------------------\n"..output.. | ||
461 | "\n\n") | ||
462 | return | ||
463 | else | ||
464 | if outcome == PASS then | ||
465 | -- success expected, may be a partial match | ||
466 | if string.find(output, matcher, 1, 1) and result == PASS then | ||
467 | if not BRIEF then print(head.."\nOK expected success\n") end | ||
468 | return | ||
469 | end | ||
470 | else | ||
471 | -- failure expected, may be a partial match | ||
472 | if string.find(output, matcher, 1, 1) and result == FAIL then | ||
473 | if not BRIEF then print(head.."\nOK expected failure\n") end | ||
474 | return | ||
475 | end | ||
476 | end | ||
477 | -- failed because of unmatched string or boolean result | ||
478 | local function passfail(status) | ||
479 | if status == PASS then return "PASS" else return "FAIL" end | ||
480 | end | ||
481 | print(head.." *FAILED*".. | ||
482 | "\noutcome="..passfail(outcome).. | ||
483 | "\nactual= "..passfail(result).. | ||
484 | "\n--chunk---------------------------------\n"..chunk.. | ||
485 | "\n--expected------------------------------\n"..matcher.. | ||
486 | "\n--actual--------------------------------\n"..output.. | ||
487 | "\n\n") | ||
488 | end | ||
489 | end | ||
490 | ------------------------------------------------------------------ | ||
491 | -- perform auto testing | ||
492 | ------------------------------------------------------------------ | ||
493 | for i,test_case in ipairs(test_cases) do | ||
494 | do_test_case(i, test_case) | ||
495 | end | ||
496 | end | ||
497 | |||
498 | auto_test() | ||
499 | --]] | ||