diff options
Diffstat (limited to 'spec/outputs')
| -rw-r--r-- | spec/outputs/codes_from_doc.lua | 60 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 60 | ||||
| -rw-r--r-- | spec/outputs/vararg.lua | 72 |
3 files changed, 192 insertions, 0 deletions
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index d6617a9..de5abdd 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua | |||
| @@ -737,6 +737,36 @@ end | |||
| 737 | local first = select(1, ...) | 737 | local first = select(1, ...) |
| 738 | return print(ok, count, first) | 738 | return print(ok, count, first) |
| 739 | end)(fn(true)) | 739 | end)(fn(true)) |
| 740 | local f | ||
| 741 | f = function(...) | ||
| 742 | local t = { | ||
| 743 | n = select("#", ...), | ||
| 744 | ... | ||
| 745 | } | ||
| 746 | print("argument count:", t.n) | ||
| 747 | print("table length:", #t) | ||
| 748 | for i = 1, t.n do | ||
| 749 | print(t[i]) | ||
| 750 | end | ||
| 751 | end | ||
| 752 | f(1, 2, 3) | ||
| 753 | f("a", "b", "c", "d") | ||
| 754 | f() | ||
| 755 | local process | ||
| 756 | process = function(...) | ||
| 757 | local args = { | ||
| 758 | n = select("#", ...), | ||
| 759 | ... | ||
| 760 | } | ||
| 761 | local sum = 0 | ||
| 762 | for i = 1, args.n do | ||
| 763 | if args[i] ~= nil and type(args[i]) == "number" then | ||
| 764 | sum = sum + args[i] | ||
| 765 | end | ||
| 766 | end | ||
| 767 | return sum | ||
| 768 | end | ||
| 769 | process(1, nil, 3, nil, 5) | ||
| 740 | Rx.Observable.fromRange(1, 8):filter(function(x) | 770 | Rx.Observable.fromRange(1, 8):filter(function(x) |
| 741 | return x % 2 == 0 | 771 | return x % 2 == 0 |
| 742 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | 772 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) |
| @@ -3215,6 +3245,36 @@ end | |||
| 3215 | local first = select(1, ...) | 3245 | local first = select(1, ...) |
| 3216 | return print(ok, count, first) | 3246 | return print(ok, count, first) |
| 3217 | end)(fn(true)) | 3247 | end)(fn(true)) |
| 3248 | local f | ||
| 3249 | f = function(...) | ||
| 3250 | local t = { | ||
| 3251 | n = select("#", ...), | ||
| 3252 | ... | ||
| 3253 | } | ||
| 3254 | print("argument count:", t.n) | ||
| 3255 | print("table length:", #t) | ||
| 3256 | for i = 1, t.n do | ||
| 3257 | print(t[i]) | ||
| 3258 | end | ||
| 3259 | end | ||
| 3260 | f(1, 2, 3) | ||
| 3261 | f("a", "b", "c", "d") | ||
| 3262 | f() | ||
| 3263 | local process | ||
| 3264 | process = function(...) | ||
| 3265 | local args = { | ||
| 3266 | n = select("#", ...), | ||
| 3267 | ... | ||
| 3268 | } | ||
| 3269 | local sum = 0 | ||
| 3270 | for i = 1, args.n do | ||
| 3271 | if args[i] ~= nil and type(args[i]) == "number" then | ||
| 3272 | sum = sum + args[i] | ||
| 3273 | end | ||
| 3274 | end | ||
| 3275 | return sum | ||
| 3276 | end | ||
| 3277 | process(1, nil, 3, nil, 5) | ||
| 3218 | Rx.Observable.fromRange(1, 8):filter(function(x) | 3278 | Rx.Observable.fromRange(1, 8):filter(function(x) |
| 3219 | return x % 2 == 0 | 3279 | return x % 2 == 0 |
| 3220 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | 3280 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) |
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index ec84112..6a6c38c 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
| @@ -737,6 +737,36 @@ end | |||
| 737 | local first = select(1, ...) | 737 | local first = select(1, ...) |
| 738 | return print(ok, count, first) | 738 | return print(ok, count, first) |
| 739 | end)(fn(true)) | 739 | end)(fn(true)) |
| 740 | local f | ||
| 741 | f = function(...) | ||
| 742 | local t = { | ||
| 743 | n = select("#", ...), | ||
| 744 | ... | ||
| 745 | } | ||
| 746 | print("参数个数:", t.n) | ||
| 747 | print("表长度:", #t) | ||
| 748 | for i = 1, t.n do | ||
| 749 | print(t[i]) | ||
| 750 | end | ||
| 751 | end | ||
| 752 | f(1, 2, 3) | ||
| 753 | f("a", "b", "c", "d") | ||
| 754 | f() | ||
| 755 | local process | ||
| 756 | process = function(...) | ||
| 757 | local args = { | ||
| 758 | n = select("#", ...), | ||
| 759 | ... | ||
| 760 | } | ||
| 761 | local sum = 0 | ||
| 762 | for i = 1, args.n do | ||
| 763 | if args[i] ~= nil and type(args[i]) == "number" then | ||
| 764 | sum = sum + args[i] | ||
| 765 | end | ||
| 766 | end | ||
| 767 | return sum | ||
| 768 | end | ||
| 769 | process(1, nil, 3, nil, 5) | ||
| 740 | Rx.Observable.fromRange(1, 8):filter(function(x) | 770 | Rx.Observable.fromRange(1, 8):filter(function(x) |
| 741 | return x % 2 == 0 | 771 | return x % 2 == 0 |
| 742 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | 772 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) |
| @@ -3209,6 +3239,36 @@ end | |||
| 3209 | local first = select(1, ...) | 3239 | local first = select(1, ...) |
| 3210 | return print(ok, count, first) | 3240 | return print(ok, count, first) |
| 3211 | end)(fn(true)) | 3241 | end)(fn(true)) |
| 3242 | local f | ||
| 3243 | f = function(...) | ||
| 3244 | local t = { | ||
| 3245 | n = select("#", ...), | ||
| 3246 | ... | ||
| 3247 | } | ||
| 3248 | print("参数个数:", t.n) | ||
| 3249 | print("表长度:", #t) | ||
| 3250 | for i = 1, t.n do | ||
| 3251 | print(t[i]) | ||
| 3252 | end | ||
| 3253 | end | ||
| 3254 | f(1, 2, 3) | ||
| 3255 | f("a", "b", "c", "d") | ||
| 3256 | f() | ||
| 3257 | local process | ||
| 3258 | process = function(...) | ||
| 3259 | local args = { | ||
| 3260 | n = select("#", ...), | ||
| 3261 | ... | ||
| 3262 | } | ||
| 3263 | local sum = 0 | ||
| 3264 | for i = 1, args.n do | ||
| 3265 | if args[i] ~= nil and type(args[i]) == "number" then | ||
| 3266 | sum = sum + args[i] | ||
| 3267 | end | ||
| 3268 | end | ||
| 3269 | return sum | ||
| 3270 | end | ||
| 3271 | process(1, nil, 3, nil, 5) | ||
| 3212 | Rx.Observable.fromRange(1, 8):filter(function(x) | 3272 | Rx.Observable.fromRange(1, 8):filter(function(x) |
| 3213 | return x % 2 == 0 | 3273 | return x % 2 == 0 |
| 3214 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) | 3274 | end):concat(Rx.Observable.of('who do we appreciate')):map(function(value) |
diff --git a/spec/outputs/vararg.lua b/spec/outputs/vararg.lua index 254aa6a..9f97681 100644 --- a/spec/outputs/vararg.lua +++ b/spec/outputs/vararg.lua | |||
| @@ -294,3 +294,75 @@ join = function(...) | |||
| 294 | end | 294 | end |
| 295 | return nil | 295 | return nil |
| 296 | end | 296 | end |
| 297 | do | ||
| 298 | local f1 | ||
| 299 | f1 = function(...) | ||
| 300 | local t = { | ||
| 301 | n = select("#", ...), | ||
| 302 | ... | ||
| 303 | } | ||
| 304 | print(t.n) | ||
| 305 | print(#t) | ||
| 306 | for i = 1, t.n do | ||
| 307 | print(t[i]) | ||
| 308 | end | ||
| 309 | end | ||
| 310 | f1(1, 2, 3) | ||
| 311 | f1("a", "b", "c", "d") | ||
| 312 | f1() | ||
| 313 | local f2 | ||
| 314 | f2 = function(...) | ||
| 315 | local args = { | ||
| 316 | n = select("#", ...), | ||
| 317 | ... | ||
| 318 | } | ||
| 319 | print("args count:", args.n) | ||
| 320 | print("args length:", #args) | ||
| 321 | for i = 1, args.n do | ||
| 322 | if args[i] == nil then | ||
| 323 | print("position", i, "is nil") | ||
| 324 | else | ||
| 325 | print("position", i, ":", args[i]) | ||
| 326 | end | ||
| 327 | end | ||
| 328 | end | ||
| 329 | f2(1, nil, 3, nil, 5) | ||
| 330 | local f3 | ||
| 331 | f3 = function(prefix, ...) | ||
| 332 | local items = { | ||
| 333 | n = select("#", ...), | ||
| 334 | ... | ||
| 335 | } | ||
| 336 | local result = { } | ||
| 337 | for i = 1, items.n do | ||
| 338 | result[i] = prefix .. tostring(items[i]) | ||
| 339 | end | ||
| 340 | return result | ||
| 341 | end | ||
| 342 | f3("item_", 1, 2, 3) | ||
| 343 | local f4 | ||
| 344 | f4 = function(...) | ||
| 345 | local empty = { | ||
| 346 | n = select("#", ...), | ||
| 347 | ... | ||
| 348 | } | ||
| 349 | print("empty count:", empty.n) | ||
| 350 | return print("empty length:", #empty) | ||
| 351 | end | ||
| 352 | f4() | ||
| 353 | local process | ||
| 354 | process = function(...) | ||
| 355 | local data = { | ||
| 356 | n = select("#", ...), | ||
| 357 | ... | ||
| 358 | } | ||
| 359 | local sum = 0 | ||
| 360 | for i = 1, data.n do | ||
| 361 | if type(data[i]) == "number" then | ||
| 362 | sum = sum + data[i] | ||
| 363 | end | ||
| 364 | end | ||
| 365 | return sum | ||
| 366 | end | ||
| 367 | return process(1, 2, 3, "skip", 5) | ||
| 368 | end | ||
