diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-05-26 11:07:38 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-05-26 11:07:38 +0800 |
| commit | a91135ce512f907ed085d9aac147d8fcad356406 (patch) | |
| tree | e53408fe0a88ef71ea33d14bcb0b6eeb3a344810 /spec/outputs | |
| parent | 4ba4c90e711c6204aa40e38347c5a5a076d9370e (diff) | |
| download | yuescript-a91135ce512f907ed085d9aac147d8fcad356406.tar.gz yuescript-a91135ce512f907ed085d9aac147d8fcad356406.tar.bz2 yuescript-a91135ce512f907ed085d9aac147d8fcad356406.zip | |
Added assignment expression for switch syntax.
Diffstat (limited to 'spec/outputs')
| -rw-r--r-- | spec/outputs/codes_from_doc.lua | 4 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 4 | ||||
| -rw-r--r-- | spec/outputs/switch.lua | 71 |
3 files changed, 75 insertions, 4 deletions
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index c7a2d50..d857dec 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua | |||
| @@ -1234,7 +1234,7 @@ if "Robert" == name then | |||
| 1234 | elseif "Dan" == name or "Daniel" == name then | 1234 | elseif "Dan" == name or "Daniel" == name then |
| 1235 | print("Your name, it's Dan") | 1235 | print("Your name, it's Dan") |
| 1236 | else | 1236 | else |
| 1237 | print("I don't know about your name") | 1237 | print("I don't know about you with name " .. tostring(name)) |
| 1238 | end | 1238 | end |
| 1239 | local b = 1 | 1239 | local b = 1 |
| 1240 | local next_number | 1240 | local next_number |
| @@ -3450,7 +3450,7 @@ if "Robert" == name then | |||
| 3450 | elseif "Dan" == name or "Daniel" == name then | 3450 | elseif "Dan" == name or "Daniel" == name then |
| 3451 | print("Your name, it's Dan") | 3451 | print("Your name, it's Dan") |
| 3452 | else | 3452 | else |
| 3453 | print("I don't know about your name") | 3453 | print("I don't know about you with name " .. tostring(name)) |
| 3454 | end | 3454 | end |
| 3455 | local b = 1 | 3455 | local b = 1 |
| 3456 | local next_number | 3456 | local next_number |
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index fcde41f..ecab077 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
| @@ -1228,7 +1228,7 @@ if "Robert" == name then | |||
| 1228 | elseif "Dan" == name or "Daniel" == name then | 1228 | elseif "Dan" == name or "Daniel" == name then |
| 1229 | print("你的名字是Dan") | 1229 | print("你的名字是Dan") |
| 1230 | else | 1230 | else |
| 1231 | print("我不知道你的名字") | 1231 | print("我不认识你,你的名字是" .. tostring(name)) |
| 1232 | end | 1232 | end |
| 1233 | local b = 1 | 1233 | local b = 1 |
| 1234 | local next_number | 1234 | local next_number |
| @@ -3438,7 +3438,7 @@ if "Robert" == name then | |||
| 3438 | elseif "Dan" == name or "Daniel" == name then | 3438 | elseif "Dan" == name or "Daniel" == name then |
| 3439 | print("你的名字是Dan") | 3439 | print("你的名字是Dan") |
| 3440 | else | 3440 | else |
| 3441 | print("我不知道你的名字") | 3441 | print("我不认识你,你的名字是" .. tostring(name)) |
| 3442 | end | 3442 | end |
| 3443 | local b = 1 | 3443 | local b = 1 |
| 3444 | local next_number | 3444 | local next_number |
diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua index 0f8bba2..204b816 100644 --- a/spec/outputs/switch.lua +++ b/spec/outputs/switch.lua | |||
| @@ -656,4 +656,75 @@ do | |||
| 656 | end | 656 | end |
| 657 | end | 657 | end |
| 658 | end | 658 | end |
| 659 | do | ||
| 660 | local v = "hello" | ||
| 661 | if "hello" == v then | ||
| 662 | print("matched hello") | ||
| 663 | else | ||
| 664 | print("not matched") | ||
| 665 | end | ||
| 666 | end | ||
| 667 | do | ||
| 668 | local f | ||
| 669 | f = function() | ||
| 670 | return "ok" | ||
| 671 | end | ||
| 672 | local val = f() | ||
| 673 | if "ok" == val then | ||
| 674 | print("it's ok") | ||
| 675 | end | ||
| 676 | end | ||
| 677 | do | ||
| 678 | local g | ||
| 679 | g = function() | ||
| 680 | return 42 | ||
| 681 | end | ||
| 682 | local result = g() | ||
| 683 | if 1 == result or 2 == result then | ||
| 684 | print("small") | ||
| 685 | elseif 42 == result then | ||
| 686 | print("life universe everything") | ||
| 687 | else | ||
| 688 | print("other " .. tostring(result)) | ||
| 689 | end | ||
| 690 | end | ||
| 691 | do | ||
| 692 | local check | ||
| 693 | check = function() | ||
| 694 | if true then | ||
| 695 | return "yes" | ||
| 696 | else | ||
| 697 | return "no" | ||
| 698 | end | ||
| 699 | end | ||
| 700 | local x = check() | ||
| 701 | if "yes" == x then | ||
| 702 | print("affirmative") | ||
| 703 | else | ||
| 704 | print("negative") | ||
| 705 | end | ||
| 706 | end | ||
| 707 | do | ||
| 708 | local t | ||
| 709 | t = function() | ||
| 710 | local tb = { | ||
| 711 | a = 1 | ||
| 712 | } | ||
| 713 | tb.a = 2 | ||
| 714 | return tb | ||
| 715 | end | ||
| 716 | local data = t() | ||
| 717 | local _type_0 = type(data) | ||
| 718 | local _tab_0 = "table" == _type_0 or "userdata" == _type_0 | ||
| 719 | local _match_0 = false | ||
| 720 | if _tab_0 then | ||
| 721 | if 2 == data.a then | ||
| 722 | _match_0 = true | ||
| 723 | print("matched") | ||
| 724 | end | ||
| 725 | end | ||
| 726 | if not _match_0 then | ||
| 727 | print("not matched") | ||
| 728 | end | ||
| 729 | end | ||
| 659 | return nil | 730 | return nil |
