|
| 1 | +describe('mach.deep_compare_matcher', function() |
| 2 | + local match = require 'mach.deep_compare_matcher' |
| 3 | + |
| 4 | + it('should indicate that identical numbers match', function() |
| 5 | + assert.is_true(match(13, 13)) |
| 6 | + end) |
| 7 | + |
| 8 | + it('should indicate that different numbers do not match', function() |
| 9 | + assert.is_false(match(13, 12)) |
| 10 | + end) |
| 11 | + |
| 12 | + it('should indicate that identical strings match', function() |
| 13 | + assert.is_true(match('hello', 'hello')) |
| 14 | + end) |
| 15 | + |
| 16 | + it('should indicate that different strings do not match', function() |
| 17 | + assert.is_false(match('mach', 'mock')) |
| 18 | + end) |
| 19 | + |
| 20 | + it('should indicate that identical booleans match', function() |
| 21 | + assert.is_true(match(true, true)) |
| 22 | + assert.is_true(match(false, false)) |
| 23 | + end) |
| 24 | + |
| 25 | + it('should indicate that true and false do not match', function() |
| 26 | + assert.is_false(match(true, false)) |
| 27 | + assert.is_false(match(false, true)) |
| 28 | + end) |
| 29 | + |
| 30 | + it('should indicate that nothing matches nil except nil', function() |
| 31 | + assert.is_false(match(nil, 13)) |
| 32 | + assert.is_false(match(13, nil)) |
| 33 | + assert.is_true(match(nil, nil)) |
| 34 | + end) |
| 35 | + |
| 36 | + it('should indicate that a table matches itself', function() |
| 37 | + local t = {} |
| 38 | + assert.is_true(match(t, t)) |
| 39 | + end) |
| 40 | + |
| 41 | + it('should indicate that tables with the same contents are the same', function() |
| 42 | + assert.is_true(match({ a = 1, b = 2 }, { a = 1, b = 2 })) |
| 43 | + end) |
| 44 | + |
| 45 | + it('should indicate that tables with different keys are not the same', function() |
| 46 | + assert.is_true(match({ a = 1, b = 2 }, { a = 1, b = 2 })) |
| 47 | + end) |
| 48 | + |
| 49 | + it('should indicate that two tables, one with an extra key, are not the same', function() |
| 50 | + assert.is_false(match({ a = 1, b = 2 }, { a = 1 })) |
| 51 | + assert.is_false(match({ a = 1 }, { a = 1, b = 2 })) |
| 52 | + end) |
| 53 | + |
| 54 | + it('should indicate that tables with the same keys but different values are not the same', function() |
| 55 | + assert.is_false(match({ a = 1, b = 2 }, { a = 11, b = 22 })) |
| 56 | + end) |
| 57 | + |
| 58 | + it('should indicate that deep tables match when their contents are the same', function() |
| 59 | + local t1 = { |
| 60 | + a = { b = 2 }, |
| 61 | + c = { 1, 2, 3 } |
| 62 | + } |
| 63 | + |
| 64 | + local t2 = { |
| 65 | + a = { b = 2 }, |
| 66 | + c = { 1, 2, 3 } |
| 67 | + } |
| 68 | + |
| 69 | + assert.is_true(match(t1, t2)) |
| 70 | + end) |
| 71 | + |
| 72 | + it('should indicate that deep tables match when their contents are different', function() |
| 73 | + local t1 = { |
| 74 | + a = { b = 2 }, |
| 75 | + c = { 1, 2, 3 } |
| 76 | + } |
| 77 | + |
| 78 | + local t2 = { |
| 79 | + a = { b = '2' }, |
| 80 | + c = { 1, 2, 3 } |
| 81 | + } |
| 82 | + |
| 83 | + assert.is_false(match(t1, t2)) |
| 84 | + end) |
| 85 | +end) |
0 commit comments