-
Notifications
You must be signed in to change notification settings - Fork 0
/
string-checkers.spec.ts
150 lines (142 loc) · 6.38 KB
/
string-checkers.spec.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
import { expect } from "chai";
import "mocha";
import { MockData } from "../MockData";
import * as StringCheckers from "./string-checkers";
describe("StringCheckers", () => {
describe("IsCamelCase", () => {
it("It should return true if string is camel case", () => {
[
...MockData.lowerCamelCase,
...MockData.upperCamelCase,
].forEach((text) => {
expect(StringCheckers.isCamelCase(text), `${text} is valid CamelCase`).to.be.true;
});
[
...MockData.lowerSnakeCase,
...MockData.upperSnakeCase,
"HELLO_my_name_is_ChuaN",
].forEach((text) => {
expect(StringCheckers.isCamelCase(text), `${text} is not valid CamelCase`).to.be.false;
});
});
});
describe("IsUpperCamelCase", () => {
it("It should return true if string is upper camel case", () => {
MockData.upperCamelCase.forEach((text) => {
expect(StringCheckers.isUpperCamelCase(text), `${text} is valid UpperCamelCase`).to.be.true;
});
[
...MockData.lowerCamelCase,
...MockData.lowerSnakeCase,
...MockData.upperSnakeCase,
"HELLO_my_name_is_ChuaN",
].forEach((text) => {
expect(StringCheckers.isUpperCamelCase(text), `${text} is not valid UpperCamelCase`).to.be.false;
});
});
});
describe("IsLowerCamelCase", () => {
it("It should return true if string is lower camel case", () => {
MockData.lowerCamelCase.forEach((text) => {
expect(StringCheckers.isLowerCamelCase(text), `${text} is valid LowerCamelCase`).to.be.true;
});
[
...MockData.upperCamelCase,
...MockData.lowerSnakeCase,
...MockData.upperSnakeCase,
"HELLO_my_name_is_ChuaN",
].forEach((text) => {
expect(StringCheckers.isLowerCamelCase(text), `${text} is valid LowerCamelCase`).to.be.false;
});
});
});
describe("IsSnakeCase", () => {
it("It should return true if string is snake case", () => {
[
...MockData.lowerSnakeCase,
...MockData.upperSnakeCase,
"HELLO_my_name_is_ChuaN",
].forEach((text) => {
expect(StringCheckers.isSnakeCase(text), `${text} is valid SnakeCase`).to.be.true;
});
[
...MockData.lowerCamelCase,
...MockData.upperCamelCase,
].forEach((text) => {
expect(StringCheckers.isSnakeCase(text), `${text} is not valid SnakeCase`).to.be.false;
});
});
});
describe("IsUpperSnakeCase", () => {
it("It should return true if string is upper snake case", () => {
MockData.upperSnakeCase.forEach((text) => {
expect(StringCheckers.isUpperSnakeCase(text), `${text} is valid UpperSnakeCase`).to.be.true;
});
[
...MockData.lowerSnakeCase,
...MockData.lowerCamelCase,
...MockData.upperCamelCase,
].forEach((text) => {
expect(StringCheckers.isUpperSnakeCase(text), `${text} is valid LowerSnakeCase`).to.be.false;
});
});
});
describe("IsLowerSnakeCase", () => {
it("It should return true if string is lower snake case", () => {
MockData.lowerSnakeCase.forEach((text) => {
expect(StringCheckers.isLowerSnakeCase(text), `${text} is valid LowerSnakeCase`).to.be.true;
});
[
...MockData.upperSnakeCase,
...MockData.lowerCamelCase,
...MockData.upperCamelCase,
].forEach((text) => {
expect(StringCheckers.isLowerSnakeCase(text), `${text} is not valid LowerSnakeCase`).to.be.false;
});
});
});
describe("IsTimeFormat", () => {
it("It should return true if time is in HH:mm formatTime", () => {
MockData.timesHHmm.forEach((time) => {
expect(StringCheckers.isTimeFormat(time, "HH:mm"), `time ${time} is in HH:mm:ss format`).to.be.true;
});
[...MockData.timesHHmmss, ...MockData.timesHmm].forEach((time) => {
expect(StringCheckers.isTimeFormat(time, "HH:mm"), `'${time}' is not valid time in HH:mm format`).to.be.false;
});
});
it("It should return true if time is in H:mm formatTime", () => {
MockData.timesHmm.forEach((time) => {
expect(StringCheckers.isTimeFormat(time, "H:mm"), `time ${time} is in H:mm:ss format`).to.be.true;
});
[...MockData.timesHHmmss].forEach((time) => {
expect(StringCheckers.isTimeFormat(time, "H:mm"), `'${time}' is not valid time in H:mm format`).to.be.false;
});
});
it("It should return true if time is in HH:mm:ss formatTime", () => {
MockData.timesHHmmss.forEach((time) => {
expect(StringCheckers.isTimeFormat(time, "HH:mm:ss"), `time ${time} is in HH:mm:ss format`).to.be.true;
});
[...MockData.timesHmm, ...MockData.timesHHmm].forEach((time) => {
expect(StringCheckers.isTimeFormat(time, "HH:mm:ss"), `'${time}' is not valid time in HH:mm:ss format`).to.be.false;
});
});
it("It should return true if time is in required formatTime", () => {
expect(StringCheckers.isTimeFormat("9:9", "H:m")).to.be.true;
expect(StringCheckers.isTimeFormat("9:09:09", "HH:mm:ss")).to.be.false;
expect(StringCheckers.isTimeFormat("1:59:59", "HH:mm:ss")).to.be.false;
expect(StringCheckers.isTimeFormat("9:9:9", "HH:mm:ss")).to.be.false;
});
it("It should return false if string is invalid time formatTime", () => {
MockData.invalidTimes.forEach((time) => {
[
"HH:mm:ss",
"HH:mm",
"H:mm",
"H:m",
].forEach((format) => {
expect(StringCheckers.isTimeFormat(time, format), `'${time}' is not valid time in ${format} format`).to.be.false;
});
});
});
});
});