|
1 | 1 | /** |
2 | | - * Named slots tests — Tiers NS-A through NS-G. |
| 2 | + * Named slots tests — Tiers NS-A through NS-H. |
3 | 3 | * |
4 | 4 | * Covers slot partitioning, content substitution, expansion integration, |
5 | | - * slot prop reservation, renderChildren interaction, edge cases, and |
6 | | - * boundary scanner confirmation. |
| 5 | + * slot prop reservation, renderChildren interaction, edge cases, |
| 6 | + * boundary scanner confirmation, and nested projection points. |
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import { describe, it, beforeAll } from "@executablemd/test-support/bdd"; |
@@ -162,10 +162,6 @@ function cleanup(dir: string): void { |
162 | 162 | fs.rmSync(dir, { recursive: true, force: true }); |
163 | 163 | } |
164 | 164 |
|
165 | | -// ═══════════════════════════════════════════════════════════════════════════ |
166 | | -// Tier NS-A — Slot partitioning (unit) |
167 | | -// ═══════════════════════════════════════════════════════════════════════════ |
168 | | - |
169 | 165 | describe("Tier NS-A — Slot partitioning", () => { |
170 | 166 | // deno-lint-ignore require-yield |
171 | 167 | it("NS-A1: no slot props — all in default", function* () { |
@@ -268,10 +264,6 @@ describe("Tier NS-A — Slot partitioning", () => { |
268 | 264 | }); |
269 | 265 | }); |
270 | 266 |
|
271 | | -// ═══════════════════════════════════════════════════════════════════════════ |
272 | | -// Tier NS-B — Content substitution (unit) |
273 | | -// ═══════════════════════════════════════════════════════════════════════════ |
274 | | - |
275 | 267 | describe("Tier NS-B — Content substitution", () => { |
276 | 268 | it("NS-B1: backward compat — no slots anywhere", function* () { |
277 | 269 | const layout = makeComponent("Layout", "before\n<Content />\nafter"); |
@@ -410,10 +402,6 @@ describe("Tier NS-B — Content substitution", () => { |
410 | 402 | }); |
411 | 403 | }); |
412 | 404 |
|
413 | | -// ═══════════════════════════════════════════════════════════════════════════ |
414 | | -// Tier NS-C — Expansion integration |
415 | | -// ═══════════════════════════════════════════════════════════════════════════ |
416 | | - |
417 | 405 | describe("Tier NS-C — Expansion integration", () => { |
418 | 406 | it("NS-C1: basic named slot expansion", function* () { |
419 | 407 | const report = makeComponent( |
@@ -617,10 +605,6 @@ describe("Tier NS-C — Expansion integration", () => { |
617 | 605 | }); |
618 | 606 | }); |
619 | 607 |
|
620 | | -// ═══════════════════════════════════════════════════════════════════════════ |
621 | | -// Tier NS-D — slot prop reservation |
622 | | -// ═══════════════════════════════════════════════════════════════════════════ |
623 | | - |
624 | 608 | describe("Tier NS-D — slot prop reservation", () => { |
625 | 609 | it("NS-D1: slot in props frontmatter → error", function* () { |
626 | 610 | const { props } = parseFrontmatter({ |
@@ -691,10 +675,6 @@ describe("Tier NS-D — slot prop reservation", () => { |
691 | 675 | }); |
692 | 676 | }); |
693 | 677 |
|
694 | | -// ═══════════════════════════════════════════════════════════════════════════ |
695 | | -// Tier NS-E — renderChildren() interaction |
696 | | -// ═══════════════════════════════════════════════════════════════════════════ |
697 | | - |
698 | 678 | describe("Tier NS-E — renderChildren interaction", () => { |
699 | 679 | beforeAll(() => useTempFileCompiler()); |
700 | 680 | it("NS-E1: renderChildren includes all slots", function* () { |
@@ -814,10 +794,6 @@ describe("Tier NS-E — renderChildren interaction", () => { |
814 | 794 | }); |
815 | 795 | }); |
816 | 796 |
|
817 | | -// ═══════════════════════════════════════════════════════════════════════════ |
818 | | -// Tier NS-F — Edge cases |
819 | | -// ═══════════════════════════════════════════════════════════════════════════ |
820 | | - |
821 | 797 | describe("Tier NS-F — Edge cases", () => { |
822 | 798 | it("NS-F1: slot on self-closing component", function* () { |
823 | 799 | const layout = makeComponent("Layout", '<Content slot="icon" />\n<Content />'); |
@@ -984,10 +960,6 @@ describe("Tier NS-F — Edge cases", () => { |
984 | 960 | }); |
985 | 961 | }); |
986 | 962 |
|
987 | | -// ═══════════════════════════════════════════════════════════════════════════ |
988 | | -// Tier NS-G — Boundary scanner (confirms no changes needed) |
989 | | -// ═══════════════════════════════════════════════════════════════════════════ |
990 | | - |
991 | 963 | describe("Tier NS-G — Boundary scanner", () => { |
992 | 964 | // deno-lint-ignore require-yield |
993 | 965 | it("NS-G1: slot parsed as string prop", function* () { |
@@ -1030,3 +1002,149 @@ describe("Tier NS-G — Boundary scanner", () => { |
1030 | 1002 | expect(segments[0]!.type).toBe("text"); |
1031 | 1003 | }); |
1032 | 1004 | }); |
| 1005 | + |
| 1006 | +describe("Tier NS-H — Nested projection points", () => { |
| 1007 | + it("NS-H1: inside another component invocation", function* () { |
| 1008 | + const echo = makeComponent("Echo", "ECHO(<Content />)"); |
| 1009 | + const host = makeComponent("Host", "<Echo>prefix <Content /> suffix</Echo>"); |
| 1010 | + const segments = scanSegments("<Host>MATERIAL</Host>"); |
| 1011 | + const expanded = yield* expandAll(segments, { Echo: echo, Host: host }); |
| 1012 | + expect(renderSegments(expanded)).toContain("ECHO(prefix MATERIAL suffix)"); |
| 1013 | + }); |
| 1014 | + |
| 1015 | + it("NS-H2: several levels deep", function* () { |
| 1016 | + const inner = makeComponent("Inner", "IN(<Content />)"); |
| 1017 | + const outer = makeComponent("Outer", "OUT{<Content />}"); |
| 1018 | + const host = makeComponent("Host", "<Outer><Inner>deep <Content /></Inner></Outer>"); |
| 1019 | + const segments = scanSegments("<Host>MATERIAL</Host>"); |
| 1020 | + const expanded = yield* expandAll(segments, { Inner: inner, Outer: outer, Host: host }); |
| 1021 | + expect(renderSegments(expanded)).toContain("OUT{IN(deep MATERIAL)}"); |
| 1022 | + }); |
| 1023 | + |
| 1024 | + it("NS-H3: named slot in a nested position", function* () { |
| 1025 | + const echo = makeComponent("Echo", "ECHO(<Content />)"); |
| 1026 | + const host = makeComponent("Host", '<Echo><Content slot="header" /></Echo>\n\n<Content />'); |
| 1027 | + const headerComp = makeComponent("Header", "HEADER-TEXT"); |
| 1028 | + const segments = scanSegments('<Host>\n<Header slot="header" />\ndefault text\n</Host>'); |
| 1029 | + const expanded = yield* expandAll(segments, { Echo: echo, Host: host, Header: headerComp }); |
| 1030 | + const output = renderSegments(expanded); |
| 1031 | + expect(output).toContain("ECHO(HEADER-TEXT)"); |
| 1032 | + expect(output).toContain("default text"); |
| 1033 | + expect(output.indexOf("ECHO(HEADER-TEXT)")).toBeLessThan(output.indexOf("default text")); |
| 1034 | + }); |
| 1035 | + |
| 1036 | + it("NS-H4: two projections at different depths receive the same content", function* () { |
| 1037 | + const echo = makeComponent("Echo", "ECHO(<Content />)"); |
| 1038 | + const host = makeComponent("Host", "top: <Content />\n\n<Echo><Content /></Echo>"); |
| 1039 | + const segments = scanSegments("<Host>MATERIAL</Host>"); |
| 1040 | + const expanded = yield* expandAll(segments, { Echo: echo, Host: host }); |
| 1041 | + const output = renderSegments(expanded); |
| 1042 | + expect(output).toContain("top: MATERIAL"); |
| 1043 | + expect(output).toContain("ECHO(MATERIAL)"); |
| 1044 | + }); |
| 1045 | + |
| 1046 | + it("NS-H5: nested inside a top-level <Output> region", function* () { |
| 1047 | + const echo = makeComponent("Echo", "ECHO(<Content />)"); |
| 1048 | + const host = makeComponent("Host", "<Output><Echo><Content /></Echo></Output>"); |
| 1049 | + const segments = scanSegments("<Host>MATERIAL</Host>"); |
| 1050 | + const expanded = yield* expandAll(segments, { Echo: echo, Host: host }); |
| 1051 | + expect(renderSegments(expanded)).toContain("ECHO(MATERIAL)"); |
| 1052 | + }); |
| 1053 | + |
| 1054 | + it("NS-H6: slot validation errors are still emitted once", function* () { |
| 1055 | + const echo = makeComponent("Echo", "ECHO(<Content />)"); |
| 1056 | + const host = makeComponent("Host", "<Echo><Content /></Echo>\nsecond: <Content />"); |
| 1057 | + const bad = makeComponent("Bad", "BAD"); |
| 1058 | + const segments = scanSegments('<Host>\n<Bad slot="123invalid" />\n</Host>'); |
| 1059 | + const expanded = yield* expandAll(segments, { Echo: echo, Host: host, Bad: bad }); |
| 1060 | + const errors = expanded.filter((segment) => segment.type === "error"); |
| 1061 | + expect(errors).toHaveLength(1); |
| 1062 | + }); |
| 1063 | + |
| 1064 | + it("NS-H7: nested inside a structural construct", function* () { |
| 1065 | + const tmpDir = makeTempDir(); |
| 1066 | + try { |
| 1067 | + writeFiles(tmpDir, { |
| 1068 | + "components/HostCap.md": [ |
| 1069 | + "---", |
| 1070 | + "props: { type: object, properties: {}, additionalProperties: false }", |
| 1071 | + "---", |
| 1072 | + '<Capture as="c">captured: <Content /></Capture>', |
| 1073 | + "<Output>host got: {c}</Output>", |
| 1074 | + ].join("\n"), |
| 1075 | + "doc.md": "<HostCap>MATERIAL</HostCap>", |
| 1076 | + }); |
| 1077 | + const output = yield* collect( |
| 1078 | + yield* execute({ |
| 1079 | + path: path.join(tmpDir, "doc.md"), |
| 1080 | + stream: new InMemoryStream(), |
| 1081 | + componentDirs: [path.join(tmpDir, "components"), tmpDir], |
| 1082 | + }), |
| 1083 | + ); |
| 1084 | + expect(output).toContain("host got: captured: MATERIAL"); |
| 1085 | + } finally { |
| 1086 | + cleanup(tmpDir); |
| 1087 | + } |
| 1088 | + }); |
| 1089 | + |
| 1090 | + it("NS-H8: nested inside an iterating construct", function* () { |
| 1091 | + const tmpDir = makeTempDir(); |
| 1092 | + try { |
| 1093 | + writeFiles(tmpDir, { |
| 1094 | + "components/EachHost.md": [ |
| 1095 | + "---", |
| 1096 | + "props: { type: object, properties: {}, additionalProperties: false }", |
| 1097 | + "---", |
| 1098 | + '<Each in={[1, 2]} let="n">', |
| 1099 | + "item {n}: <Content />", |
| 1100 | + "</Each>", |
| 1101 | + ].join("\n"), |
| 1102 | + "doc.md": "<EachHost>MATERIAL</EachHost>", |
| 1103 | + }); |
| 1104 | + const output = yield* collect( |
| 1105 | + yield* execute({ |
| 1106 | + path: path.join(tmpDir, "doc.md"), |
| 1107 | + stream: new InMemoryStream(), |
| 1108 | + componentDirs: [path.join(tmpDir, "components"), tmpDir], |
| 1109 | + }), |
| 1110 | + ); |
| 1111 | + expect(output).toContain("item 1: MATERIAL"); |
| 1112 | + expect(output).toContain("item 2: MATERIAL"); |
| 1113 | + } finally { |
| 1114 | + cleanup(tmpDir); |
| 1115 | + } |
| 1116 | + }); |
| 1117 | + |
| 1118 | + it("NS-H9: an unclaimed <Content /> stays reserved through a nested wrapper", function* () { |
| 1119 | + const echo = makeComponent("Echo", "ECHO(<Content />)"); |
| 1120 | + const host = makeComponent("Host", "<Echo><Content /></Echo>"); |
| 1121 | + // Written in the document, where nothing projects: no invocation resolved |
| 1122 | + // it, so passing it through two nested bodies must not make it mean one. |
| 1123 | + const segments = scanSegments("<Host><Content /></Host>"); |
| 1124 | + const expanded = yield* expandAll(segments, { Echo: echo, Host: host }); |
| 1125 | + const errors = expanded.filter((segment) => segment.type === "error"); |
| 1126 | + expect(errors).toHaveLength(1); |
| 1127 | + expect(errors[0]!.message).toContain("<Content> is reserved"); |
| 1128 | + }); |
| 1129 | + |
| 1130 | + it("NS-H10: a wrapped projection reaches a nested invocation's named slot", function* () { |
| 1131 | + const layout = makeComponent("Layout", 'LAYOUT(<Content slot="header" />)'); |
| 1132 | + const section = makeComponent("Section", "<Content />"); |
| 1133 | + const host = makeComponent( |
| 1134 | + "Host", |
| 1135 | + '<Layout><Section slot="header"><Content slot="header" /></Section></Layout>', |
| 1136 | + ); |
| 1137 | + const headerComp = makeComponent("Header", "HEADER-TEXT"); |
| 1138 | + const segments = scanSegments('<Host>\n<Header slot="header" />\ndefault text\n</Host>'); |
| 1139 | + const expanded = yield* expandAll(segments, { |
| 1140 | + Layout: layout, |
| 1141 | + Section: section, |
| 1142 | + Host: host, |
| 1143 | + Header: headerComp, |
| 1144 | + }); |
| 1145 | + const output = renderSegments(expanded); |
| 1146 | + expect(output).toContain("LAYOUT(HEADER-TEXT)"); |
| 1147 | + // Host's default slot is not projected, so nothing else rides along. |
| 1148 | + expect(output).not.toContain("default text"); |
| 1149 | + }); |
| 1150 | +}); |
0 commit comments