forked from enviPath/enviPy
Current Dev State
This commit is contained in:
293
static/js/ketcher2/node_modules/tmatch/test/deep.js
generated
vendored
Normal file
293
static/js/ketcher2/node_modules/tmatch/test/deep.js
generated
vendored
Normal file
@ -0,0 +1,293 @@
|
||||
var tap = require('tap')
|
||||
var test = tap.test
|
||||
var match = require('../')
|
||||
|
||||
test("shouldn't care about key order and types", function (t) {
|
||||
t.ok(match({ a: 1, b: 2 }, { b: 2, a: '1' }))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should notice objects with different shapes', function (t) {
|
||||
t.notOk(match(
|
||||
{ a: 1, b: 'a thing' },
|
||||
{ a: 1, b: undefined }
|
||||
))
|
||||
t.ok(match(
|
||||
{ a: 1 },
|
||||
{ a: 1, b: undefined }
|
||||
))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('extra keys in object are ok', function (t) {
|
||||
t.ok(match(
|
||||
{ a: 1, b: null, c: 'ok' },
|
||||
{ a: 1, b: undefined }
|
||||
))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should notice objects with different keys', function (t) {
|
||||
t.notOk(match(
|
||||
{ a: 1, b: 2 },
|
||||
{ a: 1, c: 2 }
|
||||
))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should handle dates', function (t) {
|
||||
t.notOk(match(new Date('1972-08-01'), null))
|
||||
t.notOk(match(new Date('1972-08-01'), undefined))
|
||||
t.ok(match(new Date('1972-08-01'), new Date('1972-08-01')))
|
||||
t.ok(match({ x: new Date('1972-08-01') }, { x: new Date('1972-08-01') }))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should handle RegExps', function (t) {
|
||||
t.notOk(match(/[b]/, /[a]/))
|
||||
t.notOk(match(/[a]/i, /[a]/g))
|
||||
t.ok(match(/[a]/, /[a]/))
|
||||
t.ok(match(/ab?[a-z]{,6}/g, /ab?[a-z]{,6}/g))
|
||||
t.notOk(match([1, 2, 3], /asdf/))
|
||||
t.ok(match([1, 2, 3], /,2,/))
|
||||
t.ok(match({ x: 123 }, { x: /^\w+/ }))
|
||||
t.ok(match({ toString: function () { return 'FooBar' }}, /^FooBar$/))
|
||||
t.notOk(match({ toString: function () { return 'x' }}, /^FooBar$/))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should handle functions', function (t) {
|
||||
var fnA = function (a) { return a }
|
||||
var fnB = function (a) { return a }
|
||||
|
||||
t.notOk(match(
|
||||
function a () {},
|
||||
function a () {} // but is it the _same_ a tho
|
||||
))
|
||||
t.notOk(match(fnA, fnB))
|
||||
t.ok(match(fnA, fnA))
|
||||
t.ok(match(fnB, fnB))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('should handle arguments', function (t) {
|
||||
var outer = arguments
|
||||
;(function (tt) {
|
||||
var inner = arguments
|
||||
t.ok(match(outer, outer))
|
||||
t.ok(match(outer, inner))
|
||||
t.ok(match(outer, [t]))
|
||||
}(t))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('same arrays match', function (t) {
|
||||
t.ok(match([1, 2, 3], [1, 2, 3]))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("different arrays don't match", function (t) {
|
||||
t.notOk(match([1, 2, 3], [1, 2, 3, 4]))
|
||||
t.notOk(match([1, 2, 3], [1, 2, 4]))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('empty arrays match', function (t) {
|
||||
t.ok(match([], []))
|
||||
t.ok(match({ x: [] }, { x: [] }))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("shallower shouldn't care about key order recursively and types", function (t) {
|
||||
t.ok(match(
|
||||
{ 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(match(undefined, undefined))
|
||||
t.ok(match({ x: undefined }, { x: undefined }))
|
||||
t.ok(match({ x: [undefined] }, { x: [undefined] }))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('undefined and null are Close Enough', function (t) {
|
||||
t.ok(match(undefined, null))
|
||||
t.ok(match({ x: null }, { x: undefined }))
|
||||
t.ok(match({ x: [undefined] }, { x: [null] }))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("null is as shallow as you'd expect", function (t) {
|
||||
t.ok(match(null, null))
|
||||
t.ok(match({ x: null }, { x: null }))
|
||||
t.ok(match({ x: [null] }, { x: [null] }))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('the same number matches', function (t) {
|
||||
t.ok(match(0, 0))
|
||||
t.ok(match(1, 1))
|
||||
t.ok(match(3.14, 3.14))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("different numbers don't match", function (t) {
|
||||
t.notOk(match(0, 1))
|
||||
t.notOk(match(1, -1))
|
||||
t.notOk(match(3.14, 2.72))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test("tmatch shouldn't care about key order (but still might) and types", function (t) {
|
||||
t.ok(match(
|
||||
[
|
||||
{ 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("match 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(match(x1, x2))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('regexps match strings', function (t) {
|
||||
var x = { one: 'String' }
|
||||
var y = { one: /.ring$/ }
|
||||
t.ok(match(x, y))
|
||||
t.ok(match(x.one, y.one))
|
||||
|
||||
x = [ 'String', 'String' ]
|
||||
y = [ /.ring$/, /.ring$/ ]
|
||||
t.ok(match(x, y))
|
||||
|
||||
x = [ 'Ring', /.ring$/ ]
|
||||
y = [ /.ring$/ ]
|
||||
t.notOk(match(x, y))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('partial strings match on indexOf', function (t) {
|
||||
var x = { one: 'String' }
|
||||
var y = { one: 'rin' }
|
||||
|
||||
t.ok(match(x, y))
|
||||
t.notOk(match(y, x))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('ctors and other fun things', function (t) {
|
||||
function Foo () {
|
||||
this._isFoo = 'foo'
|
||||
}
|
||||
|
||||
if (!Buffer.prototype.equals) {
|
||||
Buffer.prototype.equals = function (pattern) {
|
||||
var obj = this
|
||||
if (obj.length !== pattern.length) return false
|
||||
for (var j = 0; j < obj.length; j++) if (obj[j] != pattern[j]) return false
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
t.notOk(match(new Buffer('asdf'), new Buffer('asdff')))
|
||||
|
||||
var d = new Date().toISOString()
|
||||
|
||||
var obj = {
|
||||
buffer: new Buffer('x'),
|
||||
date: new Date(d),
|
||||
fn: function () {},
|
||||
foo: new Foo(),
|
||||
num: 1.2,
|
||||
nan: NaN,
|
||||
bool: true,
|
||||
array: [],
|
||||
str: 'asdf',
|
||||
inf: Infinity,
|
||||
neginf: -Infinity
|
||||
}
|
||||
|
||||
t.ok(match(obj, {
|
||||
buffer: Buffer,
|
||||
date: Date,
|
||||
fn: Function,
|
||||
foo: Foo,
|
||||
num: Number,
|
||||
nan: NaN,
|
||||
bool: Boolean,
|
||||
array: Array,
|
||||
str: String
|
||||
}))
|
||||
|
||||
t.ok(match(obj, {
|
||||
buffer: new Buffer('x'),
|
||||
date: d,
|
||||
foo: new Foo(),
|
||||
str: 'sd'
|
||||
}))
|
||||
|
||||
var buf = new Buffer('x')
|
||||
buf.equals = null
|
||||
t.ok(match(obj, {
|
||||
buffer: buf
|
||||
}))
|
||||
|
||||
var buf2 = new Buffer('y')
|
||||
buf2.equals = null
|
||||
t.notOk(match(buf, buf2))
|
||||
|
||||
var buf3 = new Buffer('xy')
|
||||
buf3.equals = null
|
||||
t.notOk(match(buf, buf3))
|
||||
|
||||
var buf4 = new Buffer('xy')
|
||||
buf4.equals = null
|
||||
t.ok(match(buf4, buf3))
|
||||
|
||||
t.notOk(match(obj, {
|
||||
inf: Number
|
||||
}))
|
||||
|
||||
t.notOk(match(obj, {
|
||||
neginf: Number
|
||||
}))
|
||||
|
||||
t.notOk(match(obj, {
|
||||
nan: Number
|
||||
}))
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('js WAT! array/string stuff', function (t) {
|
||||
t.notOk(match([1], 1))
|
||||
t.notOk(match(1, [1]))
|
||||
t.ok(match([1], [1]))
|
||||
var o = {}
|
||||
t.ok(match(o, o))
|
||||
t.ok(match(1, '1'))
|
||||
t.end()
|
||||
})
|
||||
3
static/js/ketcher2/node_modules/tmatch/test/no-array-from.js
generated
vendored
Normal file
3
static/js/ketcher2/node_modules/tmatch/test/no-array-from.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict'
|
||||
Array.from = null
|
||||
require('./deep.js')
|
||||
50
static/js/ketcher2/node_modules/tmatch/test/set-map.js
generated
vendored
Normal file
50
static/js/ketcher2/node_modules/tmatch/test/set-map.js
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
'use strict'
|
||||
var tmatch = require('../')
|
||||
var t = require('tap')
|
||||
|
||||
t.test('set', function (t) {
|
||||
var obj = { a: 1 }
|
||||
var pattern = new Set([obj, 4])
|
||||
var a = new Set([1, 2, 3, 4, obj])
|
||||
var b = new Set([obj, 2, 4, 3, 1])
|
||||
var c = new Set([4, 3, 2, 1, { a: 1 }])
|
||||
|
||||
t.ok(tmatch(a, pattern))
|
||||
t.ok(tmatch(b, pattern))
|
||||
t.notOk(tmatch(c, pattern))
|
||||
t.notOk(tmatch({not: 'a set'}, pattern))
|
||||
|
||||
t.ok(tmatch(a, b))
|
||||
t.notOk(tmatch(a, c))
|
||||
t.notOk(tmatch(b, c))
|
||||
t.ok(tmatch(new Set(), new Set()))
|
||||
t.notOk(tmatch(a, Array.from(a)))
|
||||
t.end()
|
||||
})
|
||||
|
||||
t.test('map', function (t) {
|
||||
var obj = { a: 1 }
|
||||
var pattern = new Map([[5, { a: 1 }], [obj, '6']])
|
||||
|
||||
var a = new Map([[1, 2], [3, 4], [5, obj], [ obj, 6 ]])
|
||||
var b = new Map([[3, 4], [5, obj], [ obj, 6 ], [1, 2]])
|
||||
// values match, but not strictly
|
||||
var c = new Map([[3, 4], [5, { a: '1' }], [ obj, 6 ], [1, 2]])
|
||||
// keys don't match
|
||||
var d = new Map([[3, 4], [5, { a: 1 }], [ { a: 1 }, 6 ], [1, 2]])
|
||||
|
||||
t.ok(tmatch(a, pattern))
|
||||
t.ok(tmatch(b, pattern))
|
||||
t.ok(tmatch(c, pattern))
|
||||
t.notOk(tmatch(d, pattern))
|
||||
t.notOk(tmatch({not: 'a map'}, pattern))
|
||||
|
||||
t.ok(tmatch(a, b))
|
||||
t.ok(tmatch(a, c))
|
||||
t.ok(tmatch(b, c))
|
||||
t.ok(tmatch(new Map(), new Map()))
|
||||
t.notOk(tmatch(a, Array.from(a)))
|
||||
t.notOk(tmatch(a, d))
|
||||
t.notOk(tmatch(a, d))
|
||||
t.end()
|
||||
})
|
||||
Reference in New Issue
Block a user