-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_name.test.ts
46 lines (35 loc) · 1.12 KB
/
parse_name.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
import { assertEquals } from "testing/asserts.ts";
import { parseName } from "./parse_name.ts";
Deno.test("parseName, single", () => {
assertEquals(parseName(""), [""]); // empty
assertEquals(parseName("hello"), ["hello"]);
assertEquals(parseName("hello]..."), ["hello]"]); // warning
});
Deno.test("parseName, array", () => {
assertEquals(parseName("[]"), ["", null]);
assertEquals(parseName("hello[1]"), ["hello", 1]);
assertEquals(parseName("hello[]"), ["hello", null]);
assertEquals(parseName("hello[1][2][3]"), ["hello", 1, 2, 3]);
assertEquals(parseName("hello[world][foo][bar]"), [
"hello",
"world",
"foo",
"bar",
]);
assertEquals(parseName("hello[world][3][foo][2][bar]"), [
"hello",
"world",
3,
"foo",
2,
"bar",
]);
});
Deno.test("parseName, object", () => {
assertEquals(parseName("hello.foo"), ["hello", "foo"]);
assertEquals(parseName("hello.foo.bar"), ["hello", "foo", "bar"]);
});
Deno.test("parseName, complex", () => {
assertEquals(parseName("hello[].foo"), ["hello", null, "foo"]);
assertEquals(parseName("hello.foo.bar"), ["hello", "foo", "bar"]);
});