oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1import Foundation
2import RastrilloApple
3import XCTest
4@testable import DocsKit
5
6final class DocumentAssetsTests: XCTestCase {
7 @MainActor func testRelativeImageURLsAndCachedImagesUseCurrentDocument() async throws {
8 let origin = try XCTUnwrap(URL(string: "https://example.com"))
9 XCTAssertEqual(DocsImageStore.resolvedURL(source: "picture.png", documentPath: "/d/first", origin: origin)?.absoluteString, "https://example.com/d/picture.png")
10 XCTAssertEqual(DocsImageStore.resolvedURL(source: "?picture=1", documentPath: "/d/second", origin: origin)?.absoluteString, "https://example.com/d/second?picture=1")
11 let client = NativeHTTP(origin: origin)
12 let store = DocsImageStore()
13 let source = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII="
14 await store.load(sources: [source], client: client, documentPath: "/d/first")
15 XCTAssertNotNil(store.images(forDocumentPath: "/d/first", client: client)[source])
16 XCTAssertTrue(store.images(forDocumentPath: "/d/second", client: client).isEmpty)
17 await store.load(sources: [], client: client, documentPath: "/d/second")
18 XCTAssertTrue(store.images.isEmpty)
19 }
20 /// The three Liberation families keep their marks; the default is
21 /// Carlito (DocsFontsTests covers all sixteen families).
22 @MainActor func testLiberationFacesResolveForTheirMarks() {
23 for (key, family) in [("font_sans", "Sans"), ("font_serif", "Serif"), ("font_mono", "Mono")] {
24 for (bold, italic, face) in [(false, false, "Regular"), (true, false, "Bold"), (false, true, "Italic"), (true, true, "BoldItalic")] {
25 var marks: [String: JSONValue] = [key: .object([:])]
26 if bold { marks["strong"] = .object([:]) }
27 if italic { marks["em"] = .object([:]) }
28 let font = DocsFonts.font(marks: marks, size: 12, heading: false)
29 XCTAssertEqual(font.fontName, "Liberation\(family)" + (face == "Regular" ? "" : "-\(face)"))
30 }
31 }
32 XCTAssertEqual(DocsFonts.font(marks: [:], size: 12, heading: false).fontName, "Carlito-Regular")
33 XCTAssertEqual(DocsFonts.font(marks: ["size_24": .object([:])], size: 12, heading: false).pointSize, 24)
34 }
35 @MainActor func testAttachmentsOccupyOneUTF16UnitAndInvalidImagesFail() {
36 XCTAssertEqual(DocsAttachments.image(nil, alt: "long image description").length, 1)
37 XCTAssertEqual(DocsAttachments.rule().length, 1)
38 XCTAssertNil(DocsAttachments.decode(Data("not an image".utf8)))
39 let png = Data(base64Encoded: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII=")!
40 XCTAssertNotNil(DocsAttachments.decode(png))
41 }
42}
43