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