aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test/in_expression_spec.yue
diff options
context:
space:
mode:
Diffstat (limited to 'spec/inputs/test/in_expression_spec.yue')
-rw-r--r--spec/inputs/test/in_expression_spec.yue94
1 files changed, 94 insertions, 0 deletions
diff --git a/spec/inputs/test/in_expression_spec.yue b/spec/inputs/test/in_expression_spec.yue
new file mode 100644
index 0000000..c1f4099
--- /dev/null
+++ b/spec/inputs/test/in_expression_spec.yue
@@ -0,0 +1,94 @@
1describe "in expression", ->
2 it "should check value in table", ->
3 items = {1, 2, 3, 4, 5}
4 assert.is_true 3 in items
5 assert.is_false 10 in items
6
7 it "should work with strings", ->
8 chars = {"a", "b", "c"}
9 assert.is_true "b" in chars
10 assert.is_false "z" in chars
11
12 it "should check keys in table", ->
13 obj = {x: 1, y: 2, z: 3}
14 assert.is_true "x" in obj
15 assert.is_true "y" in obj
16 assert.is_false "w" in obj
17
18 it "should work with mixed types", ->
19 items = {1, "two", true, nil}
20 assert.is_true 1 in items
21 assert.is_true "two" in items
22 assert.is_true true in items
23 assert.is_false false in items
24
25 it "should handle empty table", ->
26 empty = {}
27 assert.is_false 1 in empty
28 assert.is_false "test" in empty
29
30 it "should work in conditional", ->
31 items = {1, 2, 3}
32 result = if 2 in items
33 "found"
34 else
35 "not found"
36 assert.same result, "found"
37
38 it "should support negation", ->
39 items = {1, 2, 3}
40 assert.is_true not (4 in items)
41 assert.is_false not (2 in items)
42
43 it "should work with nested tables", ->
44 nested = {{1, 2}, {3, 4}, {5, 6}}
45 assert.is_true {1, 2} in nested
46 assert.is_false {1, 3} in nested
47
48 it "should handle boolean values", ->
49 bools = {true, false}
50 assert.is_true true in bools
51 assert.is_true false in bools
52
53 it "should work in loop", ->
54 items = {1, 2, 3, 4, 5}
55 count = 0
56 for i = 1, 10
57 count += 1 if i in items
58 assert.same count, 5
59
60 it "should support table as value", ->
61 key1 = {a: 1}
62 key2 = {b: 2}
63 tb = {[key1]: "first", [key2]: "second"}
64
65 -- Note: this tests table reference equality
66 assert.is_true key1 in tb
67 assert.is_true key2 in tb
68
69 it "should work with function results", ->
70 get_items = -> {1, 2, 3}
71 assert.is_true 2 in get_items!
72 assert.is_false 5 in get_items!
73
74 it "should handle nil in table", ->
75 items = {1, nil, 3}
76 assert.is_true nil in items
77 assert.is_true 1 in items
78
79 it "should work with string keys", ->
80 obj = {name: "test", value: 42}
81 assert.is_true "name" in obj
82 assert.is_true "value" in obj
83 assert.is_false "missing" in obj
84
85 it "should support complex expressions", ->
86 items = {1, 2, 3}
87 result = (2 in items) and "yes" or "no"
88 assert.same result, "yes"
89
90 it "should work in comprehension", ->
91 source = {1, 2, 3, 4, 5}
92 allowed = {2, 4}
93 result = [item for item in *source when item in allowed]
94 assert.same result, {2, 4}