diff options
author | David Walter Seikel | 2012-01-23 21:58:02 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-23 21:58:02 +1000 |
commit | 2d1df4714e2736dbde7855ddcd76b4c1de822fa5 (patch) | |
tree | c80e4622631c92dbe8dd6375d187702d084c2f2b /LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test | |
parent | Remove the conflict, and the comment. lol (diff) | |
download | SledjHamr-2d1df4714e2736dbde7855ddcd76b4c1de822fa5.zip SledjHamr-2d1df4714e2736dbde7855ddcd76b4c1de822fa5.tar.gz SledjHamr-2d1df4714e2736dbde7855ddcd76b4c1de822fa5.tar.bz2 SledjHamr-2d1df4714e2736dbde7855ddcd76b4c1de822fa5.tar.xz |
Added a big bunch of example lua scripts for testing the speed of lua compiling.
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test')
8 files changed, 1195 insertions, 0 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/bench_llex.lua b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/bench_llex.lua new file mode 100644 index 0000000..0c9403e --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/bench_llex.lua | |||
@@ -0,0 +1,99 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | bench_llex.lua | ||
4 | Benchmark 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 | require("../lzio") | ||
16 | require("../llex") | ||
17 | luaX:init() | ||
18 | |||
19 | ------------------------------------------------------------------------ | ||
20 | -- load in a standard set of sample files | ||
21 | -- * file set is 5.0.3 front end set sans luac.lua | ||
22 | ------------------------------------------------------------------------ | ||
23 | |||
24 | local fileset, totalsize = {}, 0 | ||
25 | for fn in string.gfind([[ | ||
26 | ../lcode.lua | ||
27 | ../ldump.lua | ||
28 | ../llex.lua | ||
29 | ../lopcodes.lua | ||
30 | ../lparser.lua | ||
31 | ../lzio.lua | ||
32 | ]], "%S+") do | ||
33 | table.insert(fileset, fn) | ||
34 | end | ||
35 | |||
36 | for i = 1, table.getn(fileset) do | ||
37 | local fn = fileset[i] | ||
38 | local inf = io.open(fn, "rb") | ||
39 | if not inf then | ||
40 | error("failed to open "..fn.." for reading") | ||
41 | end | ||
42 | local data = inf:read("*a") | ||
43 | local data_sz = string.len(data) | ||
44 | inf:close() | ||
45 | if not data or data_sz == 0 then | ||
46 | error("failed to read data from "..fn.." or file is zero-length") | ||
47 | end | ||
48 | totalsize = totalsize + data_sz | ||
49 | fileset[i] = data | ||
50 | end | ||
51 | |||
52 | ------------------------------------------------------------------------ | ||
53 | -- benchmark tester | ||
54 | ------------------------------------------------------------------------ | ||
55 | |||
56 | local DURATION = 5 -- how long the benchmark should run | ||
57 | |||
58 | local L = {} -- LuaState | ||
59 | local LS = {} -- LexState | ||
60 | |||
61 | local time = os.time | ||
62 | local lexedsize = 0 | ||
63 | local tnow, elapsed = time(), 0 | ||
64 | |||
65 | while time() == tnow do end -- wait for second to click over | ||
66 | tnow = time() | ||
67 | |||
68 | while true do | ||
69 | for i = 1, table.getn(fileset) do | ||
70 | ------------------------------------------------------------ | ||
71 | local chunk = fileset[i] | ||
72 | local z = luaZ:init(luaZ:make_getS(chunk), nil, "=string") | ||
73 | luaX:setinput(L, LS, z, z.name) | ||
74 | while true do | ||
75 | LS.t.token = luaX:lex(LS, LS.t) | ||
76 | local tok, seminfo = LS.t.token, LS.t.seminfo | ||
77 | if tok == "TK_EOS" then break end | ||
78 | end | ||
79 | ------------------------------------------------------------ | ||
80 | lexedsize = lexedsize + string.len(chunk) | ||
81 | if time() > tnow then | ||
82 | tnow = time() | ||
83 | elapsed = elapsed + 1 | ||
84 | if elapsed >= DURATION then | ||
85 | -- report performance of lexer | ||
86 | lexedsize = lexedsize / 1024 | ||
87 | local speed = lexedsize / DURATION | ||
88 | print("Lexer performance:") | ||
89 | print("Size of data lexed (KB): "..string.format("%.1f", lexedsize)) | ||
90 | print("Speed of lexer (KB/s): "..string.format("%.1f", speed)) | ||
91 | -- repeat until user breaks program | ||
92 | elapsed = 0 | ||
93 | end | ||
94 | end | ||
95 | ------------------------------------------------------------ | ||
96 | end--for | ||
97 | end--while | ||
98 | |||
99 | -- end of script | ||
diff --git a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/sample.lua b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/sample.lua new file mode 100644 index 0000000..dc6eaee --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/sample.lua | |||
@@ -0,0 +1,3 @@ | |||
1 | local a = 47 | ||
2 | local b = "hello, world!" | ||
3 | print(a, b) | ||
diff --git a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_ldump.lua b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_ldump.lua new file mode 100644 index 0000000..d867688 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_ldump.lua | |||
@@ -0,0 +1,98 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | test_ldump.lua | ||
4 | Test for ldump.lua | ||
5 | This file is part of Yueliang. | ||
6 | |||
7 | Copyright (c) 2005 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 | -- test dump chunkwriter style | ||
17 | ------------------------------------------------------------------------ | ||
18 | |||
19 | require("../lopcodes") | ||
20 | require("../ldump") | ||
21 | |||
22 | -- Original typedef: | ||
23 | --int (*lua_Chunkwriter) (lua_State *L, const void* p, size_t sz, void* ud); | ||
24 | |||
25 | local MyWriter, MyBuff = luaU:make_setS() | ||
26 | if not MyWriter then | ||
27 | error("failed to initialize using make_setS") | ||
28 | end | ||
29 | MyWriter("hello, ", MyBuff) | ||
30 | MyWriter("world!", MyBuff) | ||
31 | print(MyBuff.data) | ||
32 | |||
33 | local MyWriter, MyBuff = luaU:make_setF("try.txt") | ||
34 | if not MyWriter then | ||
35 | error("failed to initialize using make_setF") | ||
36 | end | ||
37 | MyWriter("hello, ", MyBuff) | ||
38 | MyWriter("world!", MyBuff) | ||
39 | MyWriter(nil, MyBuff) | ||
40 | |||
41 | ------------------------------------------------------------------------ | ||
42 | -- test output of a function prototype | ||
43 | -- * data can be copied from a ChunkSpy listing output | ||
44 | ------------------------------------------------------------------------ | ||
45 | -- local a = 47 | ||
46 | -- local b = "hello, world!" | ||
47 | -- print(a, b) | ||
48 | ------------------------------------------------------------------------ | ||
49 | |||
50 | local F = {} | ||
51 | F.source = "sample.lua" | ||
52 | F.lineDefined = 0 | ||
53 | F.nups = 0 | ||
54 | F.numparams = 0 | ||
55 | F.is_vararg = 0 | ||
56 | F.maxstacksize = 5 | ||
57 | F.sizelineinfo = 7 | ||
58 | F.lineinfo = {} | ||
59 | F.lineinfo[0] = 1 | ||
60 | F.lineinfo[1] = 2 | ||
61 | F.lineinfo[2] = 3 | ||
62 | F.lineinfo[3] = 3 | ||
63 | F.lineinfo[4] = 3 | ||
64 | F.lineinfo[5] = 3 | ||
65 | F.lineinfo[6] = 3 | ||
66 | F.sizelocvars = 2 | ||
67 | F.locvars = {} | ||
68 | F.locvars[0] = { varname = "a", startpc = 1, endpc = 6 } | ||
69 | F.locvars[1] = { varname = "b", startpc = 2, endpc = 6 } | ||
70 | F.sizeupvalues = 0 | ||
71 | F.upvalues = {} | ||
72 | F.sizek = 3 | ||
73 | F.k = {} | ||
74 | F.k[0] = { value = 47 } | ||
75 | F.k[1] = { value = "hello, world!" } | ||
76 | F.k[2] = { value = "print" } | ||
77 | F.sizep = 0 | ||
78 | F.p = {} | ||
79 | F.sizecode = 7 | ||
80 | F.code = {} | ||
81 | F.code[0] = { OP = 1, A = 0, Bx = 0 } | ||
82 | F.code[1] = { OP = 1, A = 1, Bx = 1 } | ||
83 | F.code[2] = { OP = 5, A = 2, Bx = 2 } | ||
84 | F.code[3] = { OP = 0, A = 3, B = 0, C = 0 } | ||
85 | F.code[4] = { OP = 0, A = 4, B = 1, C = 0 } | ||
86 | F.code[5] = { OP = 25, A = 2, B = 3, C = 1 } | ||
87 | F.code[6] = { OP = 27, A = 0, B = 1, C = 0 } | ||
88 | |||
89 | local L = {} | ||
90 | --[[ | ||
91 | local Writer, Buff = luaU:make_setS() | ||
92 | luaU:dump(L, F, Writer, Buff) | ||
93 | for i = 1, string.len(Buff.data) do | ||
94 | io.stdout:write(string.byte(string.sub(Buff.data, i, i)).." ") | ||
95 | end | ||
96 | --]] | ||
97 | local Writer, Buff = luaU:make_setF("try.out") | ||
98 | luaU:dump(L, F, Writer, Buff) | ||
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 new file mode 100644 index 0000000..6bc834d --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_llex.lua | |||
@@ -0,0 +1,504 @@ | |||
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 | ------------------------------------------------------------------------ | ||
18 | BRIEF = true -- if set to true, messages are less verbose | ||
19 | |||
20 | require("../lzio") | ||
21 | require("../llex") | ||
22 | luaX:init() | ||
23 | |||
24 | ------------------------------------------------------------------------ | ||
25 | -- simple manual tests | ||
26 | ------------------------------------------------------------------------ | ||
27 | |||
28 | --[[ | ||
29 | local L = {} -- LuaState | ||
30 | local LS = {} -- LexState | ||
31 | |||
32 | local 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 | ||
49 | end | ||
50 | |||
51 | local function try_string(chunk) | ||
52 | dump(luaZ:init(luaZ:make_getS(chunk), nil, "=string")) | ||
53 | end | ||
54 | local function try_file(filename) | ||
55 | dump(luaZ:init(luaZ:make_getF(filename), nil, filename)) | ||
56 | end | ||
57 | |||
58 | z = try_string("local c = luaZ:zgetc(z)") | ||
59 | z = try_file("test_lzio.lua") | ||
60 | z = try_file("test_llex.lua") | ||
61 | os.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 | -- [[ | ||
75 | local 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 | ||
501 | end | ||
502 | |||
503 | auto_test() | ||
504 | --]] | ||
diff --git a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_lparser.lua b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_lparser.lua new file mode 100644 index 0000000..b9400cc --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_lparser.lua | |||
@@ -0,0 +1,60 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | test_lparser.lua | ||
4 | Test for lparser.lua | ||
5 | This file is part of Yueliang. | ||
6 | |||
7 | Copyright (c) 2005 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 | -- test the whole kaboodle | ||
17 | ------------------------------------------------------------------------ | ||
18 | |||
19 | require("../lzio") | ||
20 | require("../llex") | ||
21 | require("../lopcodes") | ||
22 | require("../ldump") | ||
23 | require("../lcode") | ||
24 | require("../lparser") | ||
25 | |||
26 | function lua_assert(test) | ||
27 | if not test then error("assertion failed!") end | ||
28 | end | ||
29 | |||
30 | luaX:init() | ||
31 | |||
32 | ------------------------------------------------------------------------ | ||
33 | -- try 1 | ||
34 | ------------------------------------------------------------------------ | ||
35 | |||
36 | local zio = luaZ:init(luaZ:make_getS("local a = 1"), nil, "=string") | ||
37 | local LuaState = {} | ||
38 | local Func = luaY:parser(LuaState, zio, nil) | ||
39 | |||
40 | --[[ | ||
41 | for i, v in Func do | ||
42 | if type(v) == "string" or type(v) == "number" then | ||
43 | print(i, v) | ||
44 | elseif type(v) == "table" then | ||
45 | print(i, "TABLE") | ||
46 | end | ||
47 | end | ||
48 | --]] | ||
49 | |||
50 | local Writer, Buff = luaU:make_setF("parse1.out") | ||
51 | luaU:dump(LuaState, Func, Writer, Buff) | ||
52 | |||
53 | ------------------------------------------------------------------------ | ||
54 | -- try 2 | ||
55 | ------------------------------------------------------------------------ | ||
56 | |||
57 | zio = luaZ:init(luaZ:make_getF("sample.lua"), nil, "@sample.lua") | ||
58 | Func = luaY:parser(LuaState, zio, nil) | ||
59 | Writer, Buff = luaU:make_setF("parse2.out") | ||
60 | luaU:dump(LuaState, Func, Writer, Buff) | ||
diff --git a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_lparser2.lua b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_lparser2.lua new file mode 100644 index 0000000..b912e68 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_lparser2.lua | |||
@@ -0,0 +1,202 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | test_lparser2.lua | ||
4 | Test for lparser.lua, using the test case file | ||
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 | -- Notes: | ||
17 | -- * the test cases are in the test_lua directory (test_parser-5.0.lua) | ||
18 | ----------------------------------------------------------------------]] | ||
19 | |||
20 | -- * true if you want an output of all failure cases in native Lua, | ||
21 | -- for checking whether test cases fail where you intend them to | ||
22 | local DEBUG_FAILS = false | ||
23 | |||
24 | ------------------------------------------------------------------------ | ||
25 | -- test the whole kaboodle | ||
26 | ------------------------------------------------------------------------ | ||
27 | |||
28 | require("../lzio") | ||
29 | require("../llex") | ||
30 | require("../lopcodes") | ||
31 | require("../ldump") | ||
32 | require("../lcode") | ||
33 | require("../lparser") | ||
34 | |||
35 | function lua_assert(test) | ||
36 | if not test then error("assertion failed!") end | ||
37 | end | ||
38 | |||
39 | luaX:init() | ||
40 | |||
41 | ------------------------------------------------------------------------ | ||
42 | -- load test cases | ||
43 | ------------------------------------------------------------------------ | ||
44 | |||
45 | require("../../test_lua/test_parser-5.0") | ||
46 | |||
47 | local test, expect, heading = {}, {}, {} | ||
48 | local total, total_pass, total_fail = 0, 0, 0 | ||
49 | |||
50 | for ln in string.gfind(tests_source, "([^\n]*)\n") do | ||
51 | if string.find(ln, "^%s*%-%-") then | ||
52 | -- comment, ignore | ||
53 | else | ||
54 | local m, _, head = string.find(ln, "^%s*(TESTS:%s*.*)$") | ||
55 | if m then | ||
56 | heading[total + 1] = head -- informational heading | ||
57 | else | ||
58 | total = total + 1 | ||
59 | local n, _, flag = string.find(ln, "%s*%-%-%s*FAIL%s*$") | ||
60 | if n then -- FAIL test case | ||
61 | ln = string.sub(ln, 1, n - 1) -- remove comment | ||
62 | expect[total] = "FAIL" | ||
63 | total_fail = total_fail + 1 | ||
64 | else -- PASS test case | ||
65 | expect[total] = "PASS" | ||
66 | total_pass = total_pass + 1 | ||
67 | end--n | ||
68 | test[total] = ln | ||
69 | end--m | ||
70 | end--ln | ||
71 | end--for | ||
72 | |||
73 | print("Tests loaded: "..total.." (total), " | ||
74 | ..total_pass.." (passes), " | ||
75 | ..total_fail.." (fails)") | ||
76 | |||
77 | ------------------------------------------------------------------------ | ||
78 | -- verify test cases using native Lua | ||
79 | ------------------------------------------------------------------------ | ||
80 | |||
81 | local last_head = "TESTS: no heading yet" | ||
82 | for i = 1, total do | ||
83 | local test_case, expected, head = test[i], expect[i], heading[i] | ||
84 | -- show progress | ||
85 | if head then | ||
86 | last_head = head | ||
87 | if DEBUG_FAILS then print("\n"..head.."\n") end | ||
88 | end | ||
89 | ------------------------------------------------------------------ | ||
90 | -- perform test | ||
91 | local f, err = loadstring(test_case) | ||
92 | -- look at outcome | ||
93 | ------------------------------------------------------------------ | ||
94 | if f then-- actual PASS | ||
95 | if expected == "FAIL" then | ||
96 | print("\nVerified as PASS but expected to FAIL".. | ||
97 | "\n-------------------------------------") | ||
98 | print("Lastest heading: "..last_head) | ||
99 | print("TEST: "..test_case) | ||
100 | os.exit() | ||
101 | end | ||
102 | ------------------------------------------------------------------ | ||
103 | else-- actual FAIL | ||
104 | if expected == "PASS" then | ||
105 | print("\nVerified as FAIL but expected to PASS".. | ||
106 | "\n-------------------------------------") | ||
107 | print("Lastest heading: "..last_head) | ||
108 | print("TEST: "..test_case) | ||
109 | print("ERROR: "..err) | ||
110 | os.exit() | ||
111 | end | ||
112 | if DEBUG_FAILS then | ||
113 | print("TEST: "..test_case) | ||
114 | print("ERROR: "..err.."\n") | ||
115 | end | ||
116 | ------------------------------------------------------------------ | ||
117 | end--f | ||
118 | end--for | ||
119 | |||
120 | print("Test cases verified using native Lua, no anomalies.") | ||
121 | |||
122 | ------------------------------------------------------------------------ | ||
123 | -- dump binary chunks to a file if something goes wrong | ||
124 | ------------------------------------------------------------------------ | ||
125 | local function Dump(data, filename) | ||
126 | h = io.open(filename, "wb") | ||
127 | if not h then error("failed to open "..filename.." for writing") end | ||
128 | h:write(data) | ||
129 | h:close() | ||
130 | end | ||
131 | |||
132 | ------------------------------------------------------------------------ | ||
133 | -- test using Yueliang front end | ||
134 | ------------------------------------------------------------------------ | ||
135 | |||
136 | local last_head = "TESTS: no heading yet" | ||
137 | for i = 1, total do | ||
138 | local test_case, expected, head = test[i], expect[i], heading[i] | ||
139 | -- show progress | ||
140 | if head then last_head = head end | ||
141 | ------------------------------------------------------------------ | ||
142 | -- perform test | ||
143 | local LuaState = {} | ||
144 | local zio = luaZ:init(luaZ:make_getS(test_case), nil, "test") | ||
145 | local status, func = pcall(luaY.parser, luaY, LuaState, zio, nil) | ||
146 | -- look at outcome | ||
147 | ------------------------------------------------------------------ | ||
148 | if status then-- actual PASS | ||
149 | if expected == "PASS" then | ||
150 | -- actual PASS and expected PASS, so check binary chunks | ||
151 | local writer, buff = luaU:make_setS() | ||
152 | luaU:dump(LuaState, func, writer, buff) | ||
153 | local bc1 = buff.data -- Yueliang's output | ||
154 | local f = loadstring(test_case, "test") | ||
155 | local bc2 = string.dump(f) -- Lua's output | ||
156 | local die | ||
157 | -- compare outputs | ||
158 | if string.len(bc1) ~= string.len(bc2) then | ||
159 | Dump(bc1, "bc1.out") | ||
160 | Dump(bc2, "bc2.out") | ||
161 | die = "binary chunk sizes different" | ||
162 | elseif bc1 ~= bc2 then | ||
163 | Dump(bc1, "bc1.out") | ||
164 | Dump(bc2, "bc2.out") | ||
165 | die = "binary chunks different" | ||
166 | else | ||
167 | -- everything checks out! | ||
168 | end | ||
169 | if die then | ||
170 | print("\nTested PASS and expected to PASS, but chunks different".. | ||
171 | "\n------------------------------------------------------") | ||
172 | print("Reason: "..die) | ||
173 | print("Lastest heading: "..last_head) | ||
174 | print("TEST: "..test_case) | ||
175 | os.exit() | ||
176 | end | ||
177 | else-- expected FAIL | ||
178 | print("\nTested as PASS but expected to FAIL".. | ||
179 | "\n-----------------------------------") | ||
180 | print("Lastest heading: "..last_head) | ||
181 | print("TEST: "..test_case) | ||
182 | os.exit() | ||
183 | end | ||
184 | ------------------------------------------------------------------ | ||
185 | else-- actual FAIL | ||
186 | if expected == "PASS" then | ||
187 | print("\nTested as FAIL but expected to PASS".. | ||
188 | "\n-----------------------------------") | ||
189 | print("Lastest heading: "..last_head) | ||
190 | print("TEST: "..test_case) | ||
191 | print("ERROR: "..err) | ||
192 | os.exit() | ||
193 | end | ||
194 | ------------------------------------------------------------------ | ||
195 | end--status | ||
196 | io.stdout:write("\rTesting ["..i.."]...") | ||
197 | end--for | ||
198 | print(" done.") | ||
199 | |||
200 | print("Test cases run on Yueliang, no anomalies.") | ||
201 | |||
202 | -- end | ||
diff --git a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_lzio.lua b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_lzio.lua new file mode 100644 index 0000000..cfd3f4b --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_lzio.lua | |||
@@ -0,0 +1,55 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | test_lzio.lua | ||
4 | Test for lzio.lua | ||
5 | This file is part of Yueliang. | ||
6 | |||
7 | Copyright (c) 2005 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 | -- manual test for lzio.lua lua-style chunk reader | ||
16 | |||
17 | require("../lzio") | ||
18 | |||
19 | local z | ||
20 | function dump(z) | ||
21 | while true do | ||
22 | local c = luaZ:zgetc(z) | ||
23 | io.stdout:write("("..c..")") | ||
24 | if c == "EOZ" then break end | ||
25 | end | ||
26 | io.stdout:write("\n") | ||
27 | end | ||
28 | |||
29 | -- luaZ:make_getS or luaZ:make_getF creates a chunk reader | ||
30 | -- luaZ:init makes a zio stream | ||
31 | |||
32 | -- [[ | ||
33 | z = luaZ:init(luaZ:make_getS("hello, world!"), nil, "=string") | ||
34 | dump(z) | ||
35 | z = luaZ:init(luaZ:make_getS(", world!"), "hello", "=string") | ||
36 | dump(z) | ||
37 | z = luaZ:init(luaZ:make_getS("line1\nline2\n"), "", "=string") | ||
38 | dump(z) | ||
39 | z = luaZ:init(luaZ:make_getF("test_lzio.lua"), nil, "=string") | ||
40 | dump(z) | ||
41 | --]] | ||
42 | |||
43 | -- test read beyond end of file | ||
44 | -- bug reported by Adam429 | ||
45 | --[[ | ||
46 | z = luaZ:init(luaZ:make_getF("test_lzio.lua"), nil, "=string") | ||
47 | while true do | ||
48 | local c = luaZ:zgetc(z) | ||
49 | io.stdout:write("("..c..")") | ||
50 | if c == "EOZ" then break end | ||
51 | end | ||
52 | print(luaZ:zgetc(z)) | ||
53 | print(luaZ:zgetc(z)) | ||
54 | io.stdout:write("\n") | ||
55 | --]] | ||
diff --git a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_number.lua b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_number.lua new file mode 100644 index 0000000..eeabecb --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/test_number.lua | |||
@@ -0,0 +1,174 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | test_number.lua | ||
4 | Test for Lua-based number conversion functions in ldump.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 | -- Notes: | ||
17 | -- * luaU:from_int(value) does not have overflow checks, but this | ||
18 | -- can presumably be put in for debugging purposes. | ||
19 | -- * TODO: double conversion does not support denormals or NaNs | ||
20 | -- * apparently 0/0 == 0/0 is false (Lua 5.0.2 on Win32/Mingw), so | ||
21 | -- can't use to check for NaNs | ||
22 | ----------------------------------------------------------------------]] | ||
23 | |||
24 | require("../ldump") | ||
25 | |||
26 | ------------------------------------------------------------------------ | ||
27 | -- convert hex string representation to a byte string | ||
28 | -- * must have an even number of hex digits | ||
29 | ------------------------------------------------------------------------ | ||
30 | local function from_hexstring(s) | ||
31 | local bs = "" | ||
32 | for i = 1, string.len(s), 2 do | ||
33 | local asc = tonumber(string.sub(s, i, i + 1), 16) | ||
34 | bs = bs..string.char(asc) | ||
35 | end | ||
36 | return bs | ||
37 | end | ||
38 | |||
39 | ------------------------------------------------------------------------ | ||
40 | -- convert a byte string to a hex string representation | ||
41 | -- * big-endian, easier to grok | ||
42 | ------------------------------------------------------------------------ | ||
43 | local function to_hexstring(s) | ||
44 | local hs = "" | ||
45 | for i = string.len(s), 1, -1 do | ||
46 | local c = string.byte(string.sub(s, i, i)) | ||
47 | hs = hs..string.format("%02X", c) | ||
48 | end | ||
49 | return hs | ||
50 | end | ||
51 | |||
52 | ------------------------------------------------------------------------ | ||
53 | -- tests for 32-bit signed/unsigned integer | ||
54 | ------------------------------------------------------------------------ | ||
55 | local function test_int(value, expected) | ||
56 | local actual = to_hexstring(luaU:from_int(value)) | ||
57 | if not expected or expected == "" then | ||
58 | print(value..": "..actual) | ||
59 | elseif actual ~= expected then | ||
60 | print(value..": FAILED!\n".. | ||
61 | "Converted: "..actual.."\n".. | ||
62 | "Expected: "..expected) | ||
63 | return true | ||
64 | end | ||
65 | return false | ||
66 | end | ||
67 | |||
68 | local table_int = { | ||
69 | ["0"] = "00000000", | ||
70 | ["1"] = "00000001", | ||
71 | ["256"] = "00000100", | ||
72 | ["-256"] = "FFFFFF00", | ||
73 | ["-1"] = "FFFFFFFF", | ||
74 | ["2147483647"] = "7FFFFFFF", -- LONG_MAX | ||
75 | ["-2147483648"] = "80000000", -- LONG_MIN | ||
76 | ["4294967295"] = "FFFFFFFF", -- ULONG_MAX | ||
77 | --[""] = "", | ||
78 | } | ||
79 | |||
80 | local success = true | ||
81 | print("Testing luaU:from_int():") | ||
82 | for i, v in pairs(table_int) do | ||
83 | local test_value = tonumber(i) | ||
84 | local expected = v | ||
85 | if test_int(test_value, expected) then | ||
86 | success = false | ||
87 | end | ||
88 | end | ||
89 | if success then | ||
90 | print("All test numbers passed okay.\n") | ||
91 | else | ||
92 | print("There were one or more failures.\n") | ||
93 | end | ||
94 | |||
95 | ------------------------------------------------------------------------ | ||
96 | -- tests for IEEE 754 64-bit double | ||
97 | ------------------------------------------------------------------------ | ||
98 | |||
99 | local function test_double(value, expected) | ||
100 | local actual = to_hexstring(luaU:from_double(value)) | ||
101 | if not expected or expected == "" then | ||
102 | print(value..": "..actual) | ||
103 | elseif actual ~= expected then | ||
104 | print(value..": FAILED!\n".. | ||
105 | "Converted: "..actual.."\n".. | ||
106 | "Expected: "..expected) | ||
107 | return true | ||
108 | end | ||
109 | return false | ||
110 | end | ||
111 | |||
112 | -- special values, see testing loop for actual lookup | ||
113 | Infinity = 1/0 | ||
114 | Infinity_neg = -1/0 | ||
115 | |||
116 | -- can't seem to do a comparison test with NaN, so leave them | ||
117 | -- (need to check the IEEE standard on this...) | ||
118 | NaN = 0/0 | ||
119 | NaN_neg = -0/0 | ||
120 | --["NaN"] = "", -- 7FF8000000000000 (djgpp) | ||
121 | --["NaN_neg"] = "", -- FFF8000000000000 (djgpp) | ||
122 | |||
123 | local table_double = { | ||
124 | -- 0 for exponent, 0 for mantissa | ||
125 | ["0"] = "0000000000000000", | ||
126 | -- 3FF is bias of 1023, so (-1)^0 * (1+0) * 2^0 | ||
127 | ["1"] = "3FF0000000000000", | ||
128 | -- BFF has sign bit on, so (-1)^1 * (1+0) * 2^0 | ||
129 | ["-1"] = "BFF0000000000000", | ||
130 | -- 3FC is bias of 1020, so (-1)^0 * (1+0) * 2^-3 | ||
131 | ["0.125"] = "3FC0000000000000", | ||
132 | ["0.250"] = "3FD0000000000000", | ||
133 | ["0.500"] = "3FE0000000000000", | ||
134 | -- 40F is bias of 1039, so (-1)^0 * (1+0) * 2^16 | ||
135 | ["65536"] = "40F0000000000000", | ||
136 | -- 7FF is bias of 2047, 0 for mantissa | ||
137 | ["Infinity"] = "7FF0000000000000", | ||
138 | -- FFF has sign bit on, 0 for mantissa | ||
139 | ["Infinity_neg"] = "FFF0000000000000", | ||
140 | -- DBL_MIN, exponent=001 ( 1), mantissa=0000000000000 | ||
141 | ["2.2250738585072014e-308"] = "0010000000000000", | ||
142 | -- DBL_MAX, exponent=7FE (2046), mantissa=FFFFFFFFFFFFF | ||
143 | ["1.7976931348623157e+308"] = "7FEFFFFFFFFFFFFF", | ||
144 | --[[ | ||
145 | -- * the following is for float numbers only * | ||
146 | -- FLT_MIN, exponent=01 ( 1), mantissa=000000 | ||
147 | -- altervative value for FLT_MIN: 1.17549435e-38F | ||
148 | ["1.1754943508222875081e-38"] = "00800000", | ||
149 | -- FLT_MAX, exponent=FE (254), mantissa=7FFFFF | ||
150 | -- altervative value for FLT_MAX: 3.402823466e+38F | ||
151 | ["3.4028234663852885982e+38"] = "7F7FFFFF", | ||
152 | --]] | ||
153 | --[""] = "", | ||
154 | } | ||
155 | |||
156 | local success = true | ||
157 | print("Testing luaU:from_double():") | ||
158 | for i, v in pairs(table_double) do | ||
159 | local test_value | ||
160 | if not string.find(i, "%d") then | ||
161 | test_value = _G[i] | ||
162 | else | ||
163 | test_value = tonumber(i) | ||
164 | end | ||
165 | local expected = v | ||
166 | if test_double(test_value, expected) then | ||
167 | success = false | ||
168 | end | ||
169 | end | ||
170 | if success then | ||
171 | print("All test numbers passed okay.\n") | ||
172 | else | ||
173 | print("There were one or more failures.\n") | ||
174 | end | ||