forked from denoland/std
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_util_test.ts
157 lines (138 loc) · 3.82 KB
/
_util_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
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert";
import { splitToWords } from "./_util.ts";
Deno.test({
name: "split() returns an empty array for an empty string",
fn() {
const result = splitToWords("");
assertEquals(result.length, 0);
},
});
Deno.test({
name:
"split() returns an empty array when input has no alphanumeric characters",
fn() {
const result = splitToWords("🦕♥️ 🦕♥️ 🦕♥️");
assertEquals(result.length, 0);
},
});
Deno.test({
name: "split() ignores non-alphanumeric characters mixed with words",
fn() {
const result = splitToWords("🦕deno♥️wuv");
const expected = ["deno", "wuv"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles whitespace",
fn() {
const result = splitToWords("deno Is AWESOME");
const expected = ["deno", "Is", "AWESOME"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles whitespace at string end and start",
fn() {
const result = splitToWords(" deno Is AWESOME ");
const expected = ["deno", "Is", "AWESOME"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles mixed delimiters",
fn() {
const result = splitToWords("I am up-to-date!");
const expected = ["I", "am", "up", "to", "date"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles a delimiter sequence",
fn() {
const result = splitToWords("I am -> thirsty!");
const expected = ["I", "am", "thirsty"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles upper case delimiter",
fn() {
const result = splitToWords("denoIsAwesome");
const expected = ["deno", "Is", "Awesome"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles hyphen delimiter",
fn() {
const result = splitToWords("deno-is-awesome");
const expected = ["deno", "is", "awesome"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles casing",
fn() {
const result = splitToWords("denoIsAwesome");
const expected = ["deno", "Is", "Awesome"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles unicode",
fn() {
const result = splitToWords("шруберри IsAwesome");
const expected = ["шруберри", "Is", "Awesome"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles unicode casing",
fn() {
const result = splitToWords("шруберриШруберри");
const expected = ["шруберри", "Шруберри"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles languages without casing",
fn() {
const result = splitToWords("אין_על דינו");
const expected = ["אין", "על", "דינו"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles screaming snake case",
fn() {
const result = splitToWords("DENO_IS_AWESOME");
const expected = ["DENO", "IS", "AWESOME"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles acronym followed by a capitalized word",
fn() {
const result = splitToWords("I Love HTMLDivElement");
const expected = ["I", "Love", "HTML", "Div", "Element"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles underscore delimiter",
fn() {
const result = splitToWords("deno_is_awesome");
const expected = ["deno", "is", "awesome"];
assertEquals(result, expected);
},
});
Deno.test({
name: "split() handles acronym followed by a capitalized word",
fn() {
const result = splitToWords("I Love HTMLDivElement");
const expected = ["I", "Love", "HTML", "Div", "Element"];
assertEquals(result, expected);
},
});