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/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 ++++++++++++ 6 files changed, 46 insertions(+) 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 (limited to 'spec/inputs/test') 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 -- cgit v1.2.3-55-g6feb