Nested paste fonts, held to the shared vectors on native
feat/fonts 66662d3 lets an inner font-family that maps to the default, or to nothing, clear the outer font on the web. fixtures/vectors/ font-stacks.json gains a "nested" list for it: [outer, inner or null for a span with no font-family, the inner text's family]. Calibri or Wingdings inside Inter is Carlito with no mark, Cambria inside Inter is Caladea, a bare span keeps Inter. The web's own vector test reads only "cases" and still passes. Native DocsHTMLClipboard already behaved this way: any explicit font-family clears the inherited font marks and sets only a non-default family. So testNestedPastedFontsFollowTheSharedVectors passed on arrival, and was shown to fail under two mutations instead: clearing only when the inner stack maps to a non-default family (Inter > Calibri, Inter > Wingdings and Georgia > sans-serif kept the outer font), and clearing on any span (Inter > a bare span lost Inter). testSharedFontStackVectors now expects at least the 23 shared cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+37
−1
native/apple/Tests/DocsKitTests/DocsFontPickerTests.swift+37 −1
CI passed — run details
diff --git a/native/apple/Tests/DocsKitTests/DocsFontPickerTests.swift b/native/apple/Tests/DocsKitTests/DocsFontPickerTests.swift| index cff8c65..63ab1f4 100644 |
| --- a/native/apple/Tests/DocsKitTests/DocsFontPickerTests.swift |
| +++ b/native/apple/Tests/DocsKitTests/DocsFontPickerTests.swift |
| @@ -105,7 +105,7 @@ final class DocsFontPickerTests: XCTestCase { |
| let url = DocsFontsTests.repository.appendingPathComponent("fixtures/vectors/font-stacks.json") |
| let json = try XCTUnwrap(try JSONSerialization.jsonObject(with: Data(contentsOf: url)) as? [String: Any]) |
| let cases = try XCTUnwrap(json["cases"] as? [[Any]]) |
| - XCTAssertEqual(cases.count, 18) |
| + XCTAssertGreaterThanOrEqual(cases.count, 23) |
| for pair in cases { |
| let stack = try XCTUnwrap(pair.first as? String) |
| let expected = pair.last as? String |
| @@ -113,6 +113,42 @@ final class DocsFontPickerTests: XCTestCase { |
| } |
| } |
| + /// Nested paste, against the shared vectors' "nested" cases: an inner |
| + /// font-family that maps to the default or to nothing clears the outer |
| + /// font, one that maps to another family replaces it, and a span with no |
| + /// font-family keeps the outer font, as the web's parse rule does. |
| + @MainActor func testNestedPastedFontsFollowTheSharedVectors() throws { |
| + let url = DocsFontsTests.repository.appendingPathComponent("fixtures/vectors/font-stacks.json") |
| + let json = try XCTUnwrap(try JSONSerialization.jsonObject(with: Data(contentsOf: url)) as? [String: Any]) |
| + let cases = try XCTUnwrap(json["nested"] as? [[Any]]) |
| + XCTAssertGreaterThanOrEqual(cases.count, 8) |
| + func attribute(_ stack: String) -> String { "font-family: " + stack.replacingOccurrences(of: "\"", with: """) } |
| + for pair in cases { |
| + let outer = try XCTUnwrap(pair[0] as? String), inner = pair[1] as? String, expected = pair[2] as? String |
| + let innerOpen = inner.map { "<span style=\"\(attribute($0))\">" } ?? "<span>" |
| + let html = "<p><span style=\"\(attribute(outer))\">Outer \(innerOpen)Inner</span></span></p>" |
| + let runs = Self.runs(DocsHTMLClipboard.blocks(html)) |
| + let run = try XCTUnwrap(runs.first { $0.text.contains("Inner") }, html) |
| + let fonts = run.marks.keys.filter { $0.hasPrefix("font_") }.sorted() |
| + XCTAssertEqual(fonts, expected.map { ["font_" + $0] } ?? [], "\(outer) > \(inner ?? "(no font-family)")") |
| + } |
| + } |
| + static func runs(_ blocks: [JSONValue]) -> [(text: String, marks: [String: JSONValue])] { |
| + var out: [(String, [String: JSONValue])] = [] |
| + func walk(_ value: JSONValue) { |
| + guard case .object(let node) = value else { return } |
| + if case .array(let runs)? = node["runs"] { |
| + for case .object(let run) in runs { |
| + guard case .string(let text)? = run["insert"] else { continue } |
| + if case .object(let marks)? = run["marks"] { out.append((text, marks)) } else { out.append((text, [:])) } |
| + } |
| + } |
| + if case .array(let children)? = node["children"] { children.forEach(walk) } |
| + } |
| + blocks.forEach(walk) |
| + return out |
| + } |
| + |
| /// A run copied out of web Docs names its private face first, then that |
| /// family's fallback stack (internal/fonts' generated stylesheet). The |
| /// private name decides: Source Sans 3's fallbacks start with Segoe UI, |