1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
var tap = require('../../..')
var test = tap.test
var same = require('../..')
test("NaN matches NaN", function (t) {
t.ok(same(NaN, NaN))
t.end()
})
test("shouldn't care about key order and types", function (t) {
t.ok(same({ a: 1, b: 2 }, { b: 2, a: '1' }))
t.end()
})
test('should notice objects with different shapes', function (t) {
t.notOk(same(
{ a: 1 },
{ a: 1, b: undefined }
))
t.end()
})
test('should notice objects with different keys', function (t) {
t.notOk(same(
{ a: 1, b: 2 },
{ a: 1, c: 2 }
))
t.end()
})
test('should handle dates', function (t) {
t.notOk(same(new Date('1972-08-01'), null))
t.notOk(same(new Date('1972-08-01'), undefined))
t.ok(same(new Date('1972-08-01'), new Date('1972-08-01')))
t.ok(same({ x: new Date('1972-08-01') }, { x: new Date('1972-08-01') }))
t.end()
})
test('should handle RegExps', function (t) {
t.notOk(same(/[b]/, /[a]/))
t.notOk(same(/[a]/i, /[a]/g))
t.ok(same(/[a]/, /[a]/))
t.ok(same(/ab?[a-z]{,6}/g, /ab?[a-z]{,6}/g))
t.end()
})
test('should handle functions', function (t) {
var fnA = function (a) { return a }
var fnB = function (a) { return a }
t.notOk(same(
function a () {},
function a () {} // but is it the _same_ a tho
))
t.notOk(same(fnA, fnB))
t.ok(same(fnA, fnA))
t.ok(same(fnB, fnB))
t.end()
})
test('should handle arguments', function (t) {
var outer = arguments
;(function inner (tt) {
var inner = arguments
t.ok(same(outer, outer))
t.ok(same(outer, inner))
t.ok(same(outer, [t]))
}(t))
t.end()
})
test('same arrays match', function (t) {
t.ok(same([1, 2, 3], [1, 2, 3]))
t.end()
})
test("different arrays don't match", function (t) {
t.notOk(same([1, 2, 3], [1, 2, 3, 4]))
t.notOk(same([1, 2, 3], [1, 2, 4]))
t.end()
})
test('empty arrays match', function (t) {
t.ok(same([], []))
t.ok(same({ x: [] }, { x: [] }))
t.end()
})
test("shallower shouldn't care about key order recursively and types", function (t) {
t.ok(same(
{ x: { a: 1, b: 2 }, y: { c: 3, d: 4 } },
{ y: { d: 4, c: 3 }, x: { b: '2', a: '1' } }
))
t.end()
})
test('undefined is the same as itself', function (t) {
t.ok(same(undefined, undefined))
t.ok(same({ x: undefined }, { x: undefined }))
t.ok(same({ x: [undefined] }, { x: [undefined] }))
t.end()
})
test('undefined and null are Close Enough', function (t) {
t.ok(same(undefined, null))
t.ok(same({ x: null }, { x: undefined }))
t.ok(same({ x: [undefined] }, { x: [null] }))
t.end()
})
test("null is as shallow as you'd expect", function (t) {
t.ok(same(null, null))
t.ok(same({ x: null }, { x: null }))
t.ok(same({ x: [null] }, { x: [null] }))
t.end()
})
test('the same number matches', function (t) {
t.ok(same(0, 0))
t.ok(same(1, 1))
t.ok(same(3.14, 3.14))
t.end()
})
test("different numbers don't match", function (t) {
t.notOk(same(0, 1))
t.notOk(same(1, -1))
t.notOk(same(3.14, 2.72))
t.end()
})
test("shallower shouldn't care about key order (but still might) and types", function (t) {
t.ok(same(
[
{ foo: { z: 100, y: 200, x: 300 } },
'bar',
11,
{ baz: { d: 4, a: 1, b: 2, c: 3 } }
],
[
{ foo: { z: 100, y: 200, x: 300 } },
'bar',
11,
{ baz: { a: '1', b: '2', c: '3', d: '4' } }
]
))
t.end()
})
test("shallower shouldn't blow up on circular data structures", function (t) {
var x1 = { z: 4 }
var y1 = { x: x1 }
x1.y = y1
var x2 = { z: 4 }
var y2 = { x: x2 }
x2.y = y2
t.ok(same(x1, x2))
t.end()
})
|