diff options
author | David Walter Seikel | 2014-04-21 20:59:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-04-21 20:59:39 +1000 |
commit | 9621add2918cc4943e6693b74ae85d51dd264fcf (patch) | |
tree | fff1edf2c69d7a08a0e12885eecc9b96ed847a6a /LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua | |
parent | LuaSL_test's window doesn't need to be so huge. (diff) | |
download | SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.zip SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.tar.gz SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.tar.bz2 SledjHamr-9621add2918cc4943e6693b74ae85d51dd264fcf.tar.xz |
We don't need the testlua directory any more.
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua')
-rw-r--r-- | LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua | 329 |
1 files changed, 0 insertions, 329 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua deleted file mode 100644 index 11f2827..0000000 --- a/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua +++ /dev/null | |||
@@ -1,329 +0,0 @@ | |||
1 | --[[-------------------------------------------------------------------- | ||
2 | |||
3 | test_lparser_mk2.lua | ||
4 | Test for lparser_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 | -- test the whole kaboodle | ||
17 | ------------------------------------------------------------------------ | ||
18 | |||
19 | package.path = "../?.lua;"..package.path | ||
20 | local llex = require "llex_mk2" | ||
21 | local lparser = require "lparser_mk2" | ||
22 | |||
23 | ------------------------------------------------------------------------ | ||
24 | -- dump contents of log table | ||
25 | ------------------------------------------------------------------------ | ||
26 | |||
27 | local function dump_log(fs) | ||
28 | local log = fs.log | ||
29 | for i = 1, #log do | ||
30 | print(log[i]) | ||
31 | end | ||
32 | end | ||
33 | |||
34 | ------------------------------------------------------------------------ | ||
35 | -- try 1 | ||
36 | ------------------------------------------------------------------------ | ||
37 | |||
38 | --[=[ | ||
39 | llex.init("local a = 1", "=string") | ||
40 | lparser.init(llex) | ||
41 | -- nothing is returned, so hope there is an error if problem occurs | ||
42 | local fs = lparser.parser() | ||
43 | dump_log(fs) | ||
44 | --]=] | ||
45 | |||
46 | ------------------------------------------------------------------------ | ||
47 | -- try 2 | ||
48 | ------------------------------------------------------------------------ | ||
49 | |||
50 | -- a slightly larger sample | ||
51 | --[=[ | ||
52 | llex.init([[ | ||
53 | local a = 47 | ||
54 | local b = "hello, world!" | ||
55 | print(a, b) | ||
56 | ]], "@sample.lua") | ||
57 | lparser.init(llex) | ||
58 | -- nothing is returned, so hope there is an error if problem occurs | ||
59 | local fs = lparser.parser() | ||
60 | dump_log(fs) | ||
61 | --]=] | ||
62 | |||
63 | ------------------------------------------------------------------------ | ||
64 | -- automatic dumper of output log data | ||
65 | ------------------------------------------------------------------------ | ||
66 | |||
67 | local test_case = { | ||
68 | -- 1 attempts to exercise most parts, extent of coverage not known | ||
69 | [[ | ||
70 | ]], | ||
71 | -- 2 | ||
72 | [[ | ||
73 | -- foobar | ||
74 | ]], | ||
75 | -- 3 | ||
76 | [[ | ||
77 | do | ||
78 | end | ||
79 | ]], | ||
80 | -- 4 | ||
81 | [[ | ||
82 | do end | ||
83 | do end | ||
84 | ]], | ||
85 | -- 5 | ||
86 | [[ | ||
87 | foo() | ||
88 | foo{} | ||
89 | foo"" | ||
90 | foo:bar() | ||
91 | foo=false | ||
92 | foo.bar=true | ||
93 | foo[true]=nil | ||
94 | foo,bar=1,"a" | ||
95 | ]], | ||
96 | -- 6 | ||
97 | [[ | ||
98 | foo=true | ||
99 | foo=false | ||
100 | foo=nil | ||
101 | foo=1.23e45 | ||
102 | foo=-1 | ||
103 | foo=(0) | ||
104 | foo=1+2 | ||
105 | foo=1+2*3-4/5 | ||
106 | ]], | ||
107 | -- 7 | ||
108 | [[ | ||
109 | if foo then foo=1 end | ||
110 | if foo then foo=1 else foo=0 end | ||
111 | if foo then foo=1 elseif not foo then foo=0 end | ||
112 | ]], | ||
113 | -- 8 | ||
114 | [[ | ||
115 | do return end | ||
116 | do return 123 end | ||
117 | do return "foo","bar" end | ||
118 | ]], | ||
119 | -- 9 | ||
120 | [[ | ||
121 | while true do foo=not foo end | ||
122 | while foo~=42 do foo=foo-1 end | ||
123 | while true do break end | ||
124 | ]], | ||
125 | -- 10 | ||
126 | [[ | ||
127 | repeat foo=foo.."bar" until false | ||
128 | repeat foo=foo/2 until foo<1 | ||
129 | repeat break until false | ||
130 | ]], | ||
131 | -- 11 | ||
132 | [[ | ||
133 | for i=1,10 do foo=i end | ||
134 | for i=1,10,2 do break end | ||
135 | for i in foo do bar=0 end | ||
136 | for i,j in foo,bar do baz=0 end | ||
137 | ]], | ||
138 | -- 12 | ||
139 | [[ | ||
140 | local foo | ||
141 | local foo,bar,baz | ||
142 | local foo,bar="foo","bar" | ||
143 | ]], | ||
144 | -- 13 | ||
145 | [[ | ||
146 | local function foo() return end | ||
147 | local function foo(a) return end | ||
148 | local function foo(x,y,z) return end | ||
149 | local function foo(x,...) return end | ||
150 | ]], | ||
151 | -- 14 | ||
152 | [[ | ||
153 | function foo() return end | ||
154 | function foo(a) return end | ||
155 | function foo(x,y,z) return end | ||
156 | function foo(x,...) return end | ||
157 | ]], | ||
158 | -- 15 | ||
159 | [[ | ||
160 | function foo.bar(p) return end | ||
161 | function foo.bar.baz(p) return end | ||
162 | function foo:bar(p) return end | ||
163 | function foo.bar.baz(p) return end | ||
164 | ]], | ||
165 | -- 16 | ||
166 | [[ | ||
167 | foo = function() return end | ||
168 | foo = function(x,y) return end | ||
169 | foo = function(...) return end | ||
170 | foo = function(...) local bar = ... return end | ||
171 | ]], | ||
172 | -- 17 | ||
173 | [[ | ||
174 | foo = {} | ||
175 | foo = { 1,2,3; "foo"; } | ||
176 | foo = { bar=77, baz=88, } | ||
177 | foo = { ["bar"]=77, ["baz"]=88, } | ||
178 | ]], | ||
179 | -- 18 simple tests for variable management follows | ||
180 | [[ | ||
181 | print(a) | ||
182 | ]], | ||
183 | -- 19 | ||
184 | [[ | ||
185 | local a | ||
186 | print(a) | ||
187 | ]], | ||
188 | -- 20 | ||
189 | [[ | ||
190 | do | ||
191 | local a | ||
192 | print(a) | ||
193 | end | ||
194 | print(a) | ||
195 | ]], | ||
196 | -- 21 | ||
197 | [[ | ||
198 | local a,b,c | ||
199 | do | ||
200 | local b | ||
201 | print(b) | ||
202 | end | ||
203 | print(b) | ||
204 | ]], | ||
205 | -- 22 | ||
206 | [[ | ||
207 | local function foo() end | ||
208 | bar = foo | ||
209 | ]], | ||
210 | -- 23 | ||
211 | [[ | ||
212 | do | ||
213 | local function foo() end | ||
214 | bar = foo | ||
215 | end | ||
216 | baz = foo | ||
217 | ]], | ||
218 | -- 24 | ||
219 | [[ | ||
220 | local foo | ||
221 | local function bar() | ||
222 | baz = nil | ||
223 | foo = bar() | ||
224 | end | ||
225 | foo = bar | ||
226 | ]], | ||
227 | -- 25 | ||
228 | [[ | ||
229 | local foo | ||
230 | local function bar() | ||
231 | local function baz() | ||
232 | local foo, bar | ||
233 | foo = bar | ||
234 | foo = baz | ||
235 | end | ||
236 | foo = bar | ||
237 | foo = baz | ||
238 | end | ||
239 | foo = bar | ||
240 | foo = baz | ||
241 | ]], | ||
242 | -- 26 | ||
243 | [[ | ||
244 | function foo:bar() | ||
245 | print(self) | ||
246 | end | ||
247 | ]], | ||
248 | -- 27 | ||
249 | [[ | ||
250 | function foo(...) | ||
251 | print(arg) | ||
252 | end | ||
253 | ]], | ||
254 | -- 28 | ||
255 | [[ | ||
256 | local c,d | ||
257 | function foo(a,b,c) | ||
258 | print(a,c,d,e) | ||
259 | end | ||
260 | ]], | ||
261 | -- 29 | ||
262 | [[ | ||
263 | function foo(a,b) | ||
264 | local bar = function(c,d) | ||
265 | print(a,b,c,d) | ||
266 | end | ||
267 | end | ||
268 | ]], | ||
269 | -- 30 | ||
270 | [[ | ||
271 | for i = 1,10 do | ||
272 | print(i) | ||
273 | end | ||
274 | for i = 1,10,-2 do | ||
275 | print(i) | ||
276 | end | ||
277 | ]], | ||
278 | -- 31 | ||
279 | [[ | ||
280 | for foo in bar() do | ||
281 | print(foo) | ||
282 | end | ||
283 | for foo,bar,baz in spring() do | ||
284 | print(foo,bar,baz) | ||
285 | end | ||
286 | ]], | ||
287 | } | ||
288 | |||
289 | -- helps to skip old stuff during development of snippets | ||
290 | local do_beg, do_end = 1, #test_case | ||
291 | |||
292 | -- loop for all example snippets | ||
293 | for i = do_beg, do_end do | ||
294 | local fname = "parser_log/sample_"..string.format("%02d", i)..".lua" | ||
295 | local src = test_case[i] | ||
296 | local OUTF = io.open(fname, "wb") | ||
297 | if not OUTF then error("failed to write to file '"..fname.."'") end | ||
298 | -- write out actual source for comparison | ||
299 | OUTF:write( | ||
300 | "-- START OF SOURCE --\n".. | ||
301 | src.. | ||
302 | "-- END OF SOURCE --\n".. | ||
303 | "\n" | ||
304 | ) | ||
305 | -- attempt to parse | ||
306 | llex.init(src, "=string") | ||
307 | lparser.init(llex) | ||
308 | local fs = lparser.parser() | ||
309 | -- grab logged messages and write | ||
310 | local log = fs.log | ||
311 | local indent = 0 | ||
312 | for i = 1, #log do | ||
313 | local ln = log[i] | ||
314 | -- handle indentation | ||
315 | local tag = string.sub(ln, 1, 2) | ||
316 | if tag == ">>" or tag == "<<" then | ||
317 | ln = string.sub(ln, 4) | ||
318 | end | ||
319 | if tag == ">>" then | ||
320 | indent = indent + 1 | ||
321 | end | ||
322 | OUTF:write(string.rep(" ", indent)..ln.."\n") | ||
323 | if tag == "<<" then | ||
324 | indent = indent - 1 | ||
325 | end | ||
326 | end | ||
327 | -- we're done | ||
328 | OUTF:close() | ||
329 | end | ||