aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test/implicit_object_spec.yue
diff options
context:
space:
mode:
Diffstat (limited to 'spec/inputs/test/implicit_object_spec.yue')
-rw-r--r--spec/inputs/test/implicit_object_spec.yue164
1 files changed, 164 insertions, 0 deletions
diff --git a/spec/inputs/test/implicit_object_spec.yue b/spec/inputs/test/implicit_object_spec.yue
new file mode 100644
index 0000000..cea926e
--- /dev/null
+++ b/spec/inputs/test/implicit_object_spec.yue
@@ -0,0 +1,164 @@
1describe "implicit object", ->
2 it "should create list with asterisk", ->
3 list =
4 * 1
5 * 2
6 * 3
7 assert.same list, {1, 2, 3}
8
9 it "should create list with dash", ->
10 items =
11 - "a"
12 - "b"
13 - "c"
14 assert.same items, {"a", "b", "c"}
15
16 it "should work with function call", ->
17 results = []
18 fn =
19 * 1
20 * 2
21 * 3
22
23 for item in *fn
24 table.insert results, item
25
26 assert.same results, {1, 2, 3}
27
28 it "should support nested implicit objects", ->
29 tb =
30 name: "test"
31
32 values:
33 - "a"
34 - "b"
35 - "c"
36
37 objects:
38 - name: "first"
39 value: 1
40 - name: "second"
41 value: 2
42
43 assert.same tb.values, {"a", "b", "c"}
44 assert.same tb.objects[1].name, "first"
45 assert.same tb.objects[2].value, 2
46
47 it "should work with return statement", ->
48 fn = ->
49 return
50 * 1
51 * 2
52 * 3
53
54 assert.same fn!, {1, 2, 3}
55
56 it "should handle mixed content", ->
57 tb =
58 key: "value"
59
60 items:
61 - 1
62 - 2
63
64 other: "data"
65
66 assert.same tb.key, "value"
67 assert.same tb.items, {1, 2}
68 assert.same tb.other, "data"
69
70 it "should work in assignment", ->
71 list =
72 * "x"
73 * "y"
74 * "z"
75
76 assert.same list, {"x", "y", "z"}
77
78 it "should support nested structures with asterisk", ->
79 tb =
80 * 1
81 * 2
82 nested:
83 * 3
84 * 4
85
86 assert.same tb[1], 1
87 assert.same tb[2], 2
88 assert.same tb.nested, {3, 4}
89
90 it "should handle implicit object in tables", ->
91 tb = {
92 name: "test"
93
94 list:
95 - 1
96 - 2
97
98 value: 42
99 }
100
101 assert.same tb.list, {1, 2}
102
103 it "should work with expressions", ->
104 x = 10
105 list =
106 * x + 1
107 * x + 2
108 * x + 3
109
110 assert.same list, {11, 12, 13}
111
112 it "should support method calls in implicit object", ->
113 tb =
114 name: "test"
115 items:
116 - name: "item1"
117 getName: => @name
118 - name: "item2"
119 getName: => @name
120
121 assert.same tb.items[1]\getName!, "item1"
122 assert.same tb.items[2]\getName!, "item2"
123
124 it "should work with complex nested structures", ->
125 config =
126 database:
127 host: "localhost"
128 ports:
129 - 8080
130 - 8081
131 - 8082
132
133 servers:
134 - name: "server1"
135 port: 8080
136 - name: "server2"
137 port: 8081
138
139 assert.same config.database.ports, {8080, 8081, 8082}
140 assert.same config.servers[1].name, "server1"
141
142 it "should handle empty implicit object", ->
143 tb =
144 items:
145 -
146
147 assert.same tb.items, {nil}
148
149 it "should work in function arguments", ->
150 fn = (items) -> #items
151 result = fn
152 * 1
153 * 2
154 * 3
155 assert.same result, 3
156
157 it "should support mixed asterisk and dash", ->
158 tb =
159 values:
160 * 1
161 - 2
162 * 3
163
164 assert.same tb.values, {1, 2, 3}