aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-26 17:45:26 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-26 17:45:56 +0800
commite02321107277a63e7dcb12ab163c9942ac101b87 (patch)
treef38c6f2fbf4ee35df4938933dbc1e645733356f4 /spec/inputs/test
parent5d5b657f606b5939062983b1f90c3359d542672e (diff)
downloadyuescript-e02321107277a63e7dcb12ab163c9942ac101b87.tar.gz
yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.tar.bz2
yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.zip
Updated tests.
Diffstat (limited to 'spec/inputs/test')
-rw-r--r--spec/inputs/test/attrib_spec.yue12
-rw-r--r--spec/inputs/test/backcall_spec.yue5
-rw-r--r--spec/inputs/test/config_spec.yue2
-rw-r--r--spec/inputs/test/existential_spec.yue4
-rw-r--r--spec/inputs/test/export_spec.yue5
-rw-r--r--spec/inputs/test/goto_spec.yue2
-rw-r--r--spec/inputs/test/import_spec.yue4
-rw-r--r--spec/inputs/test/literals_spec.yue4
-rw-r--r--spec/inputs/test/macro_spec.yue10
-rw-r--r--spec/inputs/test/return_spec.yue4
-rw-r--r--spec/inputs/test/string_spec.yue12
-rw-r--r--spec/inputs/test/switch_spec.yue4
-rw-r--r--spec/inputs/test/try_catch_spec.yue1
-rw-r--r--spec/inputs/test/with_spec.yue23
14 files changed, 44 insertions, 48 deletions
diff --git a/spec/inputs/test/attrib_spec.yue b/spec/inputs/test/attrib_spec.yue
index 4a1fcab..ce9956a 100644
--- a/spec/inputs/test/attrib_spec.yue
+++ b/spec/inputs/test/attrib_spec.yue
@@ -14,12 +14,12 @@ describe "attrib", ->
14 it "should support close attribute", -> 14 it "should support close attribute", ->
15 -- close attribute for to-be-closed variables 15 -- close attribute for to-be-closed variables
16 do 16 do
17 close x = 1 17 close x = <close>: ->
18 assert.same x, 1 18 assert.same "table", type x
19 19
20 it "should work with destructuring", -> 20 it "should work with destructuring", ->
21 do 21 do
22 const {a, b} = {a: 1, b: 2} 22 const :a, :b = {a: 1, b: 2}
23 assert.same a, 1 23 assert.same a, 1
24 assert.same b, 2 24 assert.same b, 2
25 25
@@ -45,7 +45,7 @@ describe "attrib", ->
45 it "should support close in expressions", -> 45 it "should support close in expressions", ->
46 do 46 do
47 close result = if true 47 close result = if true
48 42 48 value: 42, <close>: ->
49 else 49 else
50 0 50 value: 0, <close>: ->
51 assert.same result, 42 51 assert.same result.value, 42
diff --git a/spec/inputs/test/backcall_spec.yue b/spec/inputs/test/backcall_spec.yue
index 9534e7c..e7d03ce 100644
--- a/spec/inputs/test/backcall_spec.yue
+++ b/spec/inputs/test/backcall_spec.yue
@@ -4,8 +4,9 @@ describe "backcall", ->
4 mock_map = (list, fn) -> 4 mock_map = (list, fn) ->
5 for item in *list 5 for item in *list
6 table.insert results, fn(item) 6 table.insert results, fn(item)
7 (x) <- mock_map {1, 2, 3} 7 do
8 x * 2 8 (x) <- mock_map {1, 2, 3}
9 x * 2
9 assert.same results, {2, 4, 6} 10 assert.same results, {2, 4, 6}
10 11
11 it "should support nested backcalls", -> 12 it "should support nested backcalls", ->
diff --git a/spec/inputs/test/config_spec.yue b/spec/inputs/test/config_spec.yue
index 2df8ef3..1c87955 100644
--- a/spec/inputs/test/config_spec.yue
+++ b/spec/inputs/test/config_spec.yue
@@ -57,7 +57,7 @@ describe "config", ->
57 it "should handle with statements", -> 57 it "should handle with statements", ->
58 obj = {x: 10, y: 20} 58 obj = {x: 10, y: 20}
59 result = with obj 59 result = with obj
60 .x + .y 60 break .x + .y
61 assert.same result, 30 61 assert.same result, 30
62 62
63 it "should handle existential operators", -> 63 it "should handle existential operators", ->
diff --git a/spec/inputs/test/existential_spec.yue b/spec/inputs/test/existential_spec.yue
index f63967a..2d516a9 100644
--- a/spec/inputs/test/existential_spec.yue
+++ b/spec/inputs/test/existential_spec.yue
@@ -36,8 +36,8 @@ describe "existential", ->
36 36
37 it "should work with ? in if condition", -> 37 it "should work with ? in if condition", ->
38 obj = {value: 5} 38 obj = {value: 5}
39 if obj?.value 39 result = if obj?.value
40 result = "exists" 40 "exists"
41 assert.same result, "exists" 41 assert.same result, "exists"
42 42
43 it "should combine ?. with and/or", -> 43 it "should combine ?. with and/or", ->
diff --git a/spec/inputs/test/export_spec.yue b/spec/inputs/test/export_spec.yue
index c6ea99b..20c0630 100644
--- a/spec/inputs/test/export_spec.yue
+++ b/spec/inputs/test/export_spec.yue
@@ -77,11 +77,6 @@ describe "export", ->
77 assert.same count, 42 77 assert.same count, 42
78 assert.same price, 19.99 78 assert.same price, 19.99
79 79
80 it "should work in nested scope", ->
81 do
82 nested = "value"
83 assert.same nested, "value"
84
85 it "should export function with parameters", -> 80 it "should export function with parameters", ->
86 add = (a, b) -> a + b 81 add = (a, b) -> a + b
87 assert.same add(5, 3), 8 82 assert.same add(5, 3), 8
diff --git a/spec/inputs/test/goto_spec.yue b/spec/inputs/test/goto_spec.yue
index fd2f401..9dad0a7 100644
--- a/spec/inputs/test/goto_spec.yue
+++ b/spec/inputs/test/goto_spec.yue
@@ -24,7 +24,7 @@ describe "goto", ->
24 if x == 2 and y == 2 24 if x == 2 and y == 2
25 goto found 25 goto found
26 ::found:: 26 ::found::
27 assert.same count, 4 -- (1,1), (1,2), (1,3), (2,1), (2,2) 27 assert.same count, 5 -- (1,1), (1,2), (1,3), (2,1), (2,2)
28 28
29 it "should support multiple labels", -> 29 it "should support multiple labels", ->
30 a = 0 30 a = 0
diff --git a/spec/inputs/test/import_spec.yue b/spec/inputs/test/import_spec.yue
index deeb4a0..7952ac0 100644
--- a/spec/inputs/test/import_spec.yue
+++ b/spec/inputs/test/import_spec.yue
@@ -6,10 +6,10 @@ describe "import", ->
6 assert.same foo, "bar" 6 assert.same foo, "bar"
7 7
8 it "should import with backslash escaping", -> 8 it "should import with backslash escaping", ->
9 source = {x: 1, y: 2, z: 3} 9 source = {x: 1, y: =>, z: 3}
10 import x, \y, z from source 10 import x, \y, z from source
11 assert.same x, 1 11 assert.same x, 1
12 assert.same y, 2 12 assert.same "function", type y
13 assert.same z, 3 13 assert.same z, 3
14 14
15 it "should import from string module", -> 15 it "should import from string module", ->
diff --git a/spec/inputs/test/literals_spec.yue b/spec/inputs/test/literals_spec.yue
index 10bd6b3..4c0b8c1 100644
--- a/spec/inputs/test/literals_spec.yue
+++ b/spec/inputs/test/literals_spec.yue
@@ -40,13 +40,13 @@ describe "literals", ->
40 hello 40 hello
41 world 41 world
42 ]] 42 ]]
43 assert.is_true s\match "hello" 43 assert.is_true s\match("hello")?
44 44
45 it "should support multi-line strings with [=[", -> 45 it "should support multi-line strings with [=[", ->
46 s = [==[ 46 s = [==[
47 test 47 test
48 ]==] 48 ]==]
49 assert.is_true s\match "test" 49 assert.is_true s\match("test")?
50 50
51 it "should support boolean true", -> 51 it "should support boolean true", ->
52 assert.same true, true 52 assert.same true, true
diff --git a/spec/inputs/test/macro_spec.yue b/spec/inputs/test/macro_spec.yue
index a4a170b..e254454 100644
--- a/spec/inputs/test/macro_spec.yue
+++ b/spec/inputs/test/macro_spec.yue
@@ -16,7 +16,7 @@ describe "macro", ->
16 it "should validate AST types", -> 16 it "should validate AST types", ->
17 macro NumAndStr = (num`Num, str`SingleString) -> "[#{num}, #{str}]" 17 macro NumAndStr = (num`Num, str`SingleString) -> "[#{num}, #{str}]"
18 result = $NumAndStr 123, 'xyz' 18 result = $NumAndStr 123, 'xyz'
19 assert.same result, "[123, xyz]" 19 assert.same result, [123, 'xyz']
20 20
21 it "should support simple code generation", -> 21 it "should support simple code generation", ->
22 macro add_one = (x) -> "#{x} + 1" 22 macro add_one = (x) -> "#{x} + 1"
@@ -30,9 +30,9 @@ describe "macro", ->
30 assert.same result, 7 30 assert.same result, 7
31 31
32 it "should respect macro scope in do blocks", -> 32 it "should respect macro scope in do blocks", ->
33 macro outer = -> "outer" 33 macro outer = -> "'outer'"
34 do 34 do
35 macro inner = -> "inner" 35 macro inner = -> "'inner'"
36 result = $inner! 36 result = $inner!
37 assert.same result, "inner" 37 assert.same result, "inner"
38 result = $outer! 38 result = $outer!
@@ -94,7 +94,7 @@ describe "macro", ->
94 it "should work with string interpolation", -> 94 it "should work with string interpolation", ->
95 macro format_result = (name, value) -> "#{name}: #{value}" 95 macro format_result = (name, value) -> "#{name}: #{value}"
96 result = $format_result "test", 123 96 result = $format_result "test", 123
97 assert.same result, "test: 123" 97 assert.same result, test: 123
98 98
99 it "should support function call syntax", -> 99 it "should support function call syntax", ->
100 macro my_func = (x, y) -> "#{x} + #{y}" 100 macro my_func = (x, y) -> "#{x} + #{y}"
@@ -130,6 +130,6 @@ describe "macro", ->
130 assert.same result, 7 130 assert.same result, 7
131 131
132 it "should work with string literals", -> 132 it "should work with string literals", ->
133 macro greet = (name) -> '"Hello, #{name}"' 133 macro greet = (name) -> "'Hello, ' .. #{name}"
134 result = $greet "World" 134 result = $greet "World"
135 assert.same result, "Hello, World" 135 assert.same result, "Hello, World"
diff --git a/spec/inputs/test/return_spec.yue b/spec/inputs/test/return_spec.yue
index 3bf0bed..9cedc40 100644
--- a/spec/inputs/test/return_spec.yue
+++ b/spec/inputs/test/return_spec.yue
@@ -59,11 +59,11 @@ describe "return", ->
59 assert.same fn({value: 100}), 100 59 assert.same fn({value: 100}), 100
60 60
61 it "should return nil implicitly", -> 61 it "should return nil implicitly", ->
62 fn -> print "no return" 62 fn = -> _ = "no return"
63 assert.same fn!, nil 63 assert.same fn!, nil
64 64
65 it "should return multiple values", -> 65 it "should return multiple values", ->
66 fn -> 1, 2, 3 66 fn = -> 1, 2, 3
67 a, b, c = fn! 67 a, b, c = fn!
68 assert.same a, 1 68 assert.same a, 1
69 assert.same b, 2 69 assert.same b, 2
diff --git a/spec/inputs/test/string_spec.yue b/spec/inputs/test/string_spec.yue
index b790518..2afbb13 100644
--- a/spec/inputs/test/string_spec.yue
+++ b/spec/inputs/test/string_spec.yue
@@ -48,12 +48,12 @@ describe "string", ->
48 it "should not interpolate in single quotes", -> 48 it "should not interpolate in single quotes", ->
49 name = "world" 49 name = "world"
50 s = 'hello #{name}' 50 s = 'hello #{name}'
51 assert.same s, "hello #{name}" 51 assert.same s, "hello \#{name}"
52 52
53 it "should escape interpolation with \\#", -> 53 it "should escape interpolation with \\\#", ->
54 name = "world" 54 name = "world"
55 s = "hello \\#{name}" 55 s = "hello \#{name}"
56 assert.same s, "hello #{name}" 56 assert.same s, 'hello #{name}'
57 57
58 it "should support method calls on string literals", -> 58 it "should support method calls on string literals", ->
59 result = "hello"\upper! 59 result = "hello"\upper!
@@ -74,7 +74,7 @@ describe "string", ->
74 name = "test" 74 name = "test"
75 s = | 75 s = |
76 hello #{name} 76 hello #{name}
77 assert.same s, "hello test\n" 77 assert.same s, "hello test"
78 78
79 it "should support string concatenation", -> 79 it "should support string concatenation", ->
80 s = "hello" .. " " .. "world" 80 s = "hello" .. " " .. "world"
@@ -109,7 +109,7 @@ describe "string", ->
109 assert.is_true s\match("y: 20") ~= nil 109 assert.is_true s\match("y: 20") ~= nil
110 110
111 it "should support function call in interpolation", -> 111 it "should support function call in interpolation", ->
112 s = "result: #{-> 42}" 112 s = "result: #{(-> 42)!}"
113 assert.same s, "result: 42" 113 assert.same s, "result: 42"
114 114
115 it "should support table indexing in interpolation", -> 115 it "should support table indexing in interpolation", ->
diff --git a/spec/inputs/test/switch_spec.yue b/spec/inputs/test/switch_spec.yue
index 3696cbe..0865e5a 100644
--- a/spec/inputs/test/switch_spec.yue
+++ b/spec/inputs/test/switch_spec.yue
@@ -73,7 +73,7 @@ describe "switch", ->
73 a: b: :c 73 a: b: :c
74 x: y: :z 74 x: y: :z
75 } 75 }
76 matched = first == {} and one == 1 and two == 2 and three == 3 and c == 1 and z == 1 76 matched = type(first) == 'table' and one == 1 and two == 2 and three == 3 and c == 1 and z == 1
77 assert.is_true matched 77 assert.is_true matched
78 78
79 it "should destructure arrays with exact match", -> 79 it "should destructure arrays with exact match", ->
@@ -259,9 +259,9 @@ describe "switch", ->
259 assert.same result, "matched cool" 259 assert.same result, "matched cool"
260 260
261 it "should handle switch in function call", -> 261 it "should handle switch in function call", ->
262 something = 1
262 getValue = -> 263 getValue = ->
263 switch something 264 switch something
264 when 1 then "yes" 265 when 1 then "yes"
265 else "no" 266 else "no"
266 something = 1
267 assert.same getValue!, "yes" 267 assert.same getValue!, "yes"
diff --git a/spec/inputs/test/try_catch_spec.yue b/spec/inputs/test/try_catch_spec.yue
index ed8fef0..7447886 100644
--- a/spec/inputs/test/try_catch_spec.yue
+++ b/spec/inputs/test/try_catch_spec.yue
@@ -1,5 +1,6 @@
1describe "try/catch", -> 1describe "try/catch", ->
2 it "catch and rethrow", -> 2 it "catch and rethrow", ->
3 import global
3 ok, success, err = pcall -> 4 ok, success, err = pcall ->
4 try 5 try
5 error "boom" 6 error "boom"
diff --git a/spec/inputs/test/with_spec.yue b/spec/inputs/test/with_spec.yue
index c3b8428..70b50ee 100644
--- a/spec/inputs/test/with_spec.yue
+++ b/spec/inputs/test/with_spec.yue
@@ -3,13 +3,13 @@ describe "with", ->
3 obj = {value: 42} 3 obj = {value: 42}
4 with obj 4 with obj
5 result = .value 5 result = .value
6 assert.same result, 42 6 assert.same result, 42
7 7
8 it "should call method with : syntax", -> 8 it "should call method with : syntax", ->
9 obj = {func: -> "result"} 9 obj = {func: -> "result"}
10 with obj 10 with obj
11 result = \func! 11 result = \func!
12 assert.same result, "result" 12 assert.same result, "result"
13 13
14 it "should work as statement", -> 14 it "should work as statement", ->
15 obj = {x: 10, y: 20} 15 obj = {x: 10, y: 20}
@@ -21,20 +21,20 @@ describe "with", ->
21 outer = {inner: {value: 100}} 21 outer = {inner: {value: 100}}
22 with outer.inner 22 with outer.inner
23 result = .value 23 result = .value
24 assert.same result, 100 24 assert.same result, 100
25 25
26 it "should work with? safely", -> 26 it "should work with? safely", ->
27 obj = {x: 5} 27 obj = {x: 5}
28 with obj 28 with obj
29 result = .x 29 result = .x
30 assert.same result, 5 30 assert.same result, 5
31 31
32 it "should work with if inside with", -> 32 it "should work with if inside with", ->
33 obj = {x: 10, y: 20} 33 obj = {x: 10, y: 20}
34 with obj 34 with obj
35 if .x > 5 35 if .x > 5
36 result = .x + .y 36 result = .x + .y
37 assert.same result, 30 37 assert.same result, 30
38 38
39 it "should work with switch inside with", -> 39 it "should work with switch inside with", ->
40 obj = {type: "add", a: 5, b: 3} 40 obj = {type: "add", a: 5, b: 3}
@@ -42,7 +42,7 @@ describe "with", ->
42 result = switch .type 42 result = switch .type
43 when "add" then .a + .b 43 when "add" then .a + .b
44 else 0 44 else 0
45 assert.same result, 8 45 assert.same result, 8
46 46
47 it "should work with loop inside with", -> 47 it "should work with loop inside with", ->
48 obj = {items: {1, 2, 3}} 48 obj = {items: {1, 2, 3}}
@@ -54,11 +54,10 @@ describe "with", ->
54 54
55 it "should work with destructure", -> 55 it "should work with destructure", ->
56 obj = {x: 1, y: 2, z: 3} 56 obj = {x: 1, y: 2, z: 3}
57 with obj 57 with {:x, :y, :z} := obj
58 {x, y, z} = obj 58 assert.same x, 1
59 assert.same x, 1 59 assert.same y, 2
60 assert.same y, 2 60 assert.same z, 3
61 assert.same z, 3
62 61
63 it "should handle simple with body", -> 62 it "should handle simple with body", ->
64 obj = {value: 42} 63 obj = {value: 42}
@@ -87,7 +86,7 @@ describe "with", ->
87 obj = {a: {b: {c: 42}}} 86 obj = {a: {b: {c: 42}}}
88 with obj.a.b 87 with obj.a.b
89 result = .c 88 result = .c
90 assert.same result, 42 89 assert.same result, 42
91 90
92 it "should work with multiple statements", -> 91 it "should work with multiple statements", ->
93 obj = {x: 1, y: 2} 92 obj = {x: 1, y: 2}