From e02321107277a63e7dcb12ab163c9942ac101b87 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 26 Jan 2026 17:45:26 +0800 Subject: Updated tests. --- spec/inputs/test/attrib_spec.yue | 12 ++++++------ spec/inputs/test/backcall_spec.yue | 5 +++-- spec/inputs/test/config_spec.yue | 2 +- spec/inputs/test/existential_spec.yue | 4 ++-- spec/inputs/test/export_spec.yue | 5 ----- spec/inputs/test/goto_spec.yue | 2 +- spec/inputs/test/import_spec.yue | 4 ++-- spec/inputs/test/literals_spec.yue | 4 ++-- spec/inputs/test/macro_spec.yue | 10 +++++----- spec/inputs/test/return_spec.yue | 4 ++-- spec/inputs/test/string_spec.yue | 12 ++++++------ spec/inputs/test/switch_spec.yue | 4 ++-- spec/inputs/test/try_catch_spec.yue | 1 + spec/inputs/test/with_spec.yue | 23 +++++++++++------------ 14 files changed, 44 insertions(+), 48 deletions(-) (limited to 'spec/inputs/test') diff --git a/spec/inputs/test/attrib_spec.yue b/spec/inputs/test/attrib_spec.yue index 4a1fcab..ce9956a 100644 --- a/spec/inputs/test/attrib_spec.yue +++ b/spec/inputs/test/attrib_spec.yue @@ -14,12 +14,12 @@ describe "attrib", -> it "should support close attribute", -> -- close attribute for to-be-closed variables do - close x = 1 - assert.same x, 1 + close x = : -> + assert.same "table", type x it "should work with destructuring", -> do - const {a, b} = {a: 1, b: 2} + const :a, :b = {a: 1, b: 2} assert.same a, 1 assert.same b, 2 @@ -45,7 +45,7 @@ describe "attrib", -> it "should support close in expressions", -> do close result = if true - 42 + value: 42, : -> else - 0 - assert.same result, 42 + value: 0, : -> + assert.same result.value, 42 diff --git a/spec/inputs/test/backcall_spec.yue b/spec/inputs/test/backcall_spec.yue index 9534e7c..e7d03ce 100644 --- a/spec/inputs/test/backcall_spec.yue +++ b/spec/inputs/test/backcall_spec.yue @@ -4,8 +4,9 @@ describe "backcall", -> mock_map = (list, fn) -> for item in *list table.insert results, fn(item) - (x) <- mock_map {1, 2, 3} - x * 2 + do + (x) <- mock_map {1, 2, 3} + x * 2 assert.same results, {2, 4, 6} it "should support nested backcalls", -> diff --git a/spec/inputs/test/config_spec.yue b/spec/inputs/test/config_spec.yue index 2df8ef3..1c87955 100644 --- a/spec/inputs/test/config_spec.yue +++ b/spec/inputs/test/config_spec.yue @@ -57,7 +57,7 @@ describe "config", -> it "should handle with statements", -> obj = {x: 10, y: 20} result = with obj - .x + .y + break .x + .y assert.same result, 30 it "should handle existential operators", -> diff --git a/spec/inputs/test/existential_spec.yue b/spec/inputs/test/existential_spec.yue index f63967a..2d516a9 100644 --- a/spec/inputs/test/existential_spec.yue +++ b/spec/inputs/test/existential_spec.yue @@ -36,8 +36,8 @@ describe "existential", -> it "should work with ? in if condition", -> obj = {value: 5} - if obj?.value - result = "exists" + result = if obj?.value + "exists" assert.same result, "exists" it "should combine ?. with and/or", -> diff --git a/spec/inputs/test/export_spec.yue b/spec/inputs/test/export_spec.yue index c6ea99b..20c0630 100644 --- a/spec/inputs/test/export_spec.yue +++ b/spec/inputs/test/export_spec.yue @@ -77,11 +77,6 @@ describe "export", -> assert.same count, 42 assert.same price, 19.99 - it "should work in nested scope", -> - do - nested = "value" - assert.same nested, "value" - it "should export function with parameters", -> add = (a, b) -> a + b assert.same add(5, 3), 8 diff --git a/spec/inputs/test/goto_spec.yue b/spec/inputs/test/goto_spec.yue index fd2f401..9dad0a7 100644 --- a/spec/inputs/test/goto_spec.yue +++ b/spec/inputs/test/goto_spec.yue @@ -24,7 +24,7 @@ describe "goto", -> if x == 2 and y == 2 goto found ::found:: - assert.same count, 4 -- (1,1), (1,2), (1,3), (2,1), (2,2) + assert.same count, 5 -- (1,1), (1,2), (1,3), (2,1), (2,2) it "should support multiple labels", -> a = 0 diff --git a/spec/inputs/test/import_spec.yue b/spec/inputs/test/import_spec.yue index deeb4a0..7952ac0 100644 --- a/spec/inputs/test/import_spec.yue +++ b/spec/inputs/test/import_spec.yue @@ -6,10 +6,10 @@ describe "import", -> assert.same foo, "bar" it "should import with backslash escaping", -> - source = {x: 1, y: 2, z: 3} + source = {x: 1, y: =>, z: 3} import x, \y, z from source assert.same x, 1 - assert.same y, 2 + assert.same "function", type y assert.same z, 3 it "should import from string module", -> diff --git a/spec/inputs/test/literals_spec.yue b/spec/inputs/test/literals_spec.yue index 10bd6b3..4c0b8c1 100644 --- a/spec/inputs/test/literals_spec.yue +++ b/spec/inputs/test/literals_spec.yue @@ -40,13 +40,13 @@ describe "literals", -> hello world ]] - assert.is_true s\match "hello" + assert.is_true s\match("hello")? it "should support multi-line strings with [=[", -> s = [==[ test ]==] - assert.is_true s\match "test" + assert.is_true s\match("test")? it "should support boolean true", -> assert.same true, true diff --git a/spec/inputs/test/macro_spec.yue b/spec/inputs/test/macro_spec.yue index a4a170b..e254454 100644 --- a/spec/inputs/test/macro_spec.yue +++ b/spec/inputs/test/macro_spec.yue @@ -16,7 +16,7 @@ describe "macro", -> it "should validate AST types", -> macro NumAndStr = (num`Num, str`SingleString) -> "[#{num}, #{str}]" result = $NumAndStr 123, 'xyz' - assert.same result, "[123, xyz]" + assert.same result, [123, 'xyz'] it "should support simple code generation", -> macro add_one = (x) -> "#{x} + 1" @@ -30,9 +30,9 @@ describe "macro", -> assert.same result, 7 it "should respect macro scope in do blocks", -> - macro outer = -> "outer" + macro outer = -> "'outer'" do - macro inner = -> "inner" + macro inner = -> "'inner'" result = $inner! assert.same result, "inner" result = $outer! @@ -94,7 +94,7 @@ describe "macro", -> it "should work with string interpolation", -> macro format_result = (name, value) -> "#{name}: #{value}" result = $format_result "test", 123 - assert.same result, "test: 123" + assert.same result, test: 123 it "should support function call syntax", -> macro my_func = (x, y) -> "#{x} + #{y}" @@ -130,6 +130,6 @@ describe "macro", -> assert.same result, 7 it "should work with string literals", -> - macro greet = (name) -> '"Hello, #{name}"' + macro greet = (name) -> "'Hello, ' .. #{name}" result = $greet "World" assert.same result, "Hello, World" diff --git a/spec/inputs/test/return_spec.yue b/spec/inputs/test/return_spec.yue index 3bf0bed..9cedc40 100644 --- a/spec/inputs/test/return_spec.yue +++ b/spec/inputs/test/return_spec.yue @@ -59,11 +59,11 @@ describe "return", -> assert.same fn({value: 100}), 100 it "should return nil implicitly", -> - fn -> print "no return" + fn = -> _ = "no return" assert.same fn!, nil it "should return multiple values", -> - fn -> 1, 2, 3 + fn = -> 1, 2, 3 a, b, c = fn! assert.same a, 1 assert.same b, 2 diff --git a/spec/inputs/test/string_spec.yue b/spec/inputs/test/string_spec.yue index b790518..2afbb13 100644 --- a/spec/inputs/test/string_spec.yue +++ b/spec/inputs/test/string_spec.yue @@ -48,12 +48,12 @@ describe "string", -> it "should not interpolate in single quotes", -> name = "world" s = 'hello #{name}' - assert.same s, "hello #{name}" + assert.same s, "hello \#{name}" - it "should escape interpolation with \\#", -> + it "should escape interpolation with \\\#", -> name = "world" - s = "hello \\#{name}" - assert.same s, "hello #{name}" + s = "hello \#{name}" + assert.same s, 'hello #{name}' it "should support method calls on string literals", -> result = "hello"\upper! @@ -74,7 +74,7 @@ describe "string", -> name = "test" s = | hello #{name} - assert.same s, "hello test\n" + assert.same s, "hello test" it "should support string concatenation", -> s = "hello" .. " " .. "world" @@ -109,7 +109,7 @@ describe "string", -> assert.is_true s\match("y: 20") ~= nil it "should support function call in interpolation", -> - s = "result: #{-> 42}" + s = "result: #{(-> 42)!}" assert.same s, "result: 42" it "should support table indexing in interpolation", -> diff --git a/spec/inputs/test/switch_spec.yue b/spec/inputs/test/switch_spec.yue index 3696cbe..0865e5a 100644 --- a/spec/inputs/test/switch_spec.yue +++ b/spec/inputs/test/switch_spec.yue @@ -73,7 +73,7 @@ describe "switch", -> a: b: :c x: y: :z } - matched = first == {} and one == 1 and two == 2 and three == 3 and c == 1 and z == 1 + matched = type(first) == 'table' and one == 1 and two == 2 and three == 3 and c == 1 and z == 1 assert.is_true matched it "should destructure arrays with exact match", -> @@ -259,9 +259,9 @@ describe "switch", -> assert.same result, "matched cool" it "should handle switch in function call", -> + something = 1 getValue = -> switch something when 1 then "yes" else "no" - something = 1 assert.same getValue!, "yes" diff --git a/spec/inputs/test/try_catch_spec.yue b/spec/inputs/test/try_catch_spec.yue index ed8fef0..7447886 100644 --- a/spec/inputs/test/try_catch_spec.yue +++ b/spec/inputs/test/try_catch_spec.yue @@ -1,5 +1,6 @@ describe "try/catch", -> it "catch and rethrow", -> + import global ok, success, err = pcall -> try error "boom" diff --git a/spec/inputs/test/with_spec.yue b/spec/inputs/test/with_spec.yue index c3b8428..70b50ee 100644 --- a/spec/inputs/test/with_spec.yue +++ b/spec/inputs/test/with_spec.yue @@ -3,13 +3,13 @@ describe "with", -> obj = {value: 42} with obj result = .value - assert.same result, 42 + assert.same result, 42 it "should call method with : syntax", -> obj = {func: -> "result"} with obj result = \func! - assert.same result, "result" + assert.same result, "result" it "should work as statement", -> obj = {x: 10, y: 20} @@ -21,20 +21,20 @@ describe "with", -> outer = {inner: {value: 100}} with outer.inner result = .value - assert.same result, 100 + assert.same result, 100 it "should work with? safely", -> obj = {x: 5} with obj result = .x - assert.same result, 5 + assert.same result, 5 it "should work with if inside with", -> obj = {x: 10, y: 20} with obj if .x > 5 result = .x + .y - assert.same result, 30 + assert.same result, 30 it "should work with switch inside with", -> obj = {type: "add", a: 5, b: 3} @@ -42,7 +42,7 @@ describe "with", -> result = switch .type when "add" then .a + .b else 0 - assert.same result, 8 + assert.same result, 8 it "should work with loop inside with", -> obj = {items: {1, 2, 3}} @@ -54,11 +54,10 @@ describe "with", -> it "should work with destructure", -> obj = {x: 1, y: 2, z: 3} - with obj - {x, y, z} = obj - assert.same x, 1 - assert.same y, 2 - assert.same z, 3 + with {:x, :y, :z} := obj + assert.same x, 1 + assert.same y, 2 + assert.same z, 3 it "should handle simple with body", -> obj = {value: 42} @@ -87,7 +86,7 @@ describe "with", -> obj = {a: {b: {c: 42}}} with obj.a.b result = .c - assert.same result, 42 + assert.same result, 42 it "should work with multiple statements", -> obj = {x: 1, y: 2} -- cgit v1.2.3-55-g6feb