aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test/advanced_macro_spec.yue
diff options
context:
space:
mode:
Diffstat (limited to 'spec/inputs/test/advanced_macro_spec.yue')
-rw-r--r--spec/inputs/test/advanced_macro_spec.yue36
1 files changed, 21 insertions, 15 deletions
diff --git a/spec/inputs/test/advanced_macro_spec.yue b/spec/inputs/test/advanced_macro_spec.yue
index 3d7b10a..d88807f 100644
--- a/spec/inputs/test/advanced_macro_spec.yue
+++ b/spec/inputs/test/advanced_macro_spec.yue
@@ -15,7 +15,10 @@ describe "advanced macro", ->
15 assert.same result, "hello world" 15 assert.same result, "hello world"
16 16
17 it "should work with conditional compilation", -> 17 it "should work with conditional compilation", ->
18 global debugMode = true
19 $ -> global debugMode = true
18 macro config = (debugging) -> 20 macro config = (debugging) ->
21 assert debugMode?
19 global debugMode = debugging == "true" 22 global debugMode = debugging == "true"
20 "" 23 ""
21 24
@@ -23,7 +26,7 @@ describe "advanced macro", ->
23 assert.is_true debugMode 26 assert.is_true debugMode
24 27
25 $config false 28 $config false
26 assert.is_false debugMode 29 assert.is_true debugMode
27 30
28 it "should support macro generating conditional code", -> 31 it "should support macro generating conditional code", ->
29 macro asserts = (cond) -> 32 macro asserts = (cond) ->
@@ -39,20 +42,24 @@ describe "advanced macro", ->
39 :code 42 :code
40 type: "lua" 43 type: "lua"
41 } 44 }
42 45 macro_test_var = 42
43 $luaCode "local macro_test_var = 42" 46 $luaCode [[local macro_test_var = 99]]
44 assert.same macro_test_var, 42 47 assert.same macro_test_var, 42
45 48
46 it "should support multi-line raw lua", -> 49 it "should support multi-line raw lua", ->
47 macro lua = (code) -> { 50 macro lua = (code) -> {
48 :code 51 :code
49 type: "lua" 52 type: "text"
53 locals: ["multiline_var1",]
50 } 54 }
51 55
56 multiline_var = "test"
52 $lua[==[ 57 $lua[==[
53 local multiline_var = "test" 58 multiline_var = "test work"
59 local multiline_var1 = "test1"
54 ]==] 60 ]==]
55 assert.same multiline_var, "test" 61 assert.same multiline_var, "test work"
62 assert.same multiline_var1, "test1"
56 63
57 it "should export macro from module", -> 64 it "should export macro from module", ->
58 -- This test demonstrates macro export syntax 65 -- This test demonstrates macro export syntax
@@ -116,10 +123,14 @@ describe "advanced macro", ->
116 assert.same result, "Red" 123 assert.same result, "Red"
117 124
118 it "should handle complex macro logic", -> 125 it "should handle complex macro logic", ->
119 macro smart_print = (items) -> 126 my_print = (...) -> ...
120 "print(#{table.concat [item for item in *items], ', ')})" 127 macro smart_print = (...items) ->
128 "my_print(#{table.concat [item for item in *items], ', '})"
121 129
122 $smart_print {"hello", "world", 123} 130 a, b, c = $smart_print "hello", "world", 123
131 assert.same a, "hello"
132 assert.same b, "world"
133 assert.same c, 123
123 134
124 it "should work with table manipulation", -> 135 it "should work with table manipulation", ->
125 macro create_table = (...) -> 136 macro create_table = (...) ->
@@ -130,12 +141,7 @@ describe "advanced macro", ->
130 assert.same result, {"1", "2", "3"} 141 assert.same result, {"1", "2", "3"}
131 142
132 it "should support string concatenation in macro", -> 143 it "should support string concatenation in macro", ->
133 macro concat = (...) -> 144 macro concat = (...) -> table.concat {...}, " .. "
134 args = {...}
135 res = {}
136 for arg in *args
137 table.insert res, tostring arg
138 "'" .. table.concat(res, " .. ") .. "'"
139 145
140 result = $concat "hello", "world" 146 result = $concat "hello", "world"
141 assert.same result, "helloworld" 147 assert.same result, "helloworld"