-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
83 lines (77 loc) · 1.85 KB
/
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
import { parser } from "./parser";
import assert from "assert";
const tests = {
"parses single time ranges": () => {
const result = parser.parse("10:00am-11:00am");
assert.deepEqual(result, [
{
start: { hour: 10, minute: 0 },
end: { hour: 11, minute: 0 }
}
]);
},
"parses minutes": () => {
const result = parser.parse("10:35am-11:00am");
assert.deepEqual(result, [
{
start: { hour: 10, minute: 35 },
end: { hour: 11, minute: 0 }
}
]);
},
"parses sequences of time ranges": () => {
const result = parser.parse("8:00am-9:00am, 10:00am-11:00am");
assert.deepEqual(result, [
{
start: { hour: 8, minute: 0 },
end: { hour: 9, minute: 0 }
},
{
start: { hour: 10, minute: 0 },
end: { hour: 11, minute: 0 }
}
]);
},
"tolerates whitespace": () => {
const result = parser.parse(" 8:00am-9:00am , 10:00am-11:00am ");
assert.deepEqual(result, [
{
start: { hour: 8, minute: 0 },
end: { hour: 9, minute: 0 }
},
{
start: { hour: 10, minute: 0 },
end: { hour: 11, minute: 0 }
}
]);
}
};
const results = [];
let passing = 0;
let failing = 0;
for (const [test, testFn] of Object.entries(tests)) {
try {
testFn();
results.push({ passed: true, test });
passing++;
} catch (error) {
results.push({ passed: false, test: test, error });
failing++;
}
}
results.forEach((result, index) => {
const icon = result.passed ? "✅" : "🚨";
console.log(
`${icon} ${(index + 1)
.toString()
.padStart(results.length.toString().length, " ")}) ${result.test}`
);
if (result.error) {
console.log(result.error.message);
}
});
console.log(`${passing} Passing`);
console.log(`${failing} Failing`);
if (failing > 0) {
process.exit(1);
}