-
-
Notifications
You must be signed in to change notification settings - Fork 809
/
Copy pathtest.js
70 lines (54 loc) · 1.72 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
'use strict';
// MODULES //
var tape = require( 'tape' );
var removePunctuation = require( './../lib' );
// TESTS //
tape( 'main export is a function', function test( t ) {
t.ok( true, __filename );
t.equal( typeof removePunctuation, 'function', 'main export is a function' );
t.end();
});
tape( 'the function throws an error if not provided a string', function test( t ) {
var values;
var i;
values = [
5,
null,
true,
undefined,
NaN,
[],
{},
function noop() {}
];
for ( i = 0; i < values.length; i++ ) {
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
}
t.end();
function badValue( value ) {
return function badValue() {
removePunctuation( value );
};
}
});
tape( 'the function returns an empty string if provided an empty string', function test( t ) {
t.equal( removePunctuation( '' ), '', 'returns empty string' );
t.end();
});
tape( 'the function removes punctuation characters from a string', function test( t ) {
var expected;
var out;
out = removePunctuation( 'Hello, Sir!' );
expected = 'Hello Sir';
t.equal( out, expected, 'removes punctuation' );
out = removePunctuation( '"Too little, too late", he said to me...' );
expected = 'Too little too late he said to me';
t.equal( out, expected, 'removes punctuation' );
out = removePunctuation( 'We don\'t need no education, we don\'t need no thought control' );
expected = 'We dont need no education we dont need no thought control';
t.equal( out, expected, 'removes punctuation' );
out = removePunctuation( 'Sun Tzu said: "A leader leads by example not by force."' );
expected = 'Sun Tzu said A leader leads by example not by force';
t.equal( out, expected, 'removes punctuation' );
t.end();
});