-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathscule.test.ts
160 lines (149 loc) · 3.86 KB
/
scule.test.ts
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { describe, test, expect } from "vitest";
import {
splitByCase,
pascalCase,
kebabCase,
camelCase,
upperFirst,
lowerFirst,
snakeCase,
trainCase,
flatCase,
titleCase,
} from "../src";
describe("splitByCase", () => {
test.each([
["", []],
["foo", ["foo"]],
["fooBar", ["foo", "Bar"]],
["FooBarBaz", ["Foo", "Bar", "Baz"]],
["FooBARb", ["Foo", "BA", "Rb"]],
["foo_bar-baz/qux", ["foo", "bar", "baz", "qux"]],
["foo--bar-Baz", ["foo", "", "bar", "Baz"]],
["FOO_BAR", ["FOO", "BAR"]],
["foo123-bar", ["foo123", "bar"]],
["FOOBar", ["FOO", "Bar"]],
["ALink", ["A", "Link"]],
// with custom splitters
[
"foo\\Bar.fuzz-FIZz",
["foo", "Bar", "fuzz", "FI", "Zz"],
["\\", ".", "-"],
],
["new-name-value", ["new-name-value"], ["_"]],
])("%s => %s", (input, expected, customSplitters?) => {
if (customSplitters) {
expect(splitByCase(input, customSplitters)).toMatchObject(expected);
} else {
expect(splitByCase(input)).toMatchObject(expected);
}
});
});
describe("pascalCase", () => {
test.each([
["", ""],
["foo", "Foo"],
["foo-bAr", "FooBAr"],
["FooBARb", "FooBaRb"],
["foo_bar-baz/qux", "FooBarBazQux"],
["FOO_BAR", "FooBar"],
["foo--bar-Baz", "FooBarBaz"],
])("%s => %s", (input, expected) => {
expect(pascalCase(input, { normalize: true })).toMatchObject(expected);
});
});
describe("camelCase", () => {
test.each([
["FooBarBaz", "fooBarBaz"],
["FOO_BAR", "fooBar"],
])("%s => %s", (input, expected) => {
expect(camelCase(input, { normalize: true })).toMatchObject(expected);
});
});
describe("kebabCase", () => {
test.each([
["", ""],
["foo", "foo"],
["foo/Bar", "foo-bar"],
["foo-bAr", "foo-b-ar"],
["foo--bar", "foo--bar"],
["FooBAR", "foo-bar"],
["ALink", "a-link"],
["FOO_BAR", "foo-bar"],
])("%s => %s", (input, expected) => {
expect(kebabCase(input)).toMatchObject(expected);
});
});
describe("snakeCase", () => {
test.each([
["FooBarBaz", "foo_bar_baz"],
["FOO_BAR", "foo_bar"],
])("%s => %s", (input, expected) => {
expect(snakeCase(input)).toMatchObject(expected);
});
});
describe("upperFirst", () => {
test.each([
["", ""],
["foo", "Foo"],
["Foo", "Foo"],
])("%s => %s", (input, expected) => {
expect(upperFirst(input)).toMatchObject(expected);
});
});
describe("lowerFirst", () => {
test.each([
["", ""],
["foo", "foo"],
["Foo", "foo"],
])("%s => %s", (input, expected) => {
expect(lowerFirst(input)).toMatchObject(expected);
});
});
describe("trainCase", () => {
test.each([
["", ""],
["f", "F"],
["foo", "Foo"],
["foo-bAr", "Foo-B-Ar"],
["AcceptCH", "Accept-CH"],
["foo_bar-baz/qux", "Foo-Bar-Baz-Qux"],
["FOO_BAR", "FOO-BAR"],
["foo--bar-Baz", "Foo-Bar-Baz"],
["WWW-authenticate", "WWW-Authenticate"],
["WWWAuthenticate", "WWW-Authenticate"],
])("%s => %s", (input, expected) => {
expect(trainCase(input)).toMatchObject(expected);
});
test.each([
["AcceptCH", "Accept-Ch"],
["FOO_BAR", "Foo-Bar"],
["WWW-authenticate", "Www-Authenticate"],
])("%s => %s", (input, expected) => {
expect(trainCase(input, { normalize: true })).toMatchObject(expected);
});
});
describe("titleCase", () => {
test.each([
["", ""],
["f", "F"],
["foo", "Foo"],
["foo-bar", "Foo Bar"],
["this-IS-aTitle", "This is a Title"],
])("%s => %s", (input, expected) => {
expect(titleCase(input)).toMatchObject(expected);
});
});
describe("flatCase", () => {
test.each([
["", ""],
["foo", "foo"],
["foo-bAr", "foobar"],
["FooBARb", "foobarb"],
["foo_bar-baz/qux", "foobarbazqux"],
["FOO_BAR", "foobar"],
["foo--bar-Baz", "foobarbaz"],
])("%s => %s", (input, expected) => {
expect(flatCase(input)).toMatchObject(expected);
});
});