From f1454bbbd13a71da2005ff789cde2da0e9eb81f6 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 22 Jan 2026 15:03:12 +0800 Subject: Adding tests. --- spec/inputs/comprehension_nested.yue | 3 +++ spec/inputs/destructure_defaults.yue | 9 +++++++++ spec/inputs/export_mixed.yue | 3 +++ spec/inputs/nil_coalesce_precedence.yue | 8 ++++++++ spec/inputs/pipe_chain_combo.yue | 8 ++++++++ spec/inputs/test/comprehension_spec.yue | 5 +++++ spec/inputs/test/destructure_spec.yue | 5 +++++ spec/inputs/test/format_spec.yue | 12 ++++++++++++ spec/inputs/test/nil_coalescing_spec.yue | 7 +++++++ spec/inputs/test/pipe_spec.yue | 5 +++++ spec/inputs/test/try_catch_spec.yue | 12 ++++++++++++ spec/inputs/unicode/pipe_chain_combo.yue | 8 ++++++++ spec/inputs/with_scope_shadow.yue | 12 ++++++++++++ 13 files changed, 97 insertions(+) create mode 100644 spec/inputs/comprehension_nested.yue create mode 100644 spec/inputs/destructure_defaults.yue create mode 100644 spec/inputs/export_mixed.yue create mode 100644 spec/inputs/nil_coalesce_precedence.yue create mode 100644 spec/inputs/pipe_chain_combo.yue create mode 100644 spec/inputs/test/comprehension_spec.yue create mode 100644 spec/inputs/test/destructure_spec.yue create mode 100644 spec/inputs/test/nil_coalescing_spec.yue create mode 100644 spec/inputs/test/pipe_spec.yue create mode 100644 spec/inputs/test/try_catch_spec.yue create mode 100644 spec/inputs/unicode/pipe_chain_combo.yue create mode 100644 spec/inputs/with_scope_shadow.yue (limited to 'spec/inputs') diff --git a/spec/inputs/comprehension_nested.yue b/spec/inputs/comprehension_nested.yue new file mode 100644 index 0000000..c60419d --- /dev/null +++ b/spec/inputs/comprehension_nested.yue @@ -0,0 +1,3 @@ +list = {1, 2, 3} +pairs = ["#{i}-#{j}" for i in *list when i % 2 == 1 for j in *list when j > i] +print table.concat pairs, "," diff --git a/spec/inputs/destructure_defaults.yue b/spec/inputs/destructure_defaults.yue new file mode 100644 index 0000000..112d4a1 --- /dev/null +++ b/spec/inputs/destructure_defaults.yue @@ -0,0 +1,9 @@ +t = { + a: 1 + b: + c: 3 + d: nil +} + +{:a, b: {:c, :d = 4}, :e = 5} = t +print a, c, d, e diff --git a/spec/inputs/export_mixed.yue b/spec/inputs/export_mixed.yue new file mode 100644 index 0000000..5adfdd7 --- /dev/null +++ b/spec/inputs/export_mixed.yue @@ -0,0 +1,3 @@ +export answer = 42 +export foo = -> "bar" +export baz = "baz" diff --git a/spec/inputs/nil_coalesce_precedence.yue b/spec/inputs/nil_coalesce_precedence.yue new file mode 100644 index 0000000..4e7eabf --- /dev/null +++ b/spec/inputs/nil_coalesce_precedence.yue @@ -0,0 +1,8 @@ +a = nil +b = false +c = 0 + +x = a ?? (b and 1) ?? (c or 2) +y = (a ?? b) and 1 or 2 + +print x, y diff --git a/spec/inputs/pipe_chain_combo.yue b/spec/inputs/pipe_chain_combo.yue new file mode 100644 index 0000000..d9265e4 --- /dev/null +++ b/spec/inputs/pipe_chain_combo.yue @@ -0,0 +1,8 @@ +f1 = (x)-> x + 2 +f2 = (x)-> x * 3 + +value = 3 + |> f1 + |> f2 + |> tostring + |> print diff --git a/spec/inputs/test/comprehension_spec.yue b/spec/inputs/test/comprehension_spec.yue new file mode 100644 index 0000000..5f24aba --- /dev/null +++ b/spec/inputs/test/comprehension_spec.yue @@ -0,0 +1,5 @@ +describe "comprehension", -> + it "nested with filter", -> + list = {1, 2, 3} + out = ["#{i}-#{j}" for i in *list when i % 2 == 1 for j in *list when j > i] + assert.same out, {"1-2", "1-3"} diff --git a/spec/inputs/test/destructure_spec.yue b/spec/inputs/test/destructure_spec.yue new file mode 100644 index 0000000..802774c --- /dev/null +++ b/spec/inputs/test/destructure_spec.yue @@ -0,0 +1,5 @@ +describe "destructure", -> + it "defaults and nested", -> + t = { a: 1, b: { c: 3 }, d: nil } + {:a, b: {:c, :d = 4}, :e = 5} = t + assert.same {a, c, d, e}, {1, 3, 4, 5} diff --git a/spec/inputs/test/format_spec.yue b/spec/inputs/test/format_spec.yue index 95f73fc..6b94540 100644 --- a/spec/inputs/test/format_spec.yue +++ b/spec/inputs/test/format_spec.yue @@ -95,6 +95,18 @@ files = [ "spec/inputs/unicode/syntax.yue" "spec/inputs/unicode/global.yue" "spec/inputs/unicode/plus.yue" + "spec/inputs/pipe_chain_combo.yue" + "spec/inputs/destructure_defaults.yue" + "spec/inputs/nil_coalesce_precedence.yue" + "spec/inputs/comprehension_nested.yue" + "spec/inputs/with_scope_shadow.yue" + "spec/inputs/export_mixed.yue" + "spec/inputs/unicode/pipe_chain_combo.yue" + "spec/inputs/test/destructure_spec.yue" + "spec/inputs/test/nil_coalescing_spec.yue" + "spec/inputs/test/pipe_spec.yue" + "spec/inputs/test/try_catch_spec.yue" + "spec/inputs/test/comprehension_spec.yue" ] import "yue" diff --git a/spec/inputs/test/nil_coalescing_spec.yue b/spec/inputs/test/nil_coalescing_spec.yue new file mode 100644 index 0000000..4f845b3 --- /dev/null +++ b/spec/inputs/test/nil_coalescing_spec.yue @@ -0,0 +1,7 @@ +describe "nil coalescing", -> + it "distinguish nil and false", -> + a = nil + b = false + c = 0 + assert.same (a ?? b), false + assert.same (a ?? c), 0 diff --git a/spec/inputs/test/pipe_spec.yue b/spec/inputs/test/pipe_spec.yue new file mode 100644 index 0000000..58d48aa --- /dev/null +++ b/spec/inputs/test/pipe_spec.yue @@ -0,0 +1,5 @@ +describe "pipe", -> + it "pipes through functions", -> + f = (x)-> x + 1 + g = (x)-> x * 2 + assert.same (3 |> f |> g), 8 diff --git a/spec/inputs/test/try_catch_spec.yue b/spec/inputs/test/try_catch_spec.yue new file mode 100644 index 0000000..ed8fef0 --- /dev/null +++ b/spec/inputs/test/try_catch_spec.yue @@ -0,0 +1,12 @@ +describe "try/catch", -> + it "catch and rethrow", -> + ok, success, err = pcall -> + try + error "boom" + catch e + _, result = try + error "wrap:" .. e\match "^.-:%d+:%s*(.*)$" + result + assert.same ok, true + assert.same success, false + assert.is_true err\match("wrap:boom") != nil diff --git a/spec/inputs/unicode/pipe_chain_combo.yue b/spec/inputs/unicode/pipe_chain_combo.yue new file mode 100644 index 0000000..8f85207 --- /dev/null +++ b/spec/inputs/unicode/pipe_chain_combo.yue @@ -0,0 +1,8 @@ +加 = (x)-> x + 2 +乘 = (x)-> x * 3 + +值 = 3 + |> 加 + |> 乘 + |> tostring + |> print diff --git a/spec/inputs/with_scope_shadow.yue b/spec/inputs/with_scope_shadow.yue new file mode 100644 index 0000000..a0d58cc --- /dev/null +++ b/spec/inputs/with_scope_shadow.yue @@ -0,0 +1,12 @@ +target = { + val: 1 + add: (n)=> + @val += n + @val +} + +result = with target + val = 100 + add 2 + +print result, target.val -- cgit v1.2.3-55-g6feb