|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { |
| 3 | + HTML_BODY_CSS_HEIGHT_FIRST_RE, |
| 4 | + HTML_BODY_CSS_WIDTH_FIRST_RE, |
| 5 | + VIEWPORT_META_SIZE_RE, |
| 6 | +} from "./canvasScaffoldPatterns.js"; |
| 7 | + |
| 8 | +// Both callers key off group numbers: @hyperframes/lint's |
| 9 | +// root_dimensions_mismatch reads the digits, @hyperframes/cli's |
| 10 | +// applyResolutionPreset substitutes `$1<new>$3<new>` to keep the text around |
| 11 | +// them. Pin the layout here so neither can renumber against the other. |
| 12 | +const CASES = [ |
| 13 | + { |
| 14 | + name: "HTML_BODY_CSS_WIDTH_FIRST_RE", |
| 15 | + re: HTML_BODY_CSS_WIDTH_FIRST_RE, |
| 16 | + source: "html, body { margin: 0; width: 1920px; height: 1080px; overflow: hidden; }", |
| 17 | + digits: ["1920", "1080"], |
| 18 | + replacement: "$13840px$32160px", |
| 19 | + replaced: "html, body { margin: 0; width: 3840px; height: 2160px; overflow: hidden; }", |
| 20 | + }, |
| 21 | + { |
| 22 | + name: "HTML_BODY_CSS_HEIGHT_FIRST_RE", |
| 23 | + re: HTML_BODY_CSS_HEIGHT_FIRST_RE, |
| 24 | + source: "html, body { margin: 0; height: 1080px; width: 1920px; overflow: hidden; }", |
| 25 | + digits: ["1080", "1920"], |
| 26 | + replacement: "$12160px$33840px", |
| 27 | + replaced: "html, body { margin: 0; height: 2160px; width: 3840px; overflow: hidden; }", |
| 28 | + }, |
| 29 | + { |
| 30 | + name: "VIEWPORT_META_SIZE_RE", |
| 31 | + re: VIEWPORT_META_SIZE_RE, |
| 32 | + source: '<meta name="viewport" content="width=1920, height=1080" />', |
| 33 | + digits: ["1920", "1080"], |
| 34 | + replacement: "$13840$32160", |
| 35 | + replaced: '<meta name="viewport" content="width=3840, height=2160" />', |
| 36 | + }, |
| 37 | +]; |
| 38 | + |
| 39 | +describe("canvas scaffold patterns", () => { |
| 40 | + it.each(CASES)("$name exposes the two dimensions as groups 2 and 4", ({ re, source, digits }) => { |
| 41 | + const match = source.match(re); |
| 42 | + expect(match).not.toBeNull(); |
| 43 | + expect(match?.slice(1)).toHaveLength(4); |
| 44 | + expect([match?.[2], match?.[4]]).toEqual(digits); |
| 45 | + }); |
| 46 | + |
| 47 | + it.each(CASES)( |
| 48 | + "$name replaces both dimensions in place, leaving the rest untouched", |
| 49 | + ({ re, source, replacement, replaced }) => { |
| 50 | + expect(source.replace(re, replacement)).toBe(replaced); |
| 51 | + }, |
| 52 | + ); |
| 53 | +}); |
0 commit comments