diff options
Diffstat (limited to 'spec/outputs/test/chaining_comparison_spec.lua')
| -rw-r--r-- | spec/outputs/test/chaining_comparison_spec.lua | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/spec/outputs/test/chaining_comparison_spec.lua b/spec/outputs/test/chaining_comparison_spec.lua new file mode 100644 index 0000000..fe61fae --- /dev/null +++ b/spec/outputs/test/chaining_comparison_spec.lua | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | local _anon_func_0 = function() | ||
| 2 | local _cond_0 = "b" | ||
| 3 | if not ("a" < _cond_0) then | ||
| 4 | return false | ||
| 5 | else | ||
| 6 | return _cond_0 < "c" | ||
| 7 | end | ||
| 8 | end | ||
| 9 | local _anon_func_1 = function() | ||
| 10 | local _cond_0 = "b" | ||
| 11 | if not ("a" <= _cond_0) then | ||
| 12 | return false | ||
| 13 | else | ||
| 14 | return _cond_0 <= "c" | ||
| 15 | end | ||
| 16 | end | ||
| 17 | local _anon_func_2 = function(v) | ||
| 18 | local _cond_0 = v(2) | ||
| 19 | if not (v(1) < _cond_0) then | ||
| 20 | return false | ||
| 21 | else | ||
| 22 | return _cond_0 < v(3) | ||
| 23 | end | ||
| 24 | end | ||
| 25 | return describe("chaining comparison", function() | ||
| 26 | it("should support simple chaining", function() | ||
| 27 | assert.is_true(1 < 2 and 2 < 3) | ||
| 28 | assert.is_true(1 <= 2 and 2 <= 3) | ||
| 29 | assert.is_true(3 > 2 and 2 > 1) | ||
| 30 | return assert.is_true(3 >= 2 and 2 >= 1) | ||
| 31 | end) | ||
| 32 | it("should support complex chaining", function() | ||
| 33 | return assert.is_true(1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5) | ||
| 34 | end) | ||
| 35 | it("should work with variables", function() | ||
| 36 | local a = 5 | ||
| 37 | assert.is_true(1 <= a and a <= 10) | ||
| 38 | assert.is_true(a >= 3) | ||
| 39 | return assert.is_true(a <= 10) | ||
| 40 | end) | ||
| 41 | it("should handle mixed comparisons", function() | ||
| 42 | local x = 5 | ||
| 43 | assert.is_true(1 < x and x < 10) | ||
| 44 | return assert.is_true(1 <= x and x <= 5) | ||
| 45 | end) | ||
| 46 | it("should work with string comparisons", function() | ||
| 47 | assert.is_true(_anon_func_0()) | ||
| 48 | return assert.is_true(_anon_func_1()) | ||
| 49 | end) | ||
| 50 | it("should handle edge cases", function() | ||
| 51 | assert.is_true(0 <= 0 and 0 <= 0) | ||
| 52 | return assert.is_true(-5 < 0 and 0 < 5) | ||
| 53 | end) | ||
| 54 | it("should work in expressions", function() | ||
| 55 | local result | ||
| 56 | if 1 < 2 and 2 < 3 then | ||
| 57 | result = "yes" | ||
| 58 | else | ||
| 59 | result = "no" | ||
| 60 | end | ||
| 61 | return assert.same(result, "yes") | ||
| 62 | end) | ||
| 63 | it("should support != operator", function() | ||
| 64 | assert.is_true(1 ~= 2 and 2 ~= 3) | ||
| 65 | return assert.is_true(1 ~= 2 and 2 ~= 3) | ||
| 66 | end) | ||
| 67 | it("should handle boolean results", function() | ||
| 68 | assert.is_true(1 < 2 and 2 < 3) | ||
| 69 | return assert.is_false(3 < 2 and 2 < 1) | ||
| 70 | end) | ||
| 71 | it("should work with function calls", function() | ||
| 72 | local v | ||
| 73 | v = function(x) | ||
| 74 | return x | ||
| 75 | end | ||
| 76 | return assert.is_true(_anon_func_2(v)) | ||
| 77 | end) | ||
| 78 | it("should handle negation", function() | ||
| 79 | return assert.is_true(-10 < -5 and -5 < 0) | ||
| 80 | end) | ||
| 81 | return it("should support mixed operators", function() | ||
| 82 | assert.is_true(1 < 2 and 2 <= 2 and 2 < 3) | ||
| 83 | return assert.is_true(3 > 2 and 2 >= 2 and 2 > 1) | ||
| 84 | end) | ||
| 85 | end) | ||
