diff options
Diffstat (limited to 'spec/inputs/test/whitespace_spec.yue')
| -rw-r--r-- | spec/inputs/test/whitespace_spec.yue | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/spec/inputs/test/whitespace_spec.yue b/spec/inputs/test/whitespace_spec.yue new file mode 100644 index 0000000..baf3fd5 --- /dev/null +++ b/spec/inputs/test/whitespace_spec.yue | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | describe "whitespace", -> | ||
| 2 | it "should support semicolon statement separator", -> | ||
| 3 | a = 1; b = 2; result = a + b | ||
| 4 | assert.same result, 3 | ||
| 5 | |||
| 6 | it "should handle multiple statements on one line", -> | ||
| 7 | x = 10; y = 20; z = x + y | ||
| 8 | assert.same z, 30 | ||
| 9 | |||
| 10 | it "should work with semicolon in function", -> | ||
| 11 | fn = -> a = 1; b = 2; a + b | ||
| 12 | assert.same fn!, 3 | ||
| 13 | |||
| 14 | it "should support multiline chaining", -> | ||
| 15 | obj = | ||
| 16 | value: 10 | ||
| 17 | add: (n) => @value += n | ||
| 18 | get: => @value | ||
| 19 | |||
| 20 | result = obj | ||
| 21 | \add 5 | ||
| 22 | \add 10 | ||
| 23 | \get! | ||
| 24 | assert.same result, 25 | ||
| 25 | |||
| 26 | it "should handle multiline method calls", -> | ||
| 27 | str = " hello " | ||
| 28 | result = str | ||
| 29 | \trim! | ||
| 30 | \upper! | ||
| 31 | assert.same result, "HELLO" | ||
| 32 | |||
| 33 | it "should work with nested chaining", -> | ||
| 34 | obj = | ||
| 35 | level1: | ||
| 36 | level2: | ||
| 37 | level3: => "deep" | ||
| 38 | |||
| 39 | result = obj | ||
| 40 | .level1 | ||
| 41 | .level2 | ||
| 42 | \level3! | ||
| 43 | assert.same result, "deep" | ||
| 44 | |||
| 45 | it "should support chaining with conditionals", -> | ||
| 46 | obj = | ||
| 47 | value: 10 | ||
| 48 | isPositive: => @value > 0 | ||
| 49 | |||
| 50 | result = obj | ||
| 51 | \isPositive! | ||
| 52 | assert.is_true result | ||
| 53 | |||
| 54 | it "should work with pipe in chaining", -> | ||
| 55 | result = [1, 2, 3] | ||
| 56 | |> [x * 2 for x in *] | ||
| 57 | |> table.concat | ||
| 58 | assert.same result, "246" | ||
| 59 | |||
| 60 | it "should handle mixed separators", -> | ||
| 61 | a = 1; b = 2 | ||
| 62 | c = 3 | ||
| 63 | d = 4 | ||
| 64 | result = a + b + c + d | ||
| 65 | assert.same result, 10 | ||
| 66 | |||
| 67 | it "should support indentation with spaces", -> | ||
| 68 | fn = -> | ||
| 69 | if true | ||
| 70 | result = 10 | ||
| 71 | result | ||
| 72 | |||
| 73 | assert.same fn!, 10 | ||
| 74 | |||
| 75 | it "should work with consistent indentation", -> | ||
| 76 | tb = { | ||
| 77 | a: 1 | ||
| 78 | b: 2 | ||
| 79 | nested: | ||
| 80 | c: 3 | ||
| 81 | d: 4 | ||
| 82 | } | ||
| 83 | assert.same tb.a, 1 | ||
| 84 | assert.same tb.nested.c, 3 | ||
| 85 | |||
| 86 | it "should handle semicolon with comments", -> | ||
| 87 | a = 1; -- comment | ||
| 88 | b = 2; -- another comment | ||
| 89 | result = a + b | ||
| 90 | assert.same result, 3 | ||
| 91 | |||
| 92 | it "should work in multiline function call", -> | ||
| 93 | sum = (a, b) -> a + b | ||
| 94 | result = sum 5, 10, | ||
| 95 | sum 3, 7 | ||
| 96 | assert.same result, 25 | ||
| 97 | |||
| 98 | it "should support chaining in assignment", -> | ||
| 99 | obj = | ||
| 100 | value: 5 | ||
| 101 | double: => @value * 2 | ||
| 102 | |||
| 103 | doubled = obj | ||
| 104 | \double! | ||
| 105 | assert.same doubled, 10 | ||
| 106 | |||
| 107 | it "should handle complex chaining", -> | ||
| 108 | result = "hello" | ||
| 109 | \upper! | ||
| 110 | \sub 1, 3 | ||
| 111 | \lower! | ||
| 112 | assert.same result, "hel" | ||
| 113 | |||
| 114 | it "should work with backcalls and whitespace", -> | ||
| 115 | results = do | ||
| 116 | data <- readAsync "data.txt" | ||
| 117 | process data | ||
| 118 | assert.is_true true | ||
