diff options
Diffstat (limited to 'spec/inputs/test/with_statement_spec.yue')
| -rw-r--r-- | spec/inputs/test/with_statement_spec.yue | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/spec/inputs/test/with_statement_spec.yue b/spec/inputs/test/with_statement_spec.yue index c2f9b3b..71ac215 100644 --- a/spec/inputs/test/with_statement_spec.yue +++ b/spec/inputs/test/with_statement_spec.yue | |||
| @@ -27,7 +27,7 @@ describe "with statement", -> | |||
| 27 | obj = {x: 1} | 27 | obj = {x: 1} |
| 28 | with obj | 28 | with obj |
| 29 | .x = 10 | 29 | .x = 10 |
| 30 | with .nested = {y: 2} | 30 | with .nested := {y: 2} |
| 31 | .y = 20 | 31 | .y = 20 |
| 32 | assert.same obj.x, 10 | 32 | assert.same obj.x, 10 |
| 33 | assert.same obj.nested.y, 20 | 33 | assert.same obj.nested.y, 20 |
| @@ -35,7 +35,7 @@ describe "with statement", -> | |||
| 35 | it "should work in expressions", -> | 35 | it "should work in expressions", -> |
| 36 | obj = {value: 5} | 36 | obj = {value: 5} |
| 37 | result = with obj | 37 | result = with obj |
| 38 | .value * 2 | 38 | break .value * 2 |
| 39 | assert.same result, 10 | 39 | assert.same result, 10 |
| 40 | 40 | ||
| 41 | it "should support multiple statements", -> | 41 | it "should support multiple statements", -> |
| @@ -76,13 +76,13 @@ describe "with statement", -> | |||
| 76 | it "should support with in assignment", -> | 76 | it "should support with in assignment", -> |
| 77 | obj = {x: 5, y: 10} | 77 | obj = {x: 5, y: 10} |
| 78 | result = with obj | 78 | result = with obj |
| 79 | .x + .y | 79 | break .x + .y |
| 80 | assert.same result, 15 | 80 | assert.same result, 15 |
| 81 | 81 | ||
| 82 | it "should work with string methods", -> | 82 | it "should work with string methods", -> |
| 83 | s = "hello" | 83 | s = "hello" |
| 84 | result = with s | 84 | result = with s |
| 85 | \upper! | 85 | break \upper! |
| 86 | assert.same result, "HELLO" | 86 | assert.same result, "HELLO" |
| 87 | 87 | ||
| 88 | it "should handle metatable access", -> | 88 | it "should handle metatable access", -> |
| @@ -98,7 +98,7 @@ describe "with statement", -> | |||
| 98 | fn = -> | 98 | fn = -> |
| 99 | obj = {x: 10} | 99 | obj = {x: 10} |
| 100 | with obj | 100 | with obj |
| 101 | .x * 2 | 101 | break .x * 2 |
| 102 | 102 | ||
| 103 | result = fn! | 103 | result = fn! |
| 104 | assert.same result, 20 | 104 | assert.same result, 20 |
| @@ -107,19 +107,19 @@ describe "with statement", -> | |||
| 107 | get_value = -> | 107 | get_value = -> |
| 108 | obj = {value: 42} | 108 | obj = {value: 42} |
| 109 | with obj | 109 | with obj |
| 110 | .value | 110 | break .value |
| 111 | 111 | ||
| 112 | assert.same get_value!, 42 | 112 | assert.same get_value!, 42 |
| 113 | 113 | ||
| 114 | it "should work with existential operator", -> | 114 | it "should work with existential operator", -> |
| 115 | obj = {value: 10} | 115 | obj = {value: 10} |
| 116 | result = with obj | 116 | result = with obj |
| 117 | .value ? 0 | 117 | break .value ?? 0 |
| 118 | assert.same result, 10 | 118 | assert.same result, 10 |
| 119 | 119 | ||
| 120 | it "should handle nil object safely", -> | 120 | it "should handle nil object safely", -> |
| 121 | result = with nil | 121 | result = with? nil |
| 122 | .value | 122 | break .value |
| 123 | assert.same result, nil | 123 | assert.same result, nil |
| 124 | 124 | ||
| 125 | it "should work with method chaining", -> | 125 | it "should work with method chaining", -> |
| @@ -131,7 +131,7 @@ describe "with statement", -> | |||
| 131 | result = with obj | 131 | result = with obj |
| 132 | \add 10 | 132 | \add 10 |
| 133 | \add 5 | 133 | \add 5 |
| 134 | \get! | 134 | break \get! |
| 135 | assert.same result, 20 | 135 | assert.same result, 20 |
| 136 | 136 | ||
| 137 | it "should support nested property access", -> | 137 | it "should support nested property access", -> |
| @@ -141,5 +141,5 @@ describe "with statement", -> | |||
| 141 | level3: "deep" | 141 | level3: "deep" |
| 142 | 142 | ||
| 143 | result = with obj | 143 | result = with obj |
| 144 | .level1.level2.level3 | 144 | break .level1.level2.level3 |
| 145 | assert.same result, "deep" | 145 | assert.same result, "deep" |
