-
Notifications
You must be signed in to change notification settings - Fork 8
/
tests.gr
90 lines (84 loc) · 2.07 KB
/
tests.gr
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
import String from "string"
import Process from "sys/process"
import File from "sys/file"
import Env from "./lib/env"
import Util from "./lib/stringutil"
import Mediatype from "./lib/mediatype"
let mut totalErr = 0
let check = (a, b, msg: String) => {
match (a == b) {
true => Ok(String.concat("✅ PASS\t\t", msg)),
false => {
totalErr += 1
print("===== Expected: =====")
print(a)
print("======= Got: ========")
print(b)
print("=====================")
Err(String.concat("⛔️ FAIL\t\t", msg))
},
}
}
let expect = (a, b, msg: String) => {
match (check(a, b, msg)) {
Ok(yay) => print(yay),
Err(e) => print(e),
}
}
let report = () => {
if (totalErr > 0) {
File.fdWrite(File.stderr, "❌ Total failed tests: ")
File.fdWrite(File.stderr, toString(totalErr))
File.fdWrite(File.stderr, "❌\n")
Process.exit(1)
void
}
}
expect(("a", "b"), Env.splitEnvVar("a=b"), "Env.splitEnvVar should parse")
expect("gfedcba", Util.reverse("abcdefg"), "Util.reverse should reverse string")
expect(
Some(5),
Util.lastIndexOf("/.", "aaaa/."),
"Util.lastIndexOf should find Some",
)
expect(
Some(18),
Util.lastIndexOf(".", "aaaa/fileserver.gr.wasm"),
"Util.lastIndexOf should find last dot, not first dot",
)
expect(
Some(12),
Util.lastIndexOf(".", "/.../aaaa/..."),
"Util.lastIndexOf should find last set of three dots",
)
expect(
None,
Util.lastIndexOf("??", "aaaa.."),
"Util.lastIndexOf should find None",
)
expect(
"test",
Util.afterLast("$.$", "foo$.$bar$.$test"),
"Util.afterLast should find last match",
)
expect(
"/prefix/../path",
Util.beforeLast("/..", "/prefix/../path/.."),
"Util.beforeLast should return first part",
)
expect(
"/prefix/../path/..",
Util.beforeLast("/$$", "/prefix/../path/.."),
"Util.beforeLast should return entire string when no match",
)
expect(
"text/plain",
Mediatype.guess("foo.txt"),
"Mediatype.guess should find text/plain",
)
expect(
"application/octet-stream",
Mediatype.guess("foo.MADEUP"),
"Mediatype.guess should find default type",
)
report()