-
Notifications
You must be signed in to change notification settings - Fork 3
/
array.js
118 lines (107 loc) · 4.71 KB
/
array.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
var atoum = require('../..')(module),
util = require('util'),
Generator = require('../../lib/asserter/generator'),
obj = require('../../lib/asserters/object'),
testedClass = require('../../lib/asserters/array'),
unit = module.exports = {
testClass: function() {
var object, generator;
this
.if(generator = new Generator())
.then()
.object(object = new testedClass(generator)).isInstanceOf(obj)
.object(object.generator).isEqualTo(generator)
;
},
testSetWith: function() {
var object, value;
this
.if(object = new testedClass(new Generator()))
.then()
.error(function() {
object.setWith(value)
})
.hasName('Failure')
.hasMessage('undefined is not an array')
.if(value = {})
.then()
.error(function() {
object.setWith(value)
})
.hasName('Failure')
.hasMessage('[object Object] is not an array')
.if(value = [])
.then()
.object(object.setWith(value)).isIdenticalTo(object)
.array(object.value).isEqualTo(value)
;
},
testHasLength: function() {
var object;
this
.if(object = new testedClass(new Generator()))
.and(object.setWith([]))
.then()
.object(object.hasLength(0)).isIdenticalTo(object)
.if(object.setWith([ 0 ]))
.then()
.error(function() {
object.hasLength(0);
})
.hasName('Failure')
.hasMessage('Array(1) has not length 0')
.object(object.hasLength(1)).isIdenticalTo(object)
;
},
testIsEqualTo: function() {
var object, value, wrongValue;
this
.if(object = new testedClass(new Generator()))
.and(object.setWith(value = [ 'foobar' ]))
.then()
.error(function() {
object.isEqualTo(wrongValue = [ Math.random().toString(36).substring(7) ]);
})
.hasName('Failure')
.hasMessage(util.format('%s is not equal to %s', value, wrongValue))
.object(object.isEqualTo([ 'foobar' ])).isIdenticalTo(object)
.if(object.setWith(value = [ Math.random().toString(36).substring(7), Math.random().toString(36).substring(7) ]))
.then()
.error(function() {
object.isEqualTo(wrongValue = []);
})
.hasName('Failure')
.hasMessage(util.format('%s is not equal to %s', value, wrongValue))
.if(object.setWith(value = [ undefined ]))
.then()
.object(object.isEqualTo(value)).isIdenticalTo(object)
.object(object.isEqualTo([ undefined ])).isIdenticalTo(object)
;
},
testContains: function() {
var object, value, wrongValue, values;
this
.if(object = new testedClass(new Generator()))
.and(object.setWith(values = [ value = Math.random().toString(36).substring(7) ]))
.then()
.error(function() {
object.contains(wrongValue = Math.random().toString(36).substring(7));
})
.hasName('Failure')
.hasMessage(util.format('%s does not contain %s', util.inspect(values), util.inspect(wrongValue)))
.object(object.contains(value)).isIdenticalTo(object)
},
testContains: function() {
var object, value, values;
this
.if(object = new testedClass(new Generator()))
.and(object.setWith(values = [ value = Math.random().toString(36).substring(7) ]))
.then()
.error(function() {
object.doesNotContain(value);
})
.hasName('Failure')
.hasMessage(util.format('%s contains %s', util.inspect(values), util.inspect(value)))
.object(object.doesNotContain(Math.random().toString(36).substring(7))).isIdenticalTo(object)
}
};