summaryrefslogtreecommitdiff
path: root/spec/inputs/test/const_attribute_spec.yue
blob: 24ced21df56563a0f8590731dfffe213b052a661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
describe "const attribute", ->
	it "should declare const variable", ->
		const a = 123
		assert.same a, 123

	it "should prevent reassignment", ->
		const b = 456
		-- b = 789  -- This should cause error
		assert.same b, 456

	it "should work with strings", ->
		const name = "test"
		assert.same name, "test"

	it "should support const with destructuring", ->
		tb = {a: 1, b: 2, 3, 4}
		const {:a, :b, c, d} = tb
		assert.same a, 1
		assert.same b, 2
		assert.same c, 3
		assert.same d, 4

	it "should handle nested const", ->
		const nested = {
			inner: {value: 10}
		}
		assert.same nested.inner.value, 10

	it "should work with arrays", ->
		const items = [1, 2, 3]
		assert.same items[1], 1

	it "should support const in function scope", ->
		fn = ->
			const local_const = "local"
			local_const

		result = fn!
		assert.same result, "local"

	it "should work with multiple const declarations", ->
		const x = 1
		const y = 2
		const z = 3
		assert.same x + y + z, 6

	it "should handle const functions", ->
		const add = (a, b) -> a + b
		assert.same add(5, 10), 15

	it "should work with const tables", ->
		const config = {
			host: "localhost"
			port: 8080
		}
		assert.same config.host, "localhost"
		assert.same config.port, 8080

	it "should support global const", ->
		global const GLOBAL_CONST = 999
		assert.same GLOBAL_CONST, 999

	it "should work with boolean const", ->
		const flag = true
		const another = false
		assert.is_true flag
		assert.is_false another

	it "should handle nil const", ->
		const nil_value = nil
		assert.same nil_value, nil

	it "should work with expressions", ->
		const calculated = 10 + 20
		assert.same calculated, 30

	it "should work in table comprehension", ->
		const multiplier = 2
		items = [1, 2, 3]
		result = [item * multiplier for item in *items]
		assert.same result, {2, 4, 6}

	it "should work with complex expressions", ->
		const complex = {
			data: [1, 2, 3]
			nested: {
				key: "value"
			}
		}
		assert.same complex.data[1], 1
		assert.same complex.nested.key, "value"