aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test
diff options
context:
space:
mode:
Diffstat (limited to 'spec/inputs/test')
-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
6 files changed, 46 insertions, 0 deletions
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