-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
104 lines (89 loc) · 3.1 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
const { wordTrans, letterTrans, regexTrans, version } = require('./index');
test('wordTrans: should throw a TypeError on invalid text', () => {
try {
wordTrans(undefined, {});
} catch (err) {
expect(err.name).toBe('TypeError');
expect(err.message).toBe('text must be a string.');
}
});
test('wordTrans: should throw a TypeError on invalid dictionary', () => {
try {
wordTrans('', undefined);
} catch (err) {
expect(err.name).toBe('TypeError');
expect(err.message).toBe('dictionary must be an object.');
}
});
test('wordTrans: should work', () => {
const tested = wordTrans('This is a test string.', { test: 'tested', string: 'sentence' });
expect(tested).toBe('This is a tested sentence.');
});
test('wordTrans: should capitalize properly', () => {
const tested = wordTrans('This is a "Test" of the casing. A TEST.', { this: 'that', test: 'testing' });
expect(tested).toBe('That is a "Testing" of the casing. A TESTING.');
});
test('wordTrans: should replace instances of "\'s" at the end of words.', () => {
const tested = wordTrans('This is the test\'s be\'st friend. The test\'s. Tests\'', { test: 'testing' });
expect(tested).toBe('This is the testing\'s be\'st friend. The testing\'s. Testings\'');
});
test('wordTrans: join should work', () => {
const tested = wordTrans('This is a test string.', { test: 'tested', string: 'sentence' }, '/');
expect(tested).toBe('This/is/a/tested/sentence.');
});
test('letterTrans: should throw a TypeError on invalid text', () => {
try {
letterTrans(undefined, {});
} catch (err) {
expect(err.name).toBe('TypeError');
expect(err.message).toBe('text must be a string.');
}
});
test('letterTrans: should throw a TypeError on invalid dictionary', () => {
try {
letterTrans('', undefined);
} catch (err) {
expect(err.name).toBe('TypeError');
expect(err.message).toBe('dictionary must be an object.');
}
});
test('letterTrans: should work', () => {
const tested = letterTrans('abc 123', { a: 'b', 1: '2' });
expect(tested).toBe('bbc 223');
});
test('letterTrans: join should work', () => {
const tested = letterTrans('abc 123', { a: 'b', 1: '2' }, '/');
expect(tested).toBe('b/b/c/ /2/2/3');
});
test('regexTrans: should throw a TypeError on invalid text', () => {
try {
regexTrans(undefined, {});
} catch (err) {
expect(err.name).toBe('TypeError');
expect(err.message).toBe('text must be a string.');
}
});
test('regexTrans: should throw a TypeError on invalid dictionary', () => {
try {
regexTrans('', undefined);
} catch (err) {
expect(err.name).toBe('TypeError');
expect(err.message).toBe('dictionary must be an object.');
}
});
test('regexTrans: should throw a TypeError on invalid flags', () => {
try {
regexTrans('', {}, undefined);
} catch (err) {
expect(err.name).toBe('TypeError');
expect(err.message).toBe('flags must be a string.');
}
});
test('regexTrans: should work', () => {
const tested = regexTrans('abcd abd 123', { 'abc?d': 'efg', '[123]': 'number' });
expect(tested).toBe('efg efg numbernumbernumber');
});
test('version: should be right', () => {
const pkg = require('./package');
expect(version).toBe(pkg.version);
});