/
test.js
137 lines (134 loc) · 6.95 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import test from 'ava';
import camelCase from '.';
test('camelCase', t => {
t.is(camelCase('foo'), 'foo');
t.is(camelCase('foo-bar'), 'fooBar');
t.is(camelCase('foo-bar-baz'), 'fooBarBaz');
t.is(camelCase('foo--bar'), 'fooBar');
t.is(camelCase('--foo-bar'), 'fooBar');
t.is(camelCase('--foo--bar'), 'fooBar');
t.is(camelCase('FOO-BAR'), 'fooBar');
t.is(camelCase('FOÈ-BAR'), 'foèBar');
t.is(camelCase('-foo-bar-'), 'fooBar');
t.is(camelCase('--foo--bar--'), 'fooBar');
t.is(camelCase('foo.bar'), 'fooBar');
t.is(camelCase('foo..bar'), 'fooBar');
t.is(camelCase('..foo..bar..'), 'fooBar');
t.is(camelCase('foo_bar'), 'fooBar');
t.is(camelCase('__foo__bar__'), 'fooBar');
t.is(camelCase('__foo__bar__'), 'fooBar');
t.is(camelCase('foo bar'), 'fooBar');
t.is(camelCase(' foo bar '), 'fooBar');
t.is(camelCase('-'), '-');
t.is(camelCase(' - '), '-');
t.is(camelCase('fooBar'), 'fooBar');
t.is(camelCase('fooBar-baz'), 'fooBarBaz');
t.is(camelCase('foìBar-baz'), 'foìBarBaz');
t.is(camelCase('fooBarBaz-bazzy'), 'fooBarBazBazzy');
t.is(camelCase('FBBazzy'), 'fbBazzy');
t.is(camelCase('F'), 'f');
t.is(camelCase('FooBar'), 'fooBar');
t.is(camelCase('Foo'), 'foo');
t.is(camelCase('FOO'), 'foo');
t.is(camelCase(['foo', 'bar']), 'fooBar');
t.is(camelCase(['foo', '-bar']), 'fooBar');
t.is(camelCase(['foo', '-bar', 'baz']), 'fooBarBaz');
t.is(camelCase(['', '']), '');
t.is(camelCase('--'), '');
t.is(camelCase(''), '');
t.is(camelCase('--__--_--_'), '');
t.is(camelCase(['---_', '--', '', '-_- ']), '');
t.is(camelCase('foo bar?'), 'fooBar?');
t.is(camelCase('foo bar!'), 'fooBar!');
t.is(camelCase('foo bar$'), 'fooBar$');
t.is(camelCase('foo-bar#'), 'fooBar#');
t.is(camelCase('XMLHttpRequest'), 'xmlHttpRequest');
t.is(camelCase('AjaxXMLHttpRequest'), 'ajaxXmlHttpRequest');
t.is(camelCase('Ajax-XMLHttpRequest'), 'ajaxXmlHttpRequest');
t.is(camelCase([]), '');
t.is(camelCase('mGridCol6@md'), 'mGridCol6@md');
t.is(camelCase('A::a'), 'a::a');
t.is(camelCase('Hello1World'), 'hello1World');
t.is(camelCase('Hello11World'), 'hello11World');
t.is(camelCase('hello1world'), 'hello1World');
t.is(camelCase('Hello1World11foo'), 'hello1World11Foo');
t.is(camelCase('Hello1'), 'hello1');
t.is(camelCase('hello1'), 'hello1');
t.is(camelCase('1Hello'), '1Hello');
t.is(camelCase('1hello'), '1Hello');
t.is(camelCase('h2w'), 'h2W');
t.is(camelCase('розовый_пушистый-единороги'), 'розовыйПушистыйЕдинороги');
t.is(camelCase('розовый_пушистый-единороги'), 'розовыйПушистыйЕдинороги');
t.is(camelCase('РОЗОВЫЙ_ПУШИСТЫЙ-ЕДИНОРОГИ'), 'розовыйПушистыйЕдинороги');
t.is(camelCase('桑德在这里。'), '桑德在这里。');
t.is(camelCase('桑德在这里。'), '桑德在这里。');
t.is(camelCase('桑德_在这里。'), '桑德在这里。');
});
test('camelCase with pascalCase option', t => {
t.is(camelCase('foo', {pascalCase: true}), 'Foo');
t.is(camelCase('foo-bar', {pascalCase: true}), 'FooBar');
t.is(camelCase('foo-bar-baz', {pascalCase: true}), 'FooBarBaz');
t.is(camelCase('foo--bar', {pascalCase: true}), 'FooBar');
t.is(camelCase('--foo-bar', {pascalCase: true}), 'FooBar');
t.is(camelCase('--foo--bar', {pascalCase: true}), 'FooBar');
t.is(camelCase('FOO-BAR', {pascalCase: true}), 'FooBar');
t.is(camelCase('FOÈ-BAR', {pascalCase: true}), 'FoèBar');
t.is(camelCase('-foo-bar-', {pascalCase: true}), 'FooBar');
t.is(camelCase('--foo--bar--', {pascalCase: true}), 'FooBar');
t.is(camelCase('foo.bar', {pascalCase: true}), 'FooBar');
t.is(camelCase('foo..bar', {pascalCase: true}), 'FooBar');
t.is(camelCase('..foo..bar..', {pascalCase: true}), 'FooBar');
t.is(camelCase('foo_bar', {pascalCase: true}), 'FooBar');
t.is(camelCase('__foo__bar__', {pascalCase: true}), 'FooBar');
t.is(camelCase('__foo__bar__', {pascalCase: true}), 'FooBar');
t.is(camelCase('foo bar', {pascalCase: true}), 'FooBar');
t.is(camelCase(' foo bar ', {pascalCase: true}), 'FooBar');
t.is(camelCase('-', {pascalCase: true}), '-');
t.is(camelCase(' - ', {pascalCase: true}), '-');
t.is(camelCase('fooBar', {pascalCase: true}), 'FooBar');
t.is(camelCase('fooBar-baz', {pascalCase: true}), 'FooBarBaz');
t.is(camelCase('foìBar-baz', {pascalCase: true}), 'FoìBarBaz');
t.is(camelCase('fooBarBaz-bazzy', {pascalCase: true}), 'FooBarBazBazzy');
t.is(camelCase('FBBazzy', {pascalCase: true}), 'FbBazzy');
t.is(camelCase('F', {pascalCase: true}), 'F');
t.is(camelCase('FooBar', {pascalCase: true}), 'FooBar');
t.is(camelCase('Foo', {pascalCase: true}), 'Foo');
t.is(camelCase('FOO', {pascalCase: true}), 'Foo');
t.is(camelCase(['foo', 'bar'], {pascalCase: true}), 'FooBar');
t.is(camelCase(['foo', '-bar'], {pascalCase: true}), 'FooBar');
t.is(camelCase(['foo', '-bar', 'baz'], {pascalCase: true}), 'FooBarBaz');
t.is(camelCase(['', ''], {pascalCase: true}), '');
t.is(camelCase('--', {pascalCase: true}), '');
t.is(camelCase('', {pascalCase: true}), '');
t.is(camelCase('--__--_--_', {pascalCase: true}), '');
t.is(camelCase(['---_', '--', '', '-_- '], {pascalCase: true}), '');
t.is(camelCase('foo bar?', {pascalCase: true}), 'FooBar?');
t.is(camelCase('foo bar!', {pascalCase: true}), 'FooBar!');
t.is(camelCase('foo bar$', {pascalCase: true}), 'FooBar$');
t.is(camelCase('foo-bar#', {pascalCase: true}), 'FooBar#');
t.is(camelCase('XMLHttpRequest', {pascalCase: true}), 'XmlHttpRequest');
t.is(camelCase('AjaxXMLHttpRequest', {pascalCase: true}), 'AjaxXmlHttpRequest');
t.is(camelCase('Ajax-XMLHttpRequest', {pascalCase: true}), 'AjaxXmlHttpRequest');
t.is(camelCase([], {pascalCase: true}), '');
t.is(camelCase('mGridCol6@md', {pascalCase: true}), 'MGridCol6@md');
t.is(camelCase('A::a', {pascalCase: true}), 'A::a');
t.is(camelCase('Hello1World', {pascalCase: true}), 'Hello1World');
t.is(camelCase('Hello11World', {pascalCase: true}), 'Hello11World');
t.is(camelCase('hello1world', {pascalCase: true}), 'Hello1World');
t.is(camelCase('hello1World', {pascalCase: true}), 'Hello1World');
t.is(camelCase('hello1', {pascalCase: true}), 'Hello1');
t.is(camelCase('Hello1', {pascalCase: true}), 'Hello1');
t.is(camelCase('1hello', {pascalCase: true}), '1Hello');
t.is(camelCase('1Hello', {pascalCase: true}), '1Hello');
t.is(camelCase('h1W', {pascalCase: true}), 'H1W');
t.is(camelCase('РозовыйПушистыйЕдинороги', {pascalCase: true}), 'РозовыйПушистыйЕдинороги');
t.is(camelCase('розовый_пушистый-единороги', {pascalCase: true}), 'РозовыйПушистыйЕдинороги');
t.is(camelCase('РОЗОВЫЙ_ПУШИСТЫЙ-ЕДИНОРОГИ', {pascalCase: true}), 'РозовыйПушистыйЕдинороги');
t.is(camelCase('桑德在这里。', {pascalCase: true}), '桑德在这里。');
t.is(camelCase('桑德_在这里。', {pascalCase: true}), '桑德在这里。');
});
test('invalid input', t => {
t.throws(() => {
camelCase(1);
}, /Expected the input to be/);
});