| 1 |
package.path = '../src/?.lua;' .. package.path |
| 2 |
local tap = require 'tapered' |
| 3 |
-- luacheck: compat |
| 4 |
|
| 5 |
tap.same({},{}, 'ok - same({}, {}') |
| 6 |
tap.same({1,2,3}, {1,2,3}, 'ok - same({1,2,3}, {1,2,3})') |
| 7 |
tap.same({1},{}, 'not ok - same({1}, {})') |
| 8 |
tap.same({{1}, 2, {3,4}},{{1}, 2, {3,4}}, |
| 9 |
'ok - same({{1}, 2, {3,4}}, {{1}, 2, {3,4})') |
| 10 |
|
| 11 |
local days1 = { 'Monday', 'Tuesday' } |
| 12 |
local days2 = { 'Monday', 'Tuesday' } |
| 13 |
tap.same(days1, days2, 'ok - same({"Monday", "Tuesday"}, {"Monday", "Tuesday"})') |
| 14 |
local days3 = { 'Monday', 'Tuesday', 'Wednesday', } |
| 15 |
tap.same(days2, days3, |
| 16 |
'not ok - same({"Monday", "Tuesday"}, {"Monday", "Tuesday", "Wednesday"})') |
| 17 |
|
| 18 |
local hash1 = { |
| 19 |
Monday = 1, |
| 20 |
} |
| 21 |
local hash2 = { |
| 22 |
Monday = 1, |
| 23 |
} |
| 24 |
local hash3 = { |
| 25 |
Monday = 1, |
| 26 |
Tuesday = 2, |
| 27 |
} |
| 28 |
tap.same(hash1, hash2, 'ok - same({Monday = 1}, {Monday = 1})') |
| 29 |
tap.same(hash1, hash3, |
| 30 |
'not ok - same({Monday = 1}, {Monday = 1, Tuesday = 2})') |
| 31 |
|
| 32 |
local n1 = { m = { 1, 2 }, n = { 1, 2 } } |
| 33 |
local n2 = { m = { 1, 2 }, n = { 1, 2 } } |
| 34 |
local n3 = { m = { 1, 2 }, n = { 1, 2, 3 } } |
| 35 |
tap.same(n1, n2, 'ok - same({m = {1,2}, n = {1,2}}, {m = {1,2}, n = {1,2}})') |
| 36 |
tap.same(n1, n3, 'not ok - same({m = {1,2}, n = {1,2}}, {m = {1,2}, n = {1,2,3}})') |
| 37 |
tap.same(n3, n1, 'not ok - same({m = {1,2}, n = {1,2,3}}, {m = {1,2}, n = {1,2}})') |
| 38 |
|
| 39 |
local method_table1 = { p = print, a = assert } |
| 40 |
local method_table2 = { p = print, a = assert } |
| 41 |
local method_table3 = { p = print, a = assert, e = error } |
| 42 |
tap.same(method_table1, method_table2, |
| 43 |
'ok - same({p = print, a = assert}, {p = print, a = assert})') |
| 44 |
tap.same(method_table1, method_table3, |
| 45 |
'not ok - same({p = print, a = assert}, {p = print, a = assert, e = error})') |
| 46 |
|
| 47 |
local foo = {4, s = 4} |
| 48 |
local bar = {6, s = 8} |
| 49 |
local oof = {4, s = 3} |
| 50 |
local mt1 = {} |
| 51 |
local mt2 = {} |
| 52 |
local evens = function (x, y) return x['s'] % 2 == 0 and y['s'] % 2 == 0 end |
| 53 |
local even_odd = function (x, y) return x['s'] % 2 == 0 and y['s'] % 2 ~= 0 end |
| 54 |
mt1.__eq = evens |
| 55 |
mt2.__eq = even_odd |
| 56 |
setmetatable(foo, mt1) |
| 57 |
setmetatable(bar, mt1) |
| 58 |
setmetatable(oof, mt1) |
| 59 |
tap.same(foo, bar, 'ok - same({4, s=4}, {6, s=4},__eq => x[s] and y[s] are even)') |
| 60 |
tap.same(bar, foo, 'ok - same({6, s=8}, {4, s=4},__eq => x[s] and y[s] are even)') |
| 61 |
tap.same(foo, oof, |
| 62 |
'not ok - same({4, s=4}, {4, s=3},__eq => x[s] and y[s] are even)') |
| 63 |
tap.same(oof, foo, |
| 64 |
'not ok - same({4, s=4}, {4, s=3},__eq => x[s] and y[s] are even)') |
| 65 |
setmetatable(foo, mt2) |
| 66 |
setmetatable(bar, mt2) |
| 67 |
setmetatable(oof, mt2) |
| 68 |
tap.same(foo, bar, |
| 69 |
'not ok - same({4, s=4}, {6, s=4},__eq => x[s] is even, y[s] odd)') |
| 70 |
tap.same(foo, oof, |
| 71 |
'ok - same({4, s=4}, {4, s=3},__eq => x[s] is even, y[s] odd)') |
| 72 |
tap.same(oof, foo, |
| 73 |
'not ok - same({4, s=3}, {4, s=4},__eq => x[s] is even, y[s] odd)') |
| 74 |
tap.done() |