aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test/const_attribute_spec.yue
diff options
context:
space:
mode:
Diffstat (limited to 'spec/inputs/test/const_attribute_spec.yue')
-rw-r--r--spec/inputs/test/const_attribute_spec.yue107
1 files changed, 107 insertions, 0 deletions
diff --git a/spec/inputs/test/const_attribute_spec.yue b/spec/inputs/test/const_attribute_spec.yue
new file mode 100644
index 0000000..e3cc638
--- /dev/null
+++ b/spec/inputs/test/const_attribute_spec.yue
@@ -0,0 +1,107 @@
1describe "const attribute", ->
2 it "should declare const variable", ->
3 const a = 123
4 assert.same a, 123
5
6 it "should prevent reassignment", ->
7 const b = 456
8 -- b = 789 -- This should cause error
9 assert.same b, 456
10
11 it "should work with strings", ->
12 const name = "test"
13 assert.same name, "test"
14
15 it "should support const with destructuring", ->
16 tb = {a: 1, b: 2, c: 3, d: 4}
17 const {:a, :b, c, d} = tb
18 assert.same a, 1
19 assert.same b, 2
20 assert.same c, 3
21 assert.same d, 4
22
23 it "should handle nested const", ->
24 const nested = {
25 inner: {value: 10}
26 }
27 assert.same nested.inner.value, 10
28
29 it "should work with arrays", ->
30 const items = [1, 2, 3]
31 assert.same items[1], 1
32
33 it "should support const in function scope", ->
34 fn = ->
35 const local_const = "local"
36 local_const
37
38 result = fn!
39 assert.same result, "local"
40
41 it "should work with multiple const declarations", ->
42 const x = 1
43 const y = 2
44 const z = 3
45 assert.same x + y + z, 6
46
47 it "should handle const functions", ->
48 const add = (a, b) -> a + b
49 assert.same add 5, 10, 15
50
51 it "should work with const tables", ->
52 const config = {
53 host: "localhost"
54 port: 8080
55 }
56 assert.same config.host, "localhost"
57 assert.same config.port, 8080
58
59 it "should support global const", ->
60 global const GLOBAL_CONST = 999
61 assert.same GLOBAL_CONST, 999
62
63 it "should work with boolean const", ->
64 const flag = true
65 const another = false
66 assert.is_true flag
67 assert.is_false another
68
69 it "should handle nil const", ->
70 const nil_value = nil
71 assert.same nil_value, nil
72
73 it "should work with expressions", ->
74 const calculated = 10 + 20
75 assert.same calculated, 30
76
77 it "should support const with prefixed return", ->
78 getDefault: const "default" ->
79 return nil
80
81 result = getDefault!
82 assert.same result, nil
83
84 it "should work in table comprehension", ->
85 const multiplier = 2
86 items = [1, 2, 3]
87 result = [item * multiplier for item in *items]
88 assert.same result, {2, 4, 6}
89
90 it "should handle const with fat arrow", ->
91 obj =
92 value: 100
93 getValue: const =>
94 @value
95
96 result = obj\getValue!
97 assert.same result, 100
98
99 it "should work with complex expressions", ->
100 const complex = {
101 data: [1, 2, 3]
102 nested: {
103 key: "value"
104 }
105 }
106 assert.same complex.data[1], 1
107 assert.same complex.nested.key, "value"