aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_llex_mk2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_llex_mk2.lua')
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_llex_mk2.lua566
1 files changed, 0 insertions, 566 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_llex_mk2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_llex_mk2.lua
deleted file mode 100644
index e9ad45f..0000000
--- a/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_llex_mk2.lua
+++ /dev/null
@@ -1,566 +0,0 @@
1--[[--------------------------------------------------------------------
2
3 test_llex_mk2.lua
4 Test for llex_mk2.lua
5 This file is part of Yueliang.
6
7 Copyright (c) 2008 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------------------------------------------------------------------------
18BRIEF = true -- if set to true, messages are less verbose
19
20package.path = "../?.lua;"..package.path
21local llex = require "llex_mk2"
22
23------------------------------------------------------------------------
24-- simple manual tests
25------------------------------------------------------------------------
26
27--[[
28local function dump(z)
29 llex.init(z)
30 while true do
31 local token, seminfo = llex.llex()
32 if token == "<name>" then
33 seminfo = " "..seminfo
34 elseif token == "<number>" then
35 seminfo = " "..seminfo
36 elseif token == "<string>" then
37 seminfo = " '"..seminfo.."'"
38 else
39 seminfo = ""
40 end
41 io.stdout:write(token..seminfo.."\n")
42 if token == "<eof>" then break end
43 end
44end
45
46dump("local c = luaZ:zgetc(z)")
47os.exit()
48--]]
49
50------------------------------------------------------------------------
51-- auto-testing of simple test cases to validate lexer behaviour:
52-- * NOTE coverage has not been checked; not comprehensive
53-- * only test cases with non-empty comments are processed
54-- * if no result, then the output is displayed for manual decision
55-- (output may be used to set expected success or fail text)
56-- * cases expected to be successful may be a partial match
57-- * cases expected to fail may also be a partial match
58------------------------------------------------------------------------
59
60-- [=====[
61local function auto_test()
62 local PASS, FAIL = true, false
63 ------------------------------------------------------------------
64 -- table of test cases
65 ------------------------------------------------------------------
66 local test_cases =
67 {
68 -------------------------------------------------------------
69 --{ "comment", -- comment about the test
70 -- "chunk", -- chunk to test
71 -- PASS, -- PASS or FAIL outcome
72 -- "output", -- output to compare against
73 --},
74 -------------------------------------------------------------
75 { "empty chunk string, test EOS",
76 "",
77 PASS, "1 <eof>",
78 },
79 -------------------------------------------------------------
80 { "line number counting",
81 "\n\n\r\n",
82 PASS, "4 <eof>",
83 },
84 -------------------------------------------------------------
85 { "various whitespaces",
86 " \n\t\t\n \t \t \n\n",
87 PASS, "5 <eof>",
88 },
89 -------------------------------------------------------------
90 { "short comment ending in EOS",
91 "-- moo moo",
92 PASS, "1 <eof>",
93 },
94 -------------------------------------------------------------
95 { "short comment ending in newline",
96 "-- moo moo\n",
97 PASS, "2 <eof>",
98 },
99 -------------------------------------------------------------
100 { "several lines of short comments",
101 "--moo\n-- moo moo\n\n--\tmoo\n",
102 PASS, "5 <eof>",
103 },
104 -------------------------------------------------------------
105 { "basic block comment 1",
106 "--[[bovine]]",
107 PASS, "1 <eof>",
108 },
109 -------------------------------------------------------------
110 { "basic block comment 2",
111 "--[=[bovine]=]",
112 PASS, "1 <eof>",
113 },
114 -------------------------------------------------------------
115 { "basic block comment 3",
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]",
132 FAIL, ":1: unfinished long comment",
133 },
134 -------------------------------------------------------------
135 { "unterminated block comment 4",
136 "--[[bovine\nmoo moo\nwoof",
137 FAIL, ":3: unfinished long comment",
138 },
139 -------------------------------------------------------------
140 { "basic long string 1",
141 "\n[[bovine]]\n",
142 PASS, "2 <string> = bovine\n3 <eof>",
143 },
144 -------------------------------------------------------------
145 { "basic long string 2",
146 "\n[=[bovine]=]\n",
147 PASS, "2 <string> = bovine\n3 <eof>",
148 },
149 -------------------------------------------------------------
150 { "first newline consumed in long string",
151 "[[\nmoo]]",
152 PASS, "2 <string> = moo\n2 <eof>",
153 },
154 -------------------------------------------------------------
155 { "multiline long string 1",
156 "[[moo\nmoo moo\n]]",
157 PASS, "3 <string> = moo\nmoo moo\n\n3 <eof>",
158 },
159 -------------------------------------------------------------
160 { "multiline long string 2",
161 "[===[moo\n[=[moo moo]=]\n]===]",
162 PASS, "3 <string> = moo\n[=[moo moo]=]\n\n3 <eof>",
163 },
164 -------------------------------------------------------------
165 { "unterminated long string 1",
166 "\n[[\nbovine",
167 FAIL, ":3: unfinished long string",
168 },
169 -------------------------------------------------------------
170 { "unterminated long string 2",
171 "[[bovine]",
172 FAIL, ":1: unfinished long string",
173 },
174 -------------------------------------------------------------
175 { "unterminated long string 2",
176 "[==[bovine]==",
177 FAIL, ":1: unfinished long string",
178 },
179 -------------------------------------------------------------
180 { "complex long string 1",
181 "[=[moo[[moo]]moo]=]",
182 PASS, "moo[[moo]]moo",
183 },
184 -------------------------------------------------------------
185 { "complex long string 2",
186 "[=[moo[[moo[[[[]]]]moo]]moo]=]",
187 PASS, "moo[[moo[[[[]]]]moo]]moo",
188 },
189 -------------------------------------------------------------
190 { "complex long string 3",
191 "[=[[[[[]]]][[[[]]]]]=]",
192 PASS, "[[[[]]]][[[[]]]]",
193 },
194 -------------------------------------------------------------
195 -- NOTE: this native lexer does not support compatible long
196 -- strings (LUA_COMPAT_LSTR)
197 -------------------------------------------------------------
198 --{ "deprecated long string 1",
199 -- "[[moo[[moo]]moo]]",
200 -- FAIL, ":1: nesting of [[...]] is deprecated near '['",
201 --},
202 ---------------------------------------------------------------
203 --{ "deprecated long string 2",
204 -- "[[[[ \n",
205 -- FAIL, ":1: nesting of [[...]] is deprecated near '['",
206 --},
207 ---------------------------------------------------------------
208 --{ "deprecated long string 3",
209 -- "[[moo[[moo[[[[]]]]moo]]moo]]",
210 -- FAIL, ":1: nesting of [[...]] is deprecated near '['",
211 --},
212 ---------------------------------------------------------------
213 --{ "deprecated long string 4",
214 -- "[[[[[[]]]][[[[]]]]]]",
215 -- FAIL, ":1: nesting of [[...]] is deprecated near '['",
216 --},
217 -------------------------------------------------------------
218 { "brackets in long strings 1",
219 "[[moo[moo]]",
220 PASS, "moo[moo",
221 },
222 -------------------------------------------------------------
223 { "brackets in long strings 2",
224 "[=[moo[[moo]moo]]moo]=]",
225 PASS, "moo[[moo]moo]]moo",
226 },
227 -------------------------------------------------------------
228 { "unprocessed escapes in long strings",
229 [[ [=[\a\b\f\n\r\t\v\123]=] ]],
230 PASS, [[\a\b\f\n\r\t\v\123]],
231 },
232 -------------------------------------------------------------
233 { "unbalanced long string",
234 "[[moo]]moo]]",
235 PASS, "1 <string> = moo\n1 <name> = moo\n1 CHAR = ']'\n1 CHAR = ']'\n1 <eof>",
236 },
237 -------------------------------------------------------------
238 { "keywords 1",
239 "and break do else",
240 PASS, "1 and\n1 break\n1 do\n1 else\n1 <eof>",
241 },
242 -------------------------------------------------------------
243 { "keywords 2",
244 "elseif end false for",
245 PASS, "1 elseif\n1 end\n1 false\n1 for\n1 <eof>",
246 },
247 -------------------------------------------------------------
248 { "keywords 3",
249 "function if in local nil",
250 PASS, "1 function\n1 if\n1 in\n1 local\n1 nil\n1 <eof>",
251 },
252 -------------------------------------------------------------
253 { "keywords 4",
254 "not or repeat return",
255 PASS, "1 not\n1 or\n1 repeat\n1 return\n1 <eof>",
256 },
257 -------------------------------------------------------------
258 { "keywords 5",
259 "then true until while",
260 PASS, "1 then\n1 true\n1 until\n1 while\n1 <eof>",
261 },
262 -------------------------------------------------------------
263 { "concat and dots",
264 ".. ...",
265 PASS, "1 ..\n1 ...\n1 <eof>",
266 },
267 -------------------------------------------------------------
268 -- NOTE: in Lua 5.1.x, shbang handling is no longer performed
269 -- in the lexer; it is now done in lauxlib.c (luaL_loadfile)
270 -- so the following cannot be performed by the lexer...
271 -------------------------------------------------------------
272 --{ "shbang handling 1",
273 -- "#blahblah",
274 -- PASS, "1 <eof>",
275 --},
276 -------------------------------------------------------------
277 --{ "shbang handling 2",
278 -- "#blahblah\nmoo moo\n",
279 -- PASS, "2 <name> = moo\n2 <name> = moo\n3 <eof>",
280 --},
281 -------------------------------------------------------------
282 { "empty string",
283 [['']],
284 PASS, "1 <string> = \n1 <eof>",
285 },
286 -------------------------------------------------------------
287 { "single-quoted string",
288 [['bovine']],
289 PASS, "1 <string> = bovine\n1 <eof>",
290 },
291 -------------------------------------------------------------
292 { "double-quoted string",
293 [["bovine"]],
294 PASS, "1 <string> = bovine\n1 <eof>",
295 },
296 -------------------------------------------------------------
297 { "unterminated string 1",
298 [['moo ]],
299 FAIL, ":1: unfinished string",
300 },
301 -------------------------------------------------------------
302 { "unterminated string 2",
303 [["moo \n]],
304 FAIL, ":1: unfinished string",
305 },
306 -------------------------------------------------------------
307 { "escaped newline in string, line number counted",
308 "\"moo\\\nmoo\\\nmoo\"",
309 PASS, "3 <string> = moo\nmoo\nmoo\n3 <eof>",
310 },
311 -------------------------------------------------------------
312 { "escaped characters in string 1",
313 [["moo\amoo"]],
314 PASS, "1 <string> = moo\amoo",
315 },
316 -------------------------------------------------------------
317 { "escaped characters in string 2",
318 [["moo\bmoo"]],
319 PASS, "1 <string> = moo\bmoo",
320 },
321 -------------------------------------------------------------
322 { "escaped characters in string 3",
323 [["moo\f\n\r\t\vmoo"]],
324 PASS, "1 <string> = moo\f\n\r\t\vmoo",
325 },
326 -------------------------------------------------------------
327 { "escaped characters in string 4",
328 [["\\ \" \' \? \[ \]"]],
329 PASS, "1 <string> = \\ \" \' \? \[ \]",
330 },
331 -------------------------------------------------------------
332 { "escaped characters in string 5",
333 [["\z \k \: \;"]],
334 PASS, "1 <string> = z k : ;",
335 },
336 -------------------------------------------------------------
337 { "escaped characters in string 6",
338 [["\8 \65 \160 \180K \097097"]],
339 PASS, "1 <string> = \8 \65 \160 \180K \097097\n",
340 },
341 -------------------------------------------------------------
342 { "escaped characters in string 7",
343 [["\666"]],
344 FAIL, ":1: escape sequence too large",
345 },
346 -------------------------------------------------------------
347 { "simple numbers",
348 "123 123+",
349 PASS, "1 <number> = 123\n1 <number> = 123\n1 CHAR = '+'\n1 <eof>",
350 },
351 -------------------------------------------------------------
352 { "longer numbers",
353 "1234567890 12345678901234567890",
354 PASS, "1 <number> = 1234567890\n1 <number> = 1.2345678901235e+19\n",
355 },
356 -------------------------------------------------------------
357 { "fractional numbers",
358 ".123 .12345678901234567890",
359 PASS, "1 <number> = 0.123\n1 <number> = 0.12345678901235\n",
360 },
361 -------------------------------------------------------------
362 { "more numbers with decimal points",
363 "12345.67890",
364 PASS, "1 <number> = 12345.6789\n",
365 },
366 -------------------------------------------------------------
367 { "malformed number with decimal points",
368 "1.1.",
369 FAIL, ":1: malformed number",
370 },
371 -------------------------------------------------------------
372 { "double decimal points",
373 ".1.1",
374 FAIL, ":1: malformed number",
375 },
376 -------------------------------------------------------------
377 { "double dots within numbers",
378 "1..1",
379 FAIL, ":1: malformed number",
380 },
381 -------------------------------------------------------------
382 { "incomplete exponential numbers",
383 "123e",
384 FAIL, ":1: malformed number",
385 },
386 -------------------------------------------------------------
387 { "exponential numbers 1",
388 "1234e5 1234e5.",
389 PASS, "1 <number> = 123400000\n1 <number> = 123400000\n1 CHAR = '.'",
390 },
391 -------------------------------------------------------------
392 { "exponential numbers 2",
393 "1234e56 1.23e123",
394 PASS, "1 <number> = 1.234e+59\n1 <number> = 1.23e+123\n",
395 },
396 -------------------------------------------------------------
397 { "exponential numbers 3",
398 "12.34e+",
399 FAIL, ":1: malformed number",
400 },
401 -------------------------------------------------------------
402 { "exponential numbers 4",
403 "12.34e+5 123.4e-5 1234.E+5",
404 PASS, "1 <number> = 1234000\n1 <number> = 0.001234\n1 <number> = 123400000\n",
405 },
406 -------------------------------------------------------------
407 { "hexadecimal numbers",
408 "0x00FF 0X1234 0xDEADBEEF",
409 PASS, "1 <number> = 255\n1 <number> = 4660\n1 <number> = 3735928559\n",
410 },
411 -------------------------------------------------------------
412 { "invalid hexadecimal numbers 1",
413 "0xFOO",
414 FAIL, ":1: malformed number",
415 },
416 -------------------------------------------------------------
417 { "invalid hexadecimal numbers 2",
418 "0.BAR",
419 FAIL, ":1: malformed number",
420 },
421 -------------------------------------------------------------
422 { "invalid hexadecimal numbers 3",
423 "0BAZ",
424 FAIL, ":1: malformed number",
425 },
426 -------------------------------------------------------------
427 { "single character symbols 1",
428 "= > < ~ #",
429 PASS, "1 CHAR = '='\n1 CHAR = '>'\n1 CHAR = '<'\n1 CHAR = '~'\n1 CHAR = '#'\n",
430 },
431 -------------------------------------------------------------
432 { "double character symbols",
433 "== >= <= ~=",
434 PASS, "1 ==\n1 >=\n1 <=\n1 ~=\n",
435 },
436 -------------------------------------------------------------
437 { "simple identifiers",
438 "abc ABC",
439 PASS, "1 <name> = abc\n1 <name> = ABC\n1 <eof>",
440 },
441 -------------------------------------------------------------
442 { "more identifiers",
443 "_abc _ABC",
444 PASS, "1 <name> = _abc\n1 <name> = _ABC\n1 <eof>",
445 },
446 -------------------------------------------------------------
447 { "still more identifiers",
448 "_aB_ _123",
449 PASS, "1 <name> = _aB_\n1 <name> = _123\n1 <eof>",
450 },
451 -------------------------------------------------------------
452 -- NOTE: in Lua 5.1.x, this test is no longer performed
453 -------------------------------------------------------------
454 --{ "invalid control character",
455 -- "\4",
456 -- FAIL, ":1: invalid control char near 'char(4)'",
457 --},
458 -------------------------------------------------------------
459 { "single character symbols 2",
460 "` ! @ $ %",
461 PASS, "1 CHAR = '`'\n1 CHAR = '!'\n1 CHAR = '@'\n1 CHAR = '$'\n1 CHAR = '%'\n",
462 },
463 -------------------------------------------------------------
464 { "single character symbols 3",
465 "^ & * ( )",
466 PASS, "1 CHAR = '^'\n1 CHAR = '&'\n1 CHAR = '*'\n1 CHAR = '('\n1 CHAR = ')'\n",
467 },
468 -------------------------------------------------------------
469 { "single character symbols 4",
470 "_ - + \\ |",
471 PASS, "1 <name> = _\n1 CHAR = '-'\n1 CHAR = '+'\n1 CHAR = '\\'\n1 CHAR = '|'\n",
472 },
473 -------------------------------------------------------------
474 { "single character symbols 5",
475 "{ } [ ] :",
476 PASS, "1 CHAR = '{'\n1 CHAR = '}'\n1 CHAR = '['\n1 CHAR = ']'\n1 CHAR = ':'\n",
477 },
478 -------------------------------------------------------------
479 { "single character symbols 6",
480 "; , . / ?",
481 PASS, "1 CHAR = ';'\n1 CHAR = ','\n1 CHAR = '.'\n1 CHAR = '/'\n1 CHAR = '?'\n",
482 },
483 -------------------------------------------------------------
484 }
485 ------------------------------------------------------------------
486 -- perform a test case
487 ------------------------------------------------------------------
488 function do_test_case(count, test_case)
489 if comment == "" then return end -- skip empty entries
490 local comment, chunk, outcome, matcher = unpack(test_case)
491 local result = PASS
492 local output = ""
493 -- initialize lexer
494 llex.init(chunk, "=test")
495 -- lexer test loop
496 repeat
497 -- protected call
498 local status, token, seminfo = pcall(llex.llex)
499 output = output..llex.ln.." "
500 if status then
501 -- successful call
502 if #token > 1 then
503 if token == "<name>"
504 or token == "<number>"
505 or token == "<string>" then
506 token = token.." = "..seminfo
507 end
508 elseif string.byte(token) >= 32 then -- displayable chars
509 token = "CHAR = '"..token.."'"
510 else -- control characters
511 token = "CHAR = (".. string.byte(token)..")"
512 end
513 output = output..token.."\n"
514 else
515 -- failed call
516 output = output..token -- token is the error message
517 result = FAIL
518 break
519 end
520 until token == "<eof>"
521 -- decision making and reporting
522 local head = "Test "..count..": "..comment
523 if matcher == "" then
524 -- nothing to check against, display for manual check
525 print(head.."\nMANUAL please check manually"..
526 "\n--chunk---------------------------------\n"..chunk..
527 "\n--actual--------------------------------\n"..output..
528 "\n\n")
529 return
530 else
531 if outcome == PASS then
532 -- success expected, may be a partial match
533 if string.find(output, matcher, 1, 1) and result == PASS then
534 if not BRIEF then print(head.."\nOK expected success\n") end
535 return
536 end
537 else
538 -- failure expected, may be a partial match
539 if string.find(output, matcher, 1, 1) and result == FAIL then
540 if not BRIEF then print(head.."\nOK expected failure\n") end
541 return
542 end
543 end
544 -- failed because of unmatched string or boolean result
545 local function passfail(status)
546 if status == PASS then return "PASS" else return "FAIL" end
547 end
548 print(head.." *FAILED*"..
549 "\noutcome="..passfail(outcome)..
550 "\nactual= "..passfail(result)..
551 "\n--chunk---------------------------------\n"..chunk..
552 "\n--expected------------------------------\n"..matcher..
553 "\n--actual--------------------------------\n"..output..
554 "\n\n")
555 end
556 end
557 ------------------------------------------------------------------
558 -- perform auto testing
559 ------------------------------------------------------------------
560 for i,test_case in ipairs(test_cases) do
561 do_test_case(i, test_case)
562 end
563end
564
565auto_test()
566--]=====]