-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdeconstructJsdocNamepath.test.mjs
48 lines (42 loc) · 1.33 KB
/
deconstructJsdocNamepath.test.mjs
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
import { deepStrictEqual, throws } from "assert";
import deconstructJsdocNamepath from "./deconstructJsdocNamepath.mjs";
export default (tests) => {
tests.add(
"`deconstructJsdocNamepath` with argument 1 `namepath` not a string.",
() => {
throws(() => {
deconstructJsdocNamepath(undefined);
}, new TypeError("Argument 1 `namepath` must be a string."));
}
);
tests.add("`deconstructJsdocNamepath` with no nested members.", () => {
deepStrictEqual(deconstructJsdocNamepath("a"), {
memberof: undefined,
membership: undefined,
name: "a",
});
});
tests.add(
"`deconstructJsdocNamepath` with nested static, instance and inner members.",
() => {
deepStrictEqual(deconstructJsdocNamepath("a.B#c~d"), {
memberof: "a.B#c",
membership: "~",
name: "d",
});
}
);
tests.add("`deconstructJsdocNamepath` with a namepath prefix.", () => {
deepStrictEqual(deconstructJsdocNamepath("A#event:a"), {
memberof: "A",
membership: "#",
name: "event:a",
});
});
tests.add("`deconstructJsdocNamepath` with invalid namepaths.", () => {
for (const namepath of ["", "a..b", "a..b.c", "a."])
throws(() => {
deconstructJsdocNamepath(namepath);
}, new SyntaxError(`Invalid JSDoc namepath \`${namepath}\`.`));
});
};