-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.test.mjs
82 lines (71 loc) · 1.78 KB
/
info.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
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
import assert from "node:assert";
import { test } from "node:test";
import { parseInfo, renderInfo } from "./info.mjs";
test("finds tag", () => {
const spec = parseInfo("img");
assert.equal(spec.tag, "img");
});
test("finds id", () => {
const spec = parseInfo("#id");
assert.equal(spec.id, "id");
});
test("finds classes", () => {
const spec = parseInfo(".wide.bg");
assert.deepStrictEqual(spec.classes, ["bg", "wide"]);
});
test("finds attributes", () => {
const spec = parseInfo("[width=200px] [height=300px]");
assert.deepStrictEqual(spec.attributes, {
width: "200px",
height: "300px",
});
});
test("finds all", () => {
const spec = parseInfo("img #id .wide [width=200px][height=300px]");
assert.deepStrictEqual(spec, {
tag: "img",
id: "id",
classes: ["wide"],
attributes: { height: "300px", width: "200px" },
});
});
test("finds all mixed up", () => {
const spec = parseInfo(" #id.bg .wide [width=200px]img[height=300px]");
assert.deepStrictEqual(spec, {
tag: "img",
id: "id",
classes: ["bg", "wide"],
attributes: { height: "300px", width: "200px" },
});
});
test("accepts first found tag", () => {
const spec = parseInfo("attr img");
assert.equal(spec.tag, "attr");
});
test("img", () => {
const rendered = renderInfo(
{
tag: "img",
id: "id",
classes: ["bg", "wide"],
attributes: { height: "300px", width: "200px" },
},
"alt text"
);
assert.equal(
rendered,
`<img id="id" class="bg wide" height="300px" width="200px" alt="alt text" />`
);
});
test("span", () => {
const rendered = renderInfo(
{
tag: "span",
id: "",
classes: ["info"],
attributes: {},
},
"Informative"
);
assert.equal(rendered, `<span class="info">Informative</span>`);
});