aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_llex.lua
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_llex.lua')
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_llex.lua504
1 files changed, 0 insertions, 504 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_llex.lua b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_llex.lua
deleted file mode 100644
index 6bc834d..0000000
--- a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_llex.lua
+++ /dev/null
@@ -1,504 +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
20require("../lzio")
21require("../llex")
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",
120 "--[[bovine]]",
121 PASS, "1 TK_EOS",
122 },
123 -------------------------------------------------------------
124 { "unterminated block comment 1",
125 "--[[bovine",
126 FAIL, ":1: unfinished long comment near `<eof>'",
127 },
128 -------------------------------------------------------------
129 { "unterminated block comment 2",
130 "--[[bovine]",
131 FAIL, ":1: unfinished long comment near `<eof>'",
132 },
133 -------------------------------------------------------------
134 { "unterminated block comment 3",
135 "--[[bovine\nmoo moo\nwoof",
136 FAIL, ":3: unfinished long comment near `<eof>'",
137 },
138 -------------------------------------------------------------
139 { "basic long string",
140 "\n[[bovine]]\n",
141 PASS, "2 TK_STRING = bovine\n3 TK_EOS",
142 },
143 -------------------------------------------------------------
144 { "first newline consumed in long string",
145 "[[\nmoo]]",
146 PASS, "2 TK_STRING = moo\n2 TK_EOS",
147 },
148 -------------------------------------------------------------
149 { "multiline long string",
150 "[[moo\nmoo moo\n]]",
151 PASS, "3 TK_STRING = moo\nmoo moo\n\n3 TK_EOS",
152 },
153 -------------------------------------------------------------
154 { "unterminated long string 1",
155 "\n[[\nbovine",
156 FAIL, ":3: unfinished long string near `<eof>'",
157 },
158 -------------------------------------------------------------
159 { "unterminated long string 2",
160 "[[bovine]",
161 FAIL, ":1: unfinished long string near `<eof>'",
162 },
163 -------------------------------------------------------------
164 { "unterminated long string 3",
165 "[[[[ \n",
166 FAIL, ":2: unfinished long string near `<eof>'",
167 },
168 -------------------------------------------------------------
169 { "nested long string 1",
170 "[[moo[[moo]]moo]]",
171 PASS, "moo[[moo]]moo",
172 },
173 -------------------------------------------------------------
174 { "nested long string 2",
175 "[[moo[[moo[[[[]]]]moo]]moo]]",
176 PASS, "moo[[moo[[[[]]]]moo]]moo",
177 },
178 -------------------------------------------------------------
179 { "nested long string 3",
180 "[[[[[[]]]][[[[]]]]]]",
181 PASS, "[[[[]]]][[[[]]]]",
182 },
183 -------------------------------------------------------------
184 { "brackets in long strings 1",
185 "[[moo[moo]]",
186 PASS, "moo[moo",
187 },
188 -------------------------------------------------------------
189 { "brackets in long strings 2",
190 "[[moo[[moo]moo]]moo]]",
191 PASS, "moo[[moo]moo]]moo",
192 },
193 -------------------------------------------------------------
194 { "unprocessed escapes in long strings",
195 [[ [[\a\b\f\n\r\t\v\123]] ]],
196 PASS, [[\a\b\f\n\r\t\v\123]],
197 },
198 -------------------------------------------------------------
199 { "unbalanced long string",
200 "[[moo]]moo]]",
201 PASS, "1 TK_STRING = moo\n1 TK_NAME = moo\n1 CHAR = ']'\n1 CHAR = ']'\n1 TK_EOS",
202 },
203 -------------------------------------------------------------
204 { "keywords 1",
205 "and break do else",
206 PASS, "1 TK_AND\n1 TK_BREAK\n1 TK_DO\n1 TK_ELSE\n1 TK_EOS",
207 },
208 -------------------------------------------------------------
209 { "keywords 2",
210 "elseif end false for",
211 PASS, "1 TK_ELSEIF\n1 TK_END\n1 TK_FALSE\n1 TK_FOR\n1 TK_EOS",
212 },
213 -------------------------------------------------------------
214 { "keywords 3",
215 "function if in local nil",
216 PASS, "1 TK_FUNCTION\n1 TK_IF\n1 TK_IN\n1 TK_LOCAL\n1 TK_NIL\n1 TK_EOS",
217 },
218 -------------------------------------------------------------
219 { "keywords 4",
220 "not or repeat return",
221 PASS, "1 TK_NOT\n1 TK_OR\n1 TK_REPEAT\n1 TK_RETURN\n1 TK_EOS",
222 },
223 -------------------------------------------------------------
224 { "keywords 5",
225 "then true until while",
226 PASS, "1 TK_THEN\n1 TK_TRUE\n1 TK_UNTIL\n1 TK_WHILE\n1 TK_EOS",
227 },
228 -------------------------------------------------------------
229 { "concat and dots",
230 ".. ...",
231 PASS, "1 TK_CONCAT\n1 TK_DOTS\n1 TK_EOS",
232 },
233 -------------------------------------------------------------
234 { "shbang handling 1",
235 "#blahblah",
236 PASS, "1 TK_EOS",
237 },
238 -------------------------------------------------------------
239 { "shbang handling 2",
240 "#blahblah\nmoo moo\n",
241 PASS, "2 TK_NAME = moo\n2 TK_NAME = moo\n3 TK_EOS",
242 },
243 -------------------------------------------------------------
244 { "empty string",
245 [['']],
246 PASS, "1 TK_STRING = \n1 TK_EOS",
247 },
248 -------------------------------------------------------------
249 { "single-quoted string",
250 [['bovine']],
251 PASS, "1 TK_STRING = bovine\n1 TK_EOS",
252 },
253 -------------------------------------------------------------
254 { "double-quoted string",
255 [["bovine"]],
256 PASS, "1 TK_STRING = bovine\n1 TK_EOS",
257 },
258 -------------------------------------------------------------
259 { "unterminated string 1",
260 [['moo ]],
261 FAIL, ":1: unfinished string near `<eof>'",
262 },
263 -------------------------------------------------------------
264 { "unterminated string 2",
265 [["moo \n]],
266 FAIL, ":1: unfinished string near `<eof>'",
267 },
268 -------------------------------------------------------------
269 { "escaped newline in string, line number counted",
270 "\"moo\\\nmoo\\\nmoo\"",
271 PASS, "3 TK_STRING = moo\nmoo\nmoo\n3 TK_EOS",
272 },
273 -------------------------------------------------------------
274 { "escaped characters in string 1",
275 [["moo\amoo"]],
276 PASS, "1 TK_STRING = moo\amoo",
277 },
278 -------------------------------------------------------------
279 { "escaped characters in string 2",
280 [["moo\bmoo"]],
281 PASS, "1 TK_STRING = moo\bmoo",
282 },
283 -------------------------------------------------------------
284 { "escaped characters in string 3",
285 [["moo\f\n\r\t\vmoo"]],
286 PASS, "1 TK_STRING = moo\f\n\r\t\vmoo",
287 },
288 -------------------------------------------------------------
289 { "escaped characters in string 4",
290 [["\\ \" \' \? \[ \]"]],
291 PASS, "1 TK_STRING = \\ \" \' \? \[ \]",
292 },
293 -------------------------------------------------------------
294 { "escaped characters in string 5",
295 [["\z \k \: \;"]],
296 PASS, "1 TK_STRING = z k : ;",
297 },
298 -------------------------------------------------------------
299 { "escaped characters in string 6",
300 [["\8 \65 \160 \180K \097097"]],
301 PASS, "1 TK_STRING = \8 \65 \160 \180K \097097\n",
302 },
303 -------------------------------------------------------------
304 { "escaped characters in string 7",
305 [["\666"]],
306 FAIL, ":1: escape sequence too large near `\"'",
307 },
308 -------------------------------------------------------------
309 { "simple numbers",
310 "123 123+",
311 PASS, "1 TK_NUMBER = 123\n1 TK_NUMBER = 123\n1 CHAR = '+'\n1 TK_EOS",
312 },
313 -------------------------------------------------------------
314 { "longer numbers",
315 "1234567890 12345678901234567890",
316 PASS, "1 TK_NUMBER = 1234567890\n1 TK_NUMBER = 1.2345678901235e+19\n",
317 },
318 -------------------------------------------------------------
319 { "fractional numbers",
320 ".123 .12345678901234567890",
321 PASS, "1 TK_NUMBER = 0.123\n1 TK_NUMBER = 0.12345678901235\n",
322 },
323 -------------------------------------------------------------
324 { "more numbers with decimal points",
325 "12345.67890 1.1.",
326 PASS, "1 TK_NUMBER = 12345.6789\n1 TK_NUMBER = 1.1\n1 CHAR = '.'\n",
327 },
328 -------------------------------------------------------------
329 { "double decimal points",
330 ".1.1",
331 FAIL, ":1: malformed number near `.1.1'",
332 },
333 -------------------------------------------------------------
334 { "double dots within numbers",
335 "1..1",
336 FAIL, ":1: ambiguous syntax (decimal point x string concatenation) near `1..'",
337 },
338 -------------------------------------------------------------
339 { "incomplete exponential numbers",
340 "123e",
341 FAIL, ":1: malformed number near `123e'",
342 },
343 -------------------------------------------------------------
344 { "exponential numbers 1",
345 "1234e5 1234e5.",
346 PASS, "1 TK_NUMBER = 123400000\n1 TK_NUMBER = 123400000\n1 CHAR = '.'",
347 },
348 -------------------------------------------------------------
349 { "exponential numbers 2",
350 "1234e56 1.23e123",
351 PASS, "1 TK_NUMBER = 1.234e+59\n1 TK_NUMBER = 1.23e+123\n",
352 },
353 -------------------------------------------------------------
354 { "exponential numbers 3",
355 "12.34e+",
356 FAIL, ":1: malformed number near `12.34e+'",
357 },
358 -------------------------------------------------------------
359 { "exponential numbers 4",
360 "12.34e+5 123.4e-5 1234.E+5",
361 PASS, "1 TK_NUMBER = 1234000\n1 TK_NUMBER = 0.001234\n1 TK_NUMBER = 123400000\n",
362 },
363 -------------------------------------------------------------
364 { "single character symbols 1",
365 "= > < ~",
366 PASS, "1 CHAR = '='\n1 CHAR = '>'\n1 CHAR = '<'\n1 CHAR = '~'\n",
367 },
368 -------------------------------------------------------------
369 { "double character symbols",
370 "== >= <= ~=",
371 PASS, "1 TK_EQ\n1 TK_GE\n1 TK_LE\n1 TK_NE\n",
372 },
373 -------------------------------------------------------------
374 { "simple identifiers",
375 "abc ABC",
376 PASS, "1 TK_NAME = abc\n1 TK_NAME = ABC\n1 TK_EOS",
377 },
378 -------------------------------------------------------------
379 { "more identifiers",
380 "_abc _ABC",
381 PASS, "1 TK_NAME = _abc\n1 TK_NAME = _ABC\n1 TK_EOS",
382 },
383 -------------------------------------------------------------
384 { "still more identifiers",
385 "_aB_ _123",
386 PASS, "1 TK_NAME = _aB_\n1 TK_NAME = _123\n1 TK_EOS",
387 },
388 -------------------------------------------------------------
389 { "invalid control character",
390 "\4",
391 FAIL, ":1: invalid control char near `char(4)'",
392 },
393 -------------------------------------------------------------
394 { "single character symbols 2",
395 "` ! @ $ %",
396 PASS, "1 CHAR = '`'\n1 CHAR = '!'\n1 CHAR = '@'\n1 CHAR = '$'\n1 CHAR = '%'\n",
397 },
398 -------------------------------------------------------------
399 { "single character symbols 3",
400 "^ & * ( )",
401 PASS, "1 CHAR = '^'\n1 CHAR = '&'\n1 CHAR = '*'\n1 CHAR = '('\n1 CHAR = ')'\n",
402 },
403 -------------------------------------------------------------
404 { "single character symbols 4",
405 "_ - + \\ |",
406 PASS, "1 TK_NAME = _\n1 CHAR = '-'\n1 CHAR = '+'\n1 CHAR = '\\'\n1 CHAR = '|'\n",
407 },
408 -------------------------------------------------------------
409 { "single character symbols 5",
410 "{ } [ ] :",
411 PASS, "1 CHAR = '{'\n1 CHAR = '}'\n1 CHAR = '['\n1 CHAR = ']'\n1 CHAR = ':'\n",
412 },
413 -------------------------------------------------------------
414 { "single character symbols 6",
415 "; , . / ?",
416 PASS, "1 CHAR = ';'\n1 CHAR = ','\n1 CHAR = '.'\n1 CHAR = '/'\n1 CHAR = '?'\n",
417 },
418 -------------------------------------------------------------
419 }
420 ------------------------------------------------------------------
421 -- perform a test case
422 ------------------------------------------------------------------
423 function do_test_case(count, test_case)
424 if comment == "" then return end -- skip empty entries
425 local comment, chunk, outcome, matcher = unpack(test_case)
426 local result = PASS
427 local output = ""
428 -- initialize lexer
429 local L, LS = {}, {}
430 local z = luaZ:init(luaZ:make_getS(chunk), nil, "=test")
431 luaX:setinput(L, LS, z, z.name)
432 -- lexer test loop
433 repeat
434 -- protected call
435 local status, token = pcall(luaX.lex, luaX, LS, LS.t)
436 LS.t.token = token
437 output = output..LS.linenumber.." "
438 if status then
439 -- successful call
440 if string.len(token) > 1 then
441 if token == "TK_NAME"
442 or token == "TK_NUMBER"
443 or token == "TK_STRING" then
444 token = token.." = "..LS.t.seminfo
445 end
446 elseif string.byte(token) >= 32 then -- displayable chars
447 token = "CHAR = '"..token.."'"
448 else -- control characters
449 token = "CHAR = (".. string.byte(token)..")"
450 end
451 output = output..token.."\n"
452 else
453 -- failed call
454 output = output..token -- token is the error message
455 result = FAIL
456 break
457 end
458 until LS.t.token == "TK_EOS"
459 -- decision making and reporting
460 local head = "Test "..count..": "..comment
461 if matcher == "" then
462 -- nothing to check against, display for manual check
463 print(head.."\nMANUAL please check manually"..
464 "\n--chunk---------------------------------\n"..chunk..
465 "\n--actual--------------------------------\n"..output..
466 "\n\n")
467 return
468 else
469 if outcome == PASS then
470 -- success expected, may be a partial match
471 if string.find(output, matcher, 1, 1) and result == PASS then
472 if not BRIEF then print(head.."\nOK expected success\n") end
473 return
474 end
475 else
476 -- failure expected, may be a partial match
477 if string.find(output, matcher, 1, 1) and result == FAIL then
478 if not BRIEF then print(head.."\nOK expected failure\n") end
479 return
480 end
481 end
482 -- failed because of unmatched string or boolean result
483 local function passfail(status)
484 if status == PASS then return "PASS" else return "FAIL" end
485 end
486 print(head.." *FAILED*"..
487 "\noutcome="..passfail(outcome)..
488 "\nactual= "..passfail(result)..
489 "\n--chunk---------------------------------\n"..chunk..
490 "\n--expected------------------------------\n"..matcher..
491 "\n--actual--------------------------------\n"..output..
492 "\n\n")
493 end
494 end
495 ------------------------------------------------------------------
496 -- perform auto testing
497 ------------------------------------------------------------------
498 for i,test_case in ipairs(test_cases) do
499 do_test_case(i, test_case)
500 end
501end
502
503auto_test()
504--]]