-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
129 lines (109 loc) · 2.59 KB
/
test.js
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
!function() {
var api = require('./')
var aok = require('aok')
var OP = Object.prototype
function noop() {}
aok.prototype.express = aok.info // uses alert in IE8
aok.prototype.fail = function() {
throw new Error('FAILED TEST: ' + this.id)
}
/**
* @this {{pass:*, fail:*}} aok instance
* @param {string} key either "pass" or "fail"
* @param {string} msg message to append
*/
aok.prototype.comment = function(key, msg) {
if (!(this instanceof aok)) throw new TypeError('@this')
if (typeof this[key] == 'string') this[key] += ' (' + msg + ')'
}
aok({
id: 'keys',
test: 'a' === api.keys({a: 1}).pop()
})
aok({
id: 'values',
test: api.values([4, 7]).join('') === '47'
})
aok({
id: 'combine',
test: api.combine(['k'], ['v']).k === 'v'
})
aok({
id: 'child-alias',
test: api.child === api.create
})
aok({
id: 'parent-object',
test: api.parent({}) === Object.prototype
})
aok({
id: 'parent-function',
test: api.parent(noop) === Function.prototype
})
aok({
id: 'orphan',
test: api.parent(api.orphan()) === null
})
aok({
id: 'parents',
test: api.parents(noop).pop() === Object.prototype
})
aok({
id: 'chain',
test: api.chain(noop)[0] === noop
})
aok({
id: 'create',
test: [null, {a: 1}, function() {}].every(function(parent) {
var child = api.create(parent)
return !!child && !api.keys(child).length && api.parent(child) === parent
})
})
aok({
id: 'names-array',
test: api.names([]).length
})
aok({
id: 'names-stack',
test: api.names({length: 0}).length
})
aok({
id: 'names-function',
test: api.names(function() {}).length
})
aok({
id: 'invert',
test: api.invert({k: 'v'}).v === 'k'
})
aok({
id: 'assign',
test: function() {
var to = {a: 1}
if (to !== api.assign(to)) return false
api.assign(to, {b: 2, c: 3}, {d: 4}, {b: 5})
return to.a === 1 && to.b === 5 && to.c === 3 && to.d === 4
}
})
aok({
id: 'adopt',
test: function() {
var to = {a: 1}
if (to !== api.adopt.call(to)) return false
api.adopt.call(to, {b: 2, c: 3}, {d: 4}, {b: 5})
return to.a === 1 && to.b === 5 && to.c === 3 && to.d === 4
}
})
aok({
id: 'chain',
test: function() {
var a = {id: 'a'}
var b = api.create(a)
var c = api.create(b)
b.id = 'b'
c.id = 'c'
var r = api.chain(c)
return 4 === r.length && c === r[0] && b === r[1] && a === r[2] && OP === r[3]
}
})
console.log('All tests passed =)')
}();