diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-28 18:43:14 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-28 18:43:14 +0800 |
| commit | dd64edd58fe25ec74ae5958128cf3f74b0692f3b (patch) | |
| tree | 0f2de1df55897e2713977c5a53936757e14b477a /spec/inputs/test/in_expression_spec.yue | |
| parent | 7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (diff) | |
| download | yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.gz yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.tar.bz2 yuescript-dd64edd58fe25ec74ae5958128cf3f74b0692f3b.zip | |
Fixed compiler issues and added 800+ test cases.
Diffstat (limited to 'spec/inputs/test/in_expression_spec.yue')
| -rw-r--r-- | spec/inputs/test/in_expression_spec.yue | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/spec/inputs/test/in_expression_spec.yue b/spec/inputs/test/in_expression_spec.yue index c1f4099..d9e3aec 100644 --- a/spec/inputs/test/in_expression_spec.yue +++ b/spec/inputs/test/in_expression_spec.yue | |||
| @@ -9,11 +9,11 @@ describe "in expression", -> | |||
| 9 | assert.is_true "b" in chars | 9 | assert.is_true "b" in chars |
| 10 | assert.is_false "z" in chars | 10 | assert.is_false "z" in chars |
| 11 | 11 | ||
| 12 | it "should check keys in table", -> | 12 | it "should check in table literal", -> |
| 13 | obj = {x: 1, y: 2, z: 3} | 13 | x = 1; y = 2; z = 3; w = 4 |
| 14 | assert.is_true "x" in obj | 14 | assert.is_true x in [x, y, z] |
| 15 | assert.is_true "y" in obj | 15 | assert.is_true y in [x, y, z] |
| 16 | assert.is_false "w" in obj | 16 | assert.is_false w in [x, y, z] |
| 17 | 17 | ||
| 18 | it "should work with mixed types", -> | 18 | it "should work with mixed types", -> |
| 19 | items = {1, "two", true, nil} | 19 | items = {1, "two", true, nil} |
| @@ -41,7 +41,8 @@ describe "in expression", -> | |||
| 41 | assert.is_false not (2 in items) | 41 | assert.is_false not (2 in items) |
| 42 | 42 | ||
| 43 | it "should work with nested tables", -> | 43 | it "should work with nested tables", -> |
| 44 | nested = {{1, 2}, {3, 4}, {5, 6}} | 44 | eq = (other) => @[1] == other[1] and @[2] == other[2] |
| 45 | nested = {{1, 2, :<eq>}, {3, 4, :<eq>}, {5, 6, :<eq>}} | ||
| 45 | assert.is_true {1, 2} in nested | 46 | assert.is_true {1, 2} in nested |
| 46 | assert.is_false {1, 3} in nested | 47 | assert.is_false {1, 3} in nested |
| 47 | 48 | ||
| @@ -60,7 +61,7 @@ describe "in expression", -> | |||
| 60 | it "should support table as value", -> | 61 | it "should support table as value", -> |
| 61 | key1 = {a: 1} | 62 | key1 = {a: 1} |
| 62 | key2 = {b: 2} | 63 | key2 = {b: 2} |
| 63 | tb = {[key1]: "first", [key2]: "second"} | 64 | tb = [key1, key2] |
| 64 | 65 | ||
| 65 | -- Note: this tests table reference equality | 66 | -- Note: this tests table reference equality |
| 66 | assert.is_true key1 in tb | 67 | assert.is_true key1 in tb |
| @@ -77,7 +78,7 @@ describe "in expression", -> | |||
| 77 | assert.is_true 1 in items | 78 | assert.is_true 1 in items |
| 78 | 79 | ||
| 79 | it "should work with string keys", -> | 80 | it "should work with string keys", -> |
| 80 | obj = {name: "test", value: 42} | 81 | obj = ["name", "value"] |
| 81 | assert.is_true "name" in obj | 82 | assert.is_true "name" in obj |
| 82 | assert.is_true "value" in obj | 83 | assert.is_true "value" in obj |
| 83 | assert.is_false "missing" in obj | 84 | assert.is_false "missing" in obj |
