-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
123 lines (109 loc) · 2.75 KB
/
tests.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
var check = require('./src/check');
var checkError = function(func, message) {
var thrown;
try {
func();
} catch (error) {
thrown = error.message;
}
if (!thrown) {
throw new Error('Expected an error (' + JSON.stringify(message) + ') but no error was thrown');
} else if (thrown !== message) {
throw new Error('Expected error ' + JSON.stringify(message) + ', got ' + JSON.stringify(thrown));
} else {
console.log('.');
}
};
check(5, function(five) { five === 5; });
check(5, (five) => five === 5);
check(5, (five) => { five === 5 });
checkError(function() {
check(4, function(five) { five === 5; });
}, 'Expected `five === 5`. Got `five`: 4.');
checkError(function() {
check(4, (five) => { five === 5; });
}, 'Expected `five === 5`. Got `five`: 4.');
checkError(function() {
check(4, (five) => five === 5);
}, 'Expected `five === 5`. Got `five`: 4.');
checkError(function() {
check(false, function(value) {
value === value;
!value;
value !== true;
value === 14;
});
}, 'Expected `value === 14`. Got `value`: false.');
checkError(function() {
check(true, function(value) {
value === value;
value !== true;
!value;
value === 14;
});
}, 'Expected `value !== true`. Got `value`: true.');
checkError(function() {
check(5, function(value) {
value === value;
value !== true;
!value;
value === 14;
});
}, 'Expected `!value`. Got `value`: 5.');
checkError(function() {
check(NaN, function(value) {
value === value;
value !== true;
!value;
value === 14;
});
}, 'Expected `value === value`. Got `value`: NaN.');
checkError(function() {
check([1, 2, 3], function(values) {
values[0] + values[1] + values[2] === 3;
});
}, 'Expected `values[0] + values[1] + values[2] === 3`. Got `values[0] + values[1] + values[2]`: 6.');
checkError(function() {
check(10, function(value) {
if (value % 4 === 0) {
'red' === 'blue';
'green' === 'orange';
} else if (value % 4 === 1) {
2 + 2 === 5;
3 + 3 === 33;
} else if (value % 4 === 2) {
10 === 0x10;
11 === 0x11;
} else {
[].length >= 1;
({})['abc'];
}
});
}, 'Expected `10 === 0x10`.');
checkError(function() {
check(10, function(value) {
if (value % 4 === 0)
'red' === 'blue';
else if (value % 4 === 1)
2 + 2 === 5;
else if (value % 4 === 2)
10 === 0x10;
else
[].length >= 1;
});
}, 'Expected `10 === 0x10`.');
checkError(function() {
check(8, function(n) {
while (n-- >= 0) {
n % 5 > 0;
n % 3 > 0;
}
});
}, 'Expected `n % 3 > 0`. Got `n % 3`: 0.');
checkError(function() {
check(8, function(n) {
while (n-- >= 0)
n % 5 > 0;
n % 3 > 0;
});
}, 'Expected `n % 5 > 0`. Got `n % 5`: 0.');