Skip to content

Commit ff5e0c9

Browse files
test(css,html): cover the source-map and list-item boundaries the printers changed
The map tests discriminate: dropping the retract-time mapping clear fails the first, and the beautify case pins the newline walk. The list-item cases assert the end-tag omission across a nested list and a table cell.
1 parent 155a154 commit ff5e0c9

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

‎test/HtmlSyntax.unittest.js‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5158,6 +5158,44 @@ describe("SourceProcessor — removeImpliedTags", () => {
51585158
).toBe("<body><!--c--><p>x");
51595159
});
51605160

5161+
// A `<li>` closes the item it is a sibling of, and no item held below a
5162+
// list-item-scope boundary — a list it nests into, or the cell it sits in.
5163+
describe("a later <li> against a list-item-scope boundary", () => {
5164+
/**
5165+
* @param {string} html the source
5166+
* @returns {string} the minified serialization
5167+
*/
5168+
const item = (html) =>
5169+
new SourceProcessor().process(html, {
5170+
mode: "minify",
5171+
removeImpliedTags: true
5172+
}).code;
5173+
5174+
it("omits the end tag of the item it is a sibling of", () => {
5175+
expect(item("<ul><li>a</li><li>b</li></ul>")).toBe("<ul><li>a<li>b</ul>");
5176+
expect(item("<li>a</li><li>b</li>")).toBe("<li>a<li>b");
5177+
});
5178+
5179+
it("keeps the end tag of an item the nested list holds", () => {
5180+
expect(item("<ul><li>a<ul><li>b</li></ul><li>c</li></ul>")).toBe(
5181+
"<ul><li>a<ul><li>b</ul><li>c</ul>"
5182+
);
5183+
});
5184+
5185+
it("keeps the end tag of an item another cell holds", () => {
5186+
expect(
5187+
item(
5188+
"<table><tr><td><ul><li>a</li></ul><td><ul><li>b</li></ul></table>"
5189+
)
5190+
).toBe("<table><tr><td><ul><li>a</ul><td><ul><li>b</ul></table>");
5191+
expect(
5192+
item(
5193+
"<table><tr><th><ol><li>a</li></ol><th><ol><li>b</li></ol></table>"
5194+
)
5195+
).toBe("<table><tr><th><ol><li>a</ol><th><ol><li>b</ol></table>");
5196+
});
5197+
});
5198+
51615199
it("keeps a <html> that carries an attribute", () => {
51625200
expect(
51635201
new SourceProcessor().process("<html lang=en><body>x", { mode: "minify" })

‎test/SourceProcessor.unittest.js‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,48 @@ describe("SourceProcessor", () => {
201201
});
202202
}
203203

204+
// The map is walked over the flat output, so a piece the print took back
205+
// takes its mapping with it and a newline still opens a generated line.
206+
describe("over the flat output", () => {
207+
// cspell:ignore CAIA
208+
209+
// The first declaration is the one the second overrides, so minifying
210+
// retracts the piece it was written into.
211+
const SOURCE =
212+
"a {\n color : red ;\n color : blue ;\n}\nb {\n color : lime ;\n}\n";
213+
214+
/**
215+
* @param {"minify" | "beautify"} mode how to print
216+
* @returns {{ code: string, mappings: string }} output and its mappings
217+
*/
218+
const printed = (mode) => {
219+
const { code, map } = new CssSourceProcessor().process(SOURCE, {
220+
mode,
221+
source: "in.css",
222+
content: SOURCE
223+
});
224+
return { code, mappings: map.mappings };
225+
};
226+
227+
it("drops the mapping of a piece the print took back", () => {
228+
// Two mappings, not three: the anchor written with `color:red` is gone,
229+
// and `b` still maps to its own line rather than to the dropped one.
230+
expect(printed("minify")).toEqual({
231+
code: "a{color:blue}b{color:lime}",
232+
mappings: "AAAA,aAIA"
233+
});
234+
});
235+
236+
it("counts a generated line for each newline the output holds", () => {
237+
// `;;;` is the three line breaks before `b`, found in the flat output
238+
// rather than in the pieces it was built from.
239+
expect(printed("beautify")).toEqual({
240+
code: "a {\ncolor: red;\ncolor: blue;\n}b {\ncolor: lime;\n}",
241+
mappings: "AAAA;;;CAIA"
242+
});
243+
});
244+
});
245+
204246
// A prefixed rule an unprefixed twin makes dead weight is taken back after
205247
// it was written, so the mapping anchored to it has to go with it.
206248
it("css anchors nothing at a rule the prefix pass took back", () => {

0 commit comments

Comments
 (0)