aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-22 15:03:12 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-22 15:03:12 +0800
commitf1454bbbd13a71da2005ff789cde2da0e9eb81f6 (patch)
tree37131187f4218dd3ebec049101c28a161e7ca289 /spec/inputs
parent604a8e5e53cdc7391a502fcabf07e8f1cc2a778c (diff)
downloadyuescript-f1454bbbd13a71da2005ff789cde2da0e9eb81f6.tar.gz
yuescript-f1454bbbd13a71da2005ff789cde2da0e9eb81f6.tar.bz2
yuescript-f1454bbbd13a71da2005ff789cde2da0e9eb81f6.zip
Adding tests.HEADmain
Diffstat (limited to 'spec/inputs')
-rw-r--r--spec/inputs/comprehension_nested.yue3
-rw-r--r--spec/inputs/destructure_defaults.yue9
-rw-r--r--spec/inputs/export_mixed.yue3
-rw-r--r--spec/inputs/nil_coalesce_precedence.yue8
-rw-r--r--spec/inputs/pipe_chain_combo.yue8
-rw-r--r--spec/inputs/test/comprehension_spec.yue5
-rw-r--r--spec/inputs/test/destructure_spec.yue5
-rw-r--r--spec/inputs/test/format_spec.yue12
-rw-r--r--spec/inputs/test/nil_coalescing_spec.yue7
-rw-r--r--spec/inputs/test/pipe_spec.yue5
-rw-r--r--spec/inputs/test/try_catch_spec.yue12
-rw-r--r--spec/inputs/unicode/pipe_chain_combo.yue8
-rw-r--r--spec/inputs/with_scope_shadow.yue12
13 files changed, 97 insertions, 0 deletions
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 @@
1list = {1, 2, 3}
2pairs = ["#{i}-#{j}" for i in *list when i % 2 == 1 for j in *list when j > i]
3print 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 @@
1t = {
2 a: 1
3 b:
4 c: 3
5 d: nil
6}
7
8{:a, b: {:c, :d = 4}, :e = 5} = t
9print 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 @@
1export answer = 42
2export foo = -> "bar"
3export 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 @@
1a = nil
2b = false
3c = 0
4
5x = a ?? (b and 1) ?? (c or 2)
6y = (a ?? b) and 1 or 2
7
8print 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 @@
1f1 = (x)-> x + 2
2f2 = (x)-> x * 3
3
4value = 3
5 |> f1
6 |> f2
7 |> tostring
8 |> 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 @@
1describe "comprehension", ->
2 it "nested with filter", ->
3 list = {1, 2, 3}
4 out = ["#{i}-#{j}" for i in *list when i % 2 == 1 for j in *list when j > i]
5 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 @@
1describe "destructure", ->
2 it "defaults and nested", ->
3 t = { a: 1, b: { c: 3 }, d: nil }
4 {:a, b: {:c, :d = 4}, :e = 5} = t
5 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 = [
95 "spec/inputs/unicode/syntax.yue" 95 "spec/inputs/unicode/syntax.yue"
96 "spec/inputs/unicode/global.yue" 96 "spec/inputs/unicode/global.yue"
97 "spec/inputs/unicode/plus.yue" 97 "spec/inputs/unicode/plus.yue"
98 "spec/inputs/pipe_chain_combo.yue"
99 "spec/inputs/destructure_defaults.yue"
100 "spec/inputs/nil_coalesce_precedence.yue"
101 "spec/inputs/comprehension_nested.yue"
102 "spec/inputs/with_scope_shadow.yue"
103 "spec/inputs/export_mixed.yue"
104 "spec/inputs/unicode/pipe_chain_combo.yue"
105 "spec/inputs/test/destructure_spec.yue"
106 "spec/inputs/test/nil_coalescing_spec.yue"
107 "spec/inputs/test/pipe_spec.yue"
108 "spec/inputs/test/try_catch_spec.yue"
109 "spec/inputs/test/comprehension_spec.yue"
98] 110]
99 111
100import "yue" 112import "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 @@
1describe "nil coalescing", ->
2 it "distinguish nil and false", ->
3 a = nil
4 b = false
5 c = 0
6 assert.same (a ?? b), false
7 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 @@
1describe "pipe", ->
2 it "pipes through functions", ->
3 f = (x)-> x + 1
4 g = (x)-> x * 2
5 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 @@
1describe "try/catch", ->
2 it "catch and rethrow", ->
3 ok, success, err = pcall ->
4 try
5 error "boom"
6 catch e
7 _, result = try
8 error "wrap:" .. e\match "^.-:%d+:%s*(.*)$"
9 result
10 assert.same ok, true
11 assert.same success, false
12 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 @@
1加 = (x)-> x + 2
2乘 = (x)-> x * 3
3
4值 = 3
5 |> 加
6 |> 乘
7 |> tostring
8 |> 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 @@
1target = {
2 val: 1
3 add: (n)=>
4 @val += n
5 @val
6}
7
8result = with target
9 val = 100
10 add 2
11
12print result, target.val