From dd64edd58fe25ec74ae5958128cf3f74b0692f3b Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 28 Jan 2026 18:43:14 +0800 Subject: Fixed compiler issues and added 800+ test cases. --- spec/inputs/syntax.yue | 4 +-- spec/inputs/test/advanced_macro_spec.yue | 36 +++++++++++-------- spec/inputs/test/close_attribute_spec.yue | 5 ++- spec/inputs/test/const_attribute_spec.yue | 20 ++--------- spec/inputs/test/do_statement_spec.yue | 22 ++++++------ spec/inputs/test/functions_advanced_spec.yue | 22 ++++++------ spec/inputs/test/implicit_object_spec.yue | 4 +-- spec/inputs/test/in_expression_spec.yue | 17 ++++----- spec/inputs/test/multiline_args_spec.yue | 52 +++++++++++++-------------- spec/inputs/test/named_varargs_spec.yue | 9 +++-- spec/inputs/test/operator_advanced_spec.yue | 6 ++-- spec/inputs/test/param_destructure_spec.yue | 20 +++++------ spec/inputs/test/reverse_index_spec.yue | 4 --- spec/inputs/test/slicing_spec.yue | 22 ++++++------ spec/inputs/test/stub_spec.yue | 3 ++ spec/inputs/test/table_append_spec.yue | 8 ++--- spec/inputs/test/table_comprehension_spec.yue | 2 +- spec/inputs/test/tables_advanced_spec.yue | 13 +++---- spec/inputs/test/varargs_assignment_spec.yue | 2 +- spec/inputs/test/whitespace_spec.yue | 17 +++++---- spec/inputs/test/with_statement_spec.yue | 22 ++++++------ spec/inputs/test/yaml_string_spec.yue | 44 +++++++++++------------ spec/inputs/unicode/syntax.yue | 4 +-- 23 files changed, 176 insertions(+), 182 deletions(-) (limited to 'spec/inputs') diff --git a/spec/inputs/syntax.yue b/spec/inputs/syntax.yue index a63f629..ccf8b01 100644 --- a/spec/inputs/syntax.yue +++ b/spec/inputs/syntax.yue @@ -84,11 +84,11 @@ _ = here(we)"go"[12123] split"abc xyz 123"\map"#"\printAll! -_ = f""[a] +_ = f("")[a] _ = f""\b! _ = f"".c! -f ""[a] +f ("")[a] f ""\b! f "".c! diff --git a/spec/inputs/test/advanced_macro_spec.yue b/spec/inputs/test/advanced_macro_spec.yue index 3d7b10a..d88807f 100644 --- a/spec/inputs/test/advanced_macro_spec.yue +++ b/spec/inputs/test/advanced_macro_spec.yue @@ -15,7 +15,10 @@ describe "advanced macro", -> assert.same result, "hello world" it "should work with conditional compilation", -> + global debugMode = true + $ -> global debugMode = true macro config = (debugging) -> + assert debugMode? global debugMode = debugging == "true" "" @@ -23,7 +26,7 @@ describe "advanced macro", -> assert.is_true debugMode $config false - assert.is_false debugMode + assert.is_true debugMode it "should support macro generating conditional code", -> macro asserts = (cond) -> @@ -39,20 +42,24 @@ describe "advanced macro", -> :code type: "lua" } - - $luaCode "local macro_test_var = 42" + macro_test_var = 42 + $luaCode [[local macro_test_var = 99]] assert.same macro_test_var, 42 it "should support multi-line raw lua", -> macro lua = (code) -> { :code - type: "lua" + type: "text" + locals: ["multiline_var1",] } + multiline_var = "test" $lua[==[ - local multiline_var = "test" + multiline_var = "test work" + local multiline_var1 = "test1" ]==] - assert.same multiline_var, "test" + assert.same multiline_var, "test work" + assert.same multiline_var1, "test1" it "should export macro from module", -> -- This test demonstrates macro export syntax @@ -116,10 +123,14 @@ describe "advanced macro", -> assert.same result, "Red" it "should handle complex macro logic", -> - macro smart_print = (items) -> - "print(#{table.concat [item for item in *items], ', ')})" + my_print = (...) -> ... + macro smart_print = (...items) -> + "my_print(#{table.concat [item for item in *items], ', '})" - $smart_print {"hello", "world", 123} + a, b, c = $smart_print "hello", "world", 123 + assert.same a, "hello" + assert.same b, "world" + assert.same c, 123 it "should work with table manipulation", -> macro create_table = (...) -> @@ -130,12 +141,7 @@ describe "advanced macro", -> assert.same result, {"1", "2", "3"} it "should support string concatenation in macro", -> - macro concat = (...) -> - args = {...} - res = {} - for arg in *args - table.insert res, tostring arg - "'" .. table.concat(res, " .. ") .. "'" + macro concat = (...) -> table.concat {...}, " .. " result = $concat "hello", "world" assert.same result, "helloworld" diff --git a/spec/inputs/test/close_attribute_spec.yue b/spec/inputs/test/close_attribute_spec.yue index 2354df7..ebda27e 100644 --- a/spec/inputs/test/close_attribute_spec.yue +++ b/spec/inputs/test/close_attribute_spec.yue @@ -43,7 +43,7 @@ describe "close attribute", -> closed = false obj = value: 10 - close_method: : => + : => closed = true do @@ -82,9 +82,8 @@ describe "close attribute", -> it "should work with table destructuring", -> closed = false - tb = {close: : -> closed = true} do - {:close} = tb + close tb = {: -> closed = true} assert.is_true closed it "should handle close with return value", -> diff --git a/spec/inputs/test/const_attribute_spec.yue b/spec/inputs/test/const_attribute_spec.yue index e3cc638..24ced21 100644 --- a/spec/inputs/test/const_attribute_spec.yue +++ b/spec/inputs/test/const_attribute_spec.yue @@ -13,7 +13,7 @@ describe "const attribute", -> assert.same name, "test" it "should support const with destructuring", -> - tb = {a: 1, b: 2, c: 3, d: 4} + tb = {a: 1, b: 2, 3, 4} const {:a, :b, c, d} = tb assert.same a, 1 assert.same b, 2 @@ -46,7 +46,7 @@ describe "const attribute", -> it "should handle const functions", -> const add = (a, b) -> a + b - assert.same add 5, 10, 15 + assert.same add(5, 10), 15 it "should work with const tables", -> const config = { @@ -74,28 +74,12 @@ describe "const attribute", -> const calculated = 10 + 20 assert.same calculated, 30 - it "should support const with prefixed return", -> - getDefault: const "default" -> - return nil - - result = getDefault! - assert.same result, nil - it "should work in table comprehension", -> const multiplier = 2 items = [1, 2, 3] result = [item * multiplier for item in *items] assert.same result, {2, 4, 6} - it "should handle const with fat arrow", -> - obj = - value: 100 - getValue: const => - @value - - result = obj\getValue! - assert.same result, 100 - it "should work with complex expressions", -> const complex = { data: [1, 2, 3] diff --git a/spec/inputs/test/do_statement_spec.yue b/spec/inputs/test/do_statement_spec.yue index 0adad20..2611cba 100644 --- a/spec/inputs/test/do_statement_spec.yue +++ b/spec/inputs/test/do_statement_spec.yue @@ -62,7 +62,7 @@ describe "do statement", -> it "should support variable shadowing", -> x = "outer" result = do - x = "inner" + local x = "inner" x assert.same result, "inner" assert.same x, "outer" @@ -74,7 +74,7 @@ describe "do statement", -> result = do with obj - \double! + break \double! assert.same result, 20 it "should handle comprehensions in do block", -> @@ -84,13 +84,13 @@ describe "do statement", -> assert.same result, {2, 4, 6, 8, 10} it "should work with try-catch", -> - result = do - success = try - error "test error" - false - catch err - true - assert.is_true success + success, result = try + error "test error" + false + catch err + true + assert.is_false success + assert.is_true result it "should support return statement", -> fn = -> @@ -125,13 +125,15 @@ describe "do statement", -> it "should support implicit return", -> result = do value = 42 + value assert.same result, 42 it "should handle empty do block", -> - result = do + result = do nil assert.same result, nil it "should work with backcalls", -> + map = (f, items) -> [f item for item in *items] result = do items = [1, 2, 3] (x) <- map _, items diff --git a/spec/inputs/test/functions_advanced_spec.yue b/spec/inputs/test/functions_advanced_spec.yue index d0e0cf5..32f0718 100644 --- a/spec/inputs/test/functions_advanced_spec.yue +++ b/spec/inputs/test/functions_advanced_spec.yue @@ -19,32 +19,32 @@ describe "advanced functions", -> x + y assert.same fn!, 1200 - assert.same fn(50), 1150 + assert.same fn(50), 1100 it "should work with multi-line arguments", -> my_func = (a, b, c, d, e, f) -> a + b + c + d + e + f result = my_func 5, 4, 3, 8, 9, 10 assert.same result, 39 - + it "should support nested function calls", -> + another_func = (a, b, c, d, e, f) -> a + b + c + d + e + f + my_func = (a, b, c, d, e, f, g) -> a + b + c + d + e + f + g + result = my_func 5, 6, 7, 6, another_func 6, 7, 8, 9, 1, 2, 5, 4 - - another_func = (a, b, c, d, e, f) -> a + b + c + d + e + f - my_func = (a, b, c, d, e, f) -> a + b + c + d + e + f - - assert.same result, 52 + + assert.same result, 66 it "should handle implicit return", -> sum = (x, y) -> x + y - assert.same sum 10, 20, 30 + assert.same sum(10, 20), 30 it "should work with explicit return", -> difference = (x, y) -> return x - y - assert.same difference 20, 10, 10 + assert.same difference(20, 10), 10 it "should support multiple return values", -> mystery = (x, y) -> x + y, x - y @@ -85,7 +85,7 @@ describe "advanced functions", -> assert.same fn(1, 2, 3), 3 it "should support prefixed return", -> - findValue: "not found" -> + findValue = (): "not found" -> items = [1, 2, 3] for item in *items if item == 5 @@ -155,4 +155,4 @@ describe "advanced functions", -> -> 0 add = get_operation "add" - assert.same add 5, 3, 8 + assert.same add(5, 3), 8 diff --git a/spec/inputs/test/implicit_object_spec.yue b/spec/inputs/test/implicit_object_spec.yue index cea926e..a0bd331 100644 --- a/spec/inputs/test/implicit_object_spec.yue +++ b/spec/inputs/test/implicit_object_spec.yue @@ -142,9 +142,9 @@ describe "implicit object", -> it "should handle empty implicit object", -> tb = items: - - + - nil - assert.same tb.items, {nil} + assert.same tb, {items: [nil,]} it "should work in function arguments", -> fn = (items) -> #items diff --git a/spec/inputs/test/in_expression_spec.yue b/spec/inputs/test/in_expression_spec.yue index c1f4099..d9e3aec 100644 --- a/spec/inputs/test/in_expression_spec.yue +++ b/spec/inputs/test/in_expression_spec.yue @@ -9,11 +9,11 @@ describe "in expression", -> assert.is_true "b" in chars assert.is_false "z" in chars - it "should check keys in table", -> - obj = {x: 1, y: 2, z: 3} - assert.is_true "x" in obj - assert.is_true "y" in obj - assert.is_false "w" in obj + it "should check in table literal", -> + x = 1; y = 2; z = 3; w = 4 + assert.is_true x in [x, y, z] + assert.is_true y in [x, y, z] + assert.is_false w in [x, y, z] it "should work with mixed types", -> items = {1, "two", true, nil} @@ -41,7 +41,8 @@ describe "in expression", -> assert.is_false not (2 in items) it "should work with nested tables", -> - nested = {{1, 2}, {3, 4}, {5, 6}} + eq = (other) => @[1] == other[1] and @[2] == other[2] + nested = {{1, 2, :}, {3, 4, :}, {5, 6, :}} assert.is_true {1, 2} in nested assert.is_false {1, 3} in nested @@ -60,7 +61,7 @@ describe "in expression", -> it "should support table as value", -> key1 = {a: 1} key2 = {b: 2} - tb = {[key1]: "first", [key2]: "second"} + tb = [key1, key2] -- Note: this tests table reference equality assert.is_true key1 in tb @@ -77,7 +78,7 @@ describe "in expression", -> assert.is_true 1 in items it "should work with string keys", -> - obj = {name: "test", value: 42} + obj = ["name", "value"] assert.is_true "name" in obj assert.is_true "value" in obj assert.is_false "missing" in obj diff --git a/spec/inputs/test/multiline_args_spec.yue b/spec/inputs/test/multiline_args_spec.yue index bbb06f9..add9d2b 100644 --- a/spec/inputs/test/multiline_args_spec.yue +++ b/spec/inputs/test/multiline_args_spec.yue @@ -1,6 +1,6 @@ describe "multiline arguments", -> it "should split arguments across lines", -> - sum = (a, b, c) -> a + b + c + sum = (a, b, c, d, e, f) -> a + b + c + d + e + f result = sum 5, 4, 3, 8, 9, 10 assert.same result, 39 @@ -42,46 +42,46 @@ describe "multiline arguments", -> assert.same result, {1, 2, 3, 4, 9, 8, 9, 10} it "should handle deeply nested indentation", -> - y = [ fn 1, 2, 3, - 4, 5, - 5, 6, 7 - ] - - -- Create the function first + -- Create function first fn = (a, b, c, d, e, f, g) -> a + b + c + d + e + f + g + y = { fn 1, 2, 3, + 4, + 5, 6, 7 + } result = y[1] - assert.same result, 22 + assert.same result, 28 it "should work with conditional statements", -> - fn = (a, b, c, d, e) -> a + b + c + d + e - - result = if fn 1, 2, 3, - "hello", - "world" - "yes" - else - "no" + fn = (a, b, c, d, e, f) -> a + b + c + d + e + f + result1 = fn 1, 2, 3, + 4, 5, + 6 + + result = if result1 > 20 + "yes" + else + "no" assert.same result, "yes" it "should support function expressions", -> - double = (x) -> x * 2 - result = double 5, + doublePlus = (x, y) -> x * 2 + y + result = doublePlus 5, 10 assert.same result, 20 it "should handle chained function calls", -> - add = (a, b) -> a + b - multiply = (a, b) -> a * b - - result = multiply add 1, 2, - add 3, 4 - assert.same result, 21 + add = (a, b, c, d) -> a + b + c + d + multiply = (a, b, c, d) -> a * b * c * d + + result = multiply 1, 2, + 3, 4 + assert.same result, 24 it "should work with method calls", -> obj = value: 10 - add: (a, b) => @value + a + b + add: (a, b, c) => @value + a + b + c result = obj\add 5, 10, 15 @@ -100,7 +100,7 @@ describe "multiline arguments", -> assert.same result, 45 it "should work with return statement", -> - fn = (a, b) -> a + b + fn = (a, b, c) -> a + b + c get_value = -> return fn 10, 20, 30 diff --git a/spec/inputs/test/named_varargs_spec.yue b/spec/inputs/test/named_varargs_spec.yue index a5ab2b1..29869b5 100644 --- a/spec/inputs/test/named_varargs_spec.yue +++ b/spec/inputs/test/named_varargs_spec.yue @@ -97,12 +97,11 @@ describe "named varargs", -> assert.same result, {"a", "b", "c"} it "should support passing named varargs to another function", -> + inner = (...) -> + {...} outer = (...t) -> - inner (table.unpack t) - - inner = (a, b, c) -> - {a, b, c} - + inner t[1], t[2], t[3] + result = outer 1, 2, 3 assert.same result, {1, 2, 3} diff --git a/spec/inputs/test/operator_advanced_spec.yue b/spec/inputs/test/operator_advanced_spec.yue index 8127fd4..8f88d17 100644 --- a/spec/inputs/test/operator_advanced_spec.yue +++ b/spec/inputs/test/operator_advanced_spec.yue @@ -75,7 +75,7 @@ describe "advanced operators", -> it "should handle compound bitwise xor", -> x = 12 -- 1100 in binary - x ~= 10 -- 1010 in binary + x = x~10 -- 1010 in binary assert.same x, 6 -- 0110 in binary it "should work with compound left shift", -> @@ -121,10 +121,10 @@ describe "advanced operators", -> it "should work with :: for method chaining", -> obj = value: 10 - add: (n) => @value += n + add: (n): @ => @value += n get: => @value - result = obj::add 5::get! + result = obj::add(5)::get! assert.same result, 15 it "should handle complex expressions with precedence", -> diff --git a/spec/inputs/test/param_destructure_spec.yue b/spec/inputs/test/param_destructure_spec.yue index 4659031..5b9ef83 100644 --- a/spec/inputs/test/param_destructure_spec.yue +++ b/spec/inputs/test/param_destructure_spec.yue @@ -38,10 +38,10 @@ describe "parameter destructuring", -> assert.same result, {1, 2, 3} it "should support mixed array and object", -> - f = ([first], {key: :value}) -> + f = ([first,], {key: :value}) -> {first, value} - result = f [1], {key: "test"} + result = f [1,], {key: value: "test"} assert.same result, {1, "test"} it "should work with fat arrow", -> @@ -54,7 +54,7 @@ describe "parameter destructuring", -> assert.same result, 130 it "should handle missing keys", -> - f = (:a, :b = "default", :c = "missing") -> + f = ({:a, :b = "default", :c = "missing"}) -> {a, b, c} result = f a: 1 @@ -89,10 +89,10 @@ describe "parameter destructuring", -> assert.same result, {1, {2, 3, 4}} it "should support spreading", -> - f = (...rest, :last) -> + f = ({...rest, :last}) -> {rest, last} - - result = f 1, 2, 3, {last: "final"} + + result = f {1, 2, 3, last: "final"} assert.same result, {{1, 2, 3}, 'final'} it "should work with table comprehensions", -> @@ -103,8 +103,8 @@ describe "parameter destructuring", -> assert.same result, {2, 4, 6} it "should handle nil arguments", -> - f = (:a = "nil_a", :b = "nil_b") -> + f = ({:a = "nil_a", :b = "nil_b"}) -> {a, b} - - result = f nil, nil - assert.same result, {'nil_a', 'nil_b'} + + result = f {} + assert.same result, {"nil_a", "nil_b"} diff --git a/spec/inputs/test/reverse_index_spec.yue b/spec/inputs/test/reverse_index_spec.yue index be67261..3c17d09 100644 --- a/spec/inputs/test/reverse_index_spec.yue +++ b/spec/inputs/test/reverse_index_spec.yue @@ -42,10 +42,6 @@ describe "reverse index", -> last = data.items.nested[#] assert.same last, 3 - it "should work with string", -> - s = "hello" - assert.same s[#], "o" - it "should handle negative offsets", -> tab = [1, 2, 3, 4, 5] assert.same tab[#-3], 2 diff --git a/spec/inputs/test/slicing_spec.yue b/spec/inputs/test/slicing_spec.yue index b0a686b..2f5b1a7 100644 --- a/spec/inputs/test/slicing_spec.yue +++ b/spec/inputs/test/slicing_spec.yue @@ -1,27 +1,27 @@ describe "slicing", -> it "should slice array with basic syntax", -> items = [1, 2, 3, 4, 5] - result = items[1..3] + result = items[1, 3] assert.same result, {1, 2, 3} it "should slice from beginning", -> items = [1, 2, 3, 4, 5] - result = items[1..#items] + result = items[1, #items] assert.same result, {1, 2, 3, 4, 5} it "should slice to end", -> items = [1, 2, 3, 4, 5] - result = items[3..5] + result = items[3, 5] assert.same result, {3, 4, 5} it "should handle negative indices", -> items = [1, 2, 3, 4, 5] - result = items[#items-2..#items] + result = items[-3, -1] assert.same result, {3, 4, 5} it "should slice single element", -> items = [1, 2, 3, 4, 5] - result = items[2..2] + result = items[2, 2] assert.same result, {2} it "should work with strings", -> @@ -31,18 +31,18 @@ describe "slicing", -> it "should handle out of bounds", -> items = [1, 2, 3] - result = items[1..10] + result = items[1, 10] assert.same result, {1, 2, 3} it "should create new table", -> original = [1, 2, 3, 4, 5] - sliced = original[2..4] + sliced = original[2, 4] sliced[1] = 99 assert.same original[2], 2 -- original unchanged it "should work with nested arrays", -> - nested = [[1, 2], [3, 4], [5, 6]] - result = nested[1..2] + nested = [ [1, 2], [3, 4], [5, 6]] + result = nested[1, 2] assert.same result, {{1, 2}, {3, 4}} it "should slice with step simulation", -> @@ -52,8 +52,8 @@ describe "slicing", -> it "should handle empty slice range", -> items = [1, 2, 3, 4, 5] - result = items[6..10] - assert.same result, nil + result = items[6, 10] + assert.same result, {} it "should work with reverse indexing", -> items = [1, 2, 3, 4, 5] diff --git a/spec/inputs/test/stub_spec.yue b/spec/inputs/test/stub_spec.yue index 99345c7..835610b 100644 --- a/spec/inputs/test/stub_spec.yue +++ b/spec/inputs/test/stub_spec.yue @@ -1,3 +1,6 @@ +-- Define stub_fn as a helper function that returns an empty function +stub_fn = -> -> + describe "function stub", -> it "should create empty function", -> stub_fn! diff --git a/spec/inputs/test/table_append_spec.yue b/spec/inputs/test/table_append_spec.yue index ab3d6d2..51c7873 100644 --- a/spec/inputs/test/table_append_spec.yue +++ b/spec/inputs/test/table_append_spec.yue @@ -30,12 +30,12 @@ describe "table append", -> tab[] = ...tb2 assert.same tab, {1, 2} - it "should append nil values", -> + it "should not append nil values", -> tab = [] tab[] = nil tab[] = "value" - assert.same tab[1], nil - assert.same tab[2], "value" + assert.same tab[2], nil + assert.same tab[1], "value" it "should work in loop", -> tab = [] @@ -73,5 +73,5 @@ describe "table append", -> it "should append function results", -> fn = -> 1, 2, 3 tab = [] - tab[] = fn! + tab[] = ...[fn!,] assert.same tab, {1, 2, 3} diff --git a/spec/inputs/test/table_comprehension_spec.yue b/spec/inputs/test/table_comprehension_spec.yue index f4d7cdb..caebdef 100644 --- a/spec/inputs/test/table_comprehension_spec.yue +++ b/spec/inputs/test/table_comprehension_spec.yue @@ -112,7 +112,7 @@ describe "table comprehension", -> assert.same result.e, nil it "should work with custom iterator", -> - custom_iter = -> -> + custom_iter = -> state = 0 -> state += 1 diff --git a/spec/inputs/test/tables_advanced_spec.yue b/spec/inputs/test/tables_advanced_spec.yue index c8cc7d5..82f4d4e 100644 --- a/spec/inputs/test/tables_advanced_spec.yue +++ b/spec/inputs/test/tables_advanced_spec.yue @@ -35,8 +35,9 @@ describe "advanced tables", -> assert.same tb[4], 4 it "should work with single line table literals", -> - my_function dance: "Tango", partner: "none" - assert.is_true true + tb = dance: "Tango", partner: "none" + assert.same tb.dance, "Tango" + assert.same tb.partner, "none" it "should support nested tables", -> tb = @@ -90,10 +91,9 @@ describe "advanced tables", -> assert.same merge.y, 1 it "should handle mixed spread", -> - parts = { + parts = * "shoulders" * "knees" - } lyrics = * "head" * ...parts @@ -108,7 +108,7 @@ describe "advanced tables", -> a = <>: mt, value: 1 b = value: 2 - b.<>, mt + b.<> = mt c = a + b assert.same c.value, 3 @@ -121,11 +121,12 @@ describe "advanced tables", -> tb = { item: "test" new: -> "created" - close: -> "closed" + : -> "closed" } {:item, :new, :} = tb assert.same item, "test" assert.same new!, "created" + assert.same close!, "closed" it "should work with string keys directly", -> t = { diff --git a/spec/inputs/test/varargs_assignment_spec.yue b/spec/inputs/test/varargs_assignment_spec.yue index 1c3b627..dfd606b 100644 --- a/spec/inputs/test/varargs_assignment_spec.yue +++ b/spec/inputs/test/varargs_assignment_spec.yue @@ -46,7 +46,7 @@ describe "varargs assignment", -> assert.same select(3, ...), 2 it "should work with table.unpack", -> - tb = {a: 1, b: 2, c: 3} + tb = [1, 2, 3] fn = -> table.unpack tb ... = fn! count = select '#', ... diff --git a/spec/inputs/test/whitespace_spec.yue b/spec/inputs/test/whitespace_spec.yue index baf3fd5..43b7644 100644 --- a/spec/inputs/test/whitespace_spec.yue +++ b/spec/inputs/test/whitespace_spec.yue @@ -8,13 +8,14 @@ describe "whitespace", -> assert.same z, 30 it "should work with semicolon in function", -> - fn = -> a = 1; b = 2; a + b + fn = -> + a = 1; b = 2; a + b assert.same fn!, 3 it "should support multiline chaining", -> obj = value: 10 - add: (n) => @value += n + add: (n): @ => @value += n get: => @value result = obj @@ -26,7 +27,7 @@ describe "whitespace", -> it "should handle multiline method calls", -> str = " hello " result = str - \trim! + \match "^%s*(.-)%s*$" \upper! assert.same result, "HELLO" @@ -53,7 +54,7 @@ describe "whitespace", -> it "should work with pipe in chaining", -> result = [1, 2, 3] - |> [x * 2 for x in *] + |> ((tb) -> [x * 2 for x in *tb]) |> table.concat assert.same result, "246" @@ -68,7 +69,7 @@ describe "whitespace", -> fn = -> if true result = 10 - result + result assert.same fn!, 10 @@ -91,7 +92,7 @@ describe "whitespace", -> it "should work in multiline function call", -> sum = (a, b) -> a + b - result = sum 5, 10, + result = sum 5, sum 10, sum 3, 7 assert.same result, 25 @@ -105,13 +106,15 @@ describe "whitespace", -> assert.same doubled, 10 it "should handle complex chaining", -> - result = "hello" + result = ("hello") \upper! \sub 1, 3 \lower! assert.same result, "hel" it "should work with backcalls and whitespace", -> + readAsync = (file, callback) -> callback "data" + process = (data) -> true if data results = do data <- readAsync "data.txt" process data diff --git a/spec/inputs/test/with_statement_spec.yue b/spec/inputs/test/with_statement_spec.yue index c2f9b3b..71ac215 100644 --- a/spec/inputs/test/with_statement_spec.yue +++ b/spec/inputs/test/with_statement_spec.yue @@ -27,7 +27,7 @@ describe "with statement", -> obj = {x: 1} with obj .x = 10 - with .nested = {y: 2} + with .nested := {y: 2} .y = 20 assert.same obj.x, 10 assert.same obj.nested.y, 20 @@ -35,7 +35,7 @@ describe "with statement", -> it "should work in expressions", -> obj = {value: 5} result = with obj - .value * 2 + break .value * 2 assert.same result, 10 it "should support multiple statements", -> @@ -76,13 +76,13 @@ describe "with statement", -> it "should support with in assignment", -> obj = {x: 5, y: 10} result = with obj - .x + .y + break .x + .y assert.same result, 15 it "should work with string methods", -> s = "hello" result = with s - \upper! + break \upper! assert.same result, "HELLO" it "should handle metatable access", -> @@ -98,7 +98,7 @@ describe "with statement", -> fn = -> obj = {x: 10} with obj - .x * 2 + break .x * 2 result = fn! assert.same result, 20 @@ -107,19 +107,19 @@ describe "with statement", -> get_value = -> obj = {value: 42} with obj - .value + break .value assert.same get_value!, 42 it "should work with existential operator", -> obj = {value: 10} result = with obj - .value ? 0 + break .value ?? 0 assert.same result, 10 it "should handle nil object safely", -> - result = with nil - .value + result = with? nil + break .value assert.same result, nil it "should work with method chaining", -> @@ -131,7 +131,7 @@ describe "with statement", -> result = with obj \add 10 \add 5 - \get! + break \get! assert.same result, 20 it "should support nested property access", -> @@ -141,5 +141,5 @@ describe "with statement", -> level3: "deep" result = with obj - .level1.level2.level3 + break .level1.level2.level3 assert.same result, "deep" diff --git a/spec/inputs/test/yaml_string_spec.yue b/spec/inputs/test/yaml_string_spec.yue index 1296340..0a7d61b 100644 --- a/spec/inputs/test/yaml_string_spec.yue +++ b/spec/inputs/test/yaml_string_spec.yue @@ -3,15 +3,15 @@ describe "yaml string", -> s = | hello world - assert.is_true s\match "hello" - assert.is_true s\match "world" + assert.is_true s\match("hello")? + assert.is_true s\match("world")? it "should preserve indentation", -> s = | key1: value1 key2: value2 - assert.is_true s\match "key1" - assert.is_true s\match "key2" + assert.is_true s\match("key1")? + assert.is_true s\match("key2")? it "should support interpolation", -> name = "test" @@ -25,13 +25,13 @@ describe "yaml string", -> point: x: #{x} y: #{y} - assert.is_true s\match "x: 10" - assert.is_true s\match "y: 20" + assert.is_true s\match("x: 10")? + assert.is_true s\match("y: 20")? it "should work with expressions", -> s = | result: #{1 + 2} - assert.is_true s\match "result: 3" + assert.is_true s\match("result: 3")? it "should support multiline with variables", -> config = | @@ -39,15 +39,17 @@ describe "yaml string", -> host: localhost port: 5432 name: mydb - assert.is_true config\match "database:" - assert.is_true config\match "host:" + assert.is_true config\match("database:")? + assert.is_true config\match("host:")? it "should escape special characters", -> + Hello = "Hello" s = | path: "C:\Program Files\App" note: 'He said: "#{Hello}!"' - assert.is_true s\match "path:" - assert.is_true s\match "note:" + assert.same s, [[ +path: "C:\Program Files\App" +note: 'He said: "Hello!"']] it "should work in function", -> fn = -> @@ -57,8 +59,7 @@ describe "yaml string", -> return str result = fn! - assert.is_true result\match "foo:" - assert.is_true result\match "bar:" + assert.same result, "foo:\n\tbar: baz" it "should strip common leading whitespace", -> fn = -> @@ -68,40 +69,39 @@ describe "yaml string", -> s result = fn! - assert.is_true result\match "nested:" - assert.is_true result\match "item:" + assert.same result, "nested: + item: value" it "should support empty lines", -> s = | line1 line3 - assert.is_true s\match "line1" - assert.is_true s\match "line3" + assert.same s, "line1\nline3" it "should work with table access in interpolation", -> t = {value: 100} s = | value: #{t.value} - assert.is_true s\match "value: 100" + assert.same s, "value: 100" it "should support function calls in interpolation", -> s = | result: #{(-> 42)!} - assert.is_true s\match "result: 42" + assert.same s, "result: 42" it "should handle quotes correctly", -> s = | "quoted" 'single quoted' - assert.is_true s\match '"quoted"' - assert.is_true s\match "'single quoted'" + assert.is_true s\match('"quoted"')? + assert.is_true s\match("'single quoted'")? it "should work with multiple interpolations", -> a, b, c = 1, 2, 3 s = | values: #{a}, #{b}, #{c} - assert.is_true s\match "values: 1, 2, 3" + assert.same s, "values: 1, 2, 3" it "should preserve newlines", -> s = | diff --git a/spec/inputs/unicode/syntax.yue b/spec/inputs/unicode/syntax.yue index 939579b..b5494f4 100644 --- a/spec/inputs/unicode/syntax.yue +++ b/spec/inputs/unicode/syntax.yue @@ -81,11 +81,11 @@ _ = 这里(我们)"去"[12123] 分裂"abc xyz 123"\映射"#"\打印全部! -_ = f""[变量a] +_ = f("")[变量a] _ = f""\变量b! _ = f"".变量c! -f ""[变量a] +f ("")[变量a] f ""\变量b! f "".变量c! -- cgit v1.2.3-55-g6feb