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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
describe "operators", ->
it "should support addition", ->
assert.same 1 + 2, 3
it "should support subtraction", ->
assert.same 5 - 3, 2
it "should support multiplication", ->
assert.same 4 * 3, 12
it "should support division", ->
assert.same 10 / 2, 5
it "should support modulo", ->
assert.same 10 % 3, 1
it "should support exponentiation", ->
assert.same 2 ^ 3, 8
it "should support unary minus", ->
assert.same -5, -5
it "should support equality comparison", ->
assert.is_true 1 == 1
assert.is_false 1 == 2
it "should support inequality comparison", ->
assert.is_true 1 ~= 2
assert.is_false 1 ~= 1
it "should support less than", ->
assert.is_true 1 < 2
assert.is_false 2 < 1
it "should support greater than", ->
assert.is_true 2 > 1
assert.is_false 1 > 2
it "should support less than or equal", ->
assert.is_true 1 <= 2
assert.is_true 2 <= 2
assert.is_false 3 <= 2
it "should support greater than or equal", ->
assert.is_true 2 >= 1
assert.is_true 2 >= 2
assert.is_false 1 >= 2
it "should support logical and", ->
assert.same true and false, false
assert.same true and true, true
assert.same false and true, false
it "should support logical or", ->
assert.same true or false, true
assert.same false or true, true
assert.same false or false, false
it "should support logical not", ->
assert.same not true, false
assert.same not false, true
assert.same not nil, true
it "should support bitwise and", ->
assert.same 5 & 3, 1 -- 101 & 011 = 001
it "should support bitwise or", ->
assert.same 5 | 3, 7 -- 101 | 011 = 111
it "should support bitwise xor", ->
assert.same 5 ~ 3, 6 -- 101 ~ 011 = 110
it "should support left shift", ->
assert.same 2 << 3, 16
it "should support right shift", ->
assert.same 16 >> 2, 4
it "should support string concatenation", ->
assert.same "hello" .. " world", "hello world"
it "should support length operator", ->
assert.same #"hello", 5
assert.same #{1, 2, 3}, 3
it "should respect operator precedence", ->
assert.same 1 + 2 * 3, 7 -- multiplication before addition
assert.same (1 + 2) * 3, 9 -- parentheses first
it "should support compound assignment", ->
x = 10
x += 5
assert.same x, 15
it "should support compound subtraction", ->
x = 10
x -= 3
assert.same x, 7
it "should support compound multiplication", ->
x = 5
x *= 2
assert.same x, 10
it "should support compound division", ->
x = 20
x /= 4
assert.same x, 5
it "should handle division by zero", ->
-- Lua returns inf or nan
result = pcall(->
x = 10 / 0
)
assert.is_true result -- doesn't error in Lua
it "should handle very large numbers", ->
big = 1e100
assert.is_true big > 0
it "should handle very small numbers", ->
small = 1e-100
assert.is_true small > 0
it "should support negation", ->
assert.same -10, -10
assert.same --5, 5
it "should work with complex expressions", ->
result = (1 + 2) * (3 + 4) / 2
assert.same result, 10.5
it "should support power with decimal", ->
assert.same 4 ^ 0.5, 2
it "should handle modulo with negative numbers", ->
assert.same -10 % 3, 2 -- Lua's modulo behavior
|