-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.js
57 lines (52 loc) · 1.52 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
import assert from 'node:assert/strict'
import test from 'node:test'
import {apStyleTitleCase} from './index.js'
test('ap-style-title-case', function () {
assert.equal(
apStyleTitleCase(),
'',
'should return an empty string w/o title'
)
assert.equal(
apStyleTitleCase('this is a test'),
'This Is a Test',
'should capitalize'
)
assert.equal(
apStyleTitleCase('Thing With Extra Spaces'),
'Thing With Extra Spaces',
'should remove spaces'
)
/** @type {Array<[string, string, boolean?]>} */
const patterns = [
['this is a test', 'This Is a Test'],
[
'why sunless tanning is A hot trend',
'Why Sunless Tanning Is a Hot Trend'
],
[
'Satin Sheets are a Luxury you Can Afford',
'Satin Sheets Are a Luxury You Can Afford'
],
[
'the Dangers Of Hiking Without Proper Shoes',
'The Dangers of Hiking Without Proper Shoes'
],
['an hour or so', 'An Hour or So'],
['Of the meaning Of Of', 'Of the Meaning of Of'],
['Thing With Extra Spaces', 'Thing With Extra Spaces'],
['Thing with extra spaces', 'Thing With Extra Spaces', true],
[
'Observations of isolated pulsars and disk-fed X-ray binaries.',
'Observations of Isolated Pulsars and Disk-Fed X-Ray Binaries.'
],
['Shakspeare; Or, the Poet', 'Shakspeare; or, the Poet']
]
for (const pattern of patterns) {
assert.equal(
apStyleTitleCase(pattern[0], {keepSpaces: pattern[2]}),
pattern[1],
pattern[1]
)
}
})