aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/test/advanced_macro_spec.lua
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-01-28 18:43:14 +0800
committerLi Jin <dragon-fly@qq.com>2026-01-28 18:43:14 +0800
commitdd64edd58fe25ec74ae5958128cf3f74b0692f3b (patch)
tree0f2de1df55897e2713977c5a53936757e14b477a /spec/outputs/test/advanced_macro_spec.lua
parent7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (diff)
downloadyuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.gz
yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.bz2
yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.zip
Fixed compiler issues and added 800+ test cases.
Diffstat (limited to 'spec/outputs/test/advanced_macro_spec.lua')
-rw-r--r--spec/outputs/test/advanced_macro_spec.lua92
1 files changed, 92 insertions, 0 deletions
diff --git a/spec/outputs/test/advanced_macro_spec.lua b/spec/outputs/test/advanced_macro_spec.lua
new file mode 100644
index 0000000..0a46978
--- /dev/null
+++ b/spec/outputs/test/advanced_macro_spec.lua
@@ -0,0 +1,92 @@
1return describe("advanced macro", function()
2 it("should evaluate macro at compile time", function()
3 local area = 6.2831853071796 * 5
4 return assert.is_true(area > 0)
5 end)
6 it("should support macro with arguments", function()
7 local result = (5 + 10)
8 return assert.same(result, 15)
9 end)
10 it("should handle string returning macro", function()
11 local result = 'hello world'
12 return assert.same(result, "hello world")
13 end)
14 it("should work with conditional compilation", function()
15 debugMode = true
16 assert.is_true(debugMode)
17 return assert.is_true(debugMode)
18 end)
19 it("should support macro generating conditional code", function()
20 debugMode = true
21 local x = 10
22 return assert.same(x, 10)
23 end)
24 it("should work with lua code insertion", function()
25 local macro_test_var = 42
26 do
27local macro_test_var = 99
28 end
29 return assert.same(macro_test_var, 42)
30 end)
31 it("should support multi-line raw lua", function()
32 local multiline_var = "test"
33multiline_var = "test work"
34 local multiline_var1 = "test1"
35 assert.same(multiline_var, "test work")
36 return assert.same(multiline_var1, "test1")
37 end)
38 it("should export macro from module", function()
39 local result = (5 * 2)
40 return assert.same(result, 10)
41 end)
42 it("should work with builtin FILE macro", function()
43 local result = "./spec/inputs/test/advanced_macro_spec.yue"
44 return assert.is_true(type(result) == "string")
45 end)
46 it("should work with builtin LINE macro", function()
47 local result = 82
48 return assert.is_true(type(result) == "number")
49 end)
50 it("should support argument validation", function()
51 local result = 123
52 return assert.same(result, 123)
53 end)
54 it("should handle string argument validation", function()
55 local result = "hello"
56 return assert.same(result, "hello")
57 end)
58 it("should work with is_ast check", function()
59 local result = (10 + 20)
60 return assert.same(result, 30)
61 end)
62 it("should support macro generating macro", function()
63 local result = "Red"
64 return assert.same(result, "Red")
65 end)
66 it("should handle complex macro logic", function()
67 local my_print
68 my_print = function(...)
69 return ...
70 end
71 local a, b, c = my_print("hello", "world", 123)
72 assert.same(a, "hello")
73 assert.same(b, "world")
74 return assert.same(c, 123)
75 end)
76 it("should work with table manipulation", function()
77 local result = {
78 "1",
79 "2",
80 "3"
81 }
82 return assert.same(result, {
83 "1",
84 "2",
85 "3"
86 })
87 end)
88 return it("should support string concatenation in macro", function()
89 local result = ("hello" .. "world")
90 return assert.same(result, "helloworld")
91 end)
92end)