|
| 1 | +/* |
| 2 | + This source file is part of the Swift.org open source project |
| 3 | + |
| 4 | + Copyright (c) 2024 Apple Inc. and the Swift project authors |
| 5 | + Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | + |
| 7 | + See https://swift.org/LICENSE.txt for license information |
| 8 | + See https://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 9 | +*/ |
| 10 | + |
| 11 | +import Foundation |
| 12 | +import XCTest |
| 13 | +import Markdown |
| 14 | +@testable import SwiftDocC |
| 15 | + |
| 16 | +class RenderBlockContent_CapitalizationTests: XCTestCase { |
| 17 | + |
| 18 | + // MARK: - Inlines |
| 19 | + // Text, Emphasis, Strong are all auto-capitalized, and everything else defaults to not capitalized. |
| 20 | + |
| 21 | + func testRenderInlineContentText() { |
| 22 | + let text = RenderInlineContent.text("hello, world!").capitalizeFirstWord |
| 23 | + XCTAssertEqual("Hello, world!", text.plainText) |
| 24 | + } |
| 25 | + |
| 26 | + func testRenderInlineContentEmphasis() { |
| 27 | + let emphasis = RenderInlineContent.emphasis(inlineContent: [.text("hello, world!")]).capitalizeFirstWord |
| 28 | + XCTAssertEqual("Hello, world!", emphasis.plainText) |
| 29 | + } |
| 30 | + |
| 31 | + func testRenderInlineContentStrong() { |
| 32 | + let strong = RenderInlineContent.strong(inlineContent: [.text("hello, world!")]).capitalizeFirstWord |
| 33 | + XCTAssertEqual("Hello, world!", strong.plainText) |
| 34 | + } |
| 35 | + |
| 36 | + func testRenderInlineContentCodeVoice() { |
| 37 | + let codeVoice = RenderInlineContent.codeVoice(code: "code voice").capitalizeFirstWord |
| 38 | + XCTAssertEqual("code voice", codeVoice.plainText) |
| 39 | + } |
| 40 | + |
| 41 | + func testRenderInlineContentReference() { |
| 42 | + let reference = RenderInlineContent.reference(identifier: .init("Test"), isActive: true, overridingTitle: "hello, world!", overridingTitleInlineContent: [.text("hello, world!")]).capitalizeFirstWord |
| 43 | + XCTAssertEqual("hello, world!", reference.plainText) |
| 44 | + } |
| 45 | + |
| 46 | + func testRenderInlineContentNewTerm() { |
| 47 | + let newTerm = RenderInlineContent.newTerm(inlineContent: [.text("helloWorld")]).capitalizeFirstWord |
| 48 | + XCTAssertEqual("helloWorld", newTerm.plainText) |
| 49 | + } |
| 50 | + |
| 51 | + func testRenderInlineContentInlineHead() { |
| 52 | + let inlineHead = RenderInlineContent.inlineHead(inlineContent: [.text("hello, world!")]).capitalizeFirstWord |
| 53 | + XCTAssertEqual("hello, world!", inlineHead.plainText) |
| 54 | + } |
| 55 | + |
| 56 | + func testRenderInlineContentSubscript() { |
| 57 | + let subscriptContent = RenderInlineContent.subscript(inlineContent: [.text("hello, world!")]).capitalizeFirstWord |
| 58 | + XCTAssertEqual("hello, world!", subscriptContent.plainText) |
| 59 | + } |
| 60 | + |
| 61 | + func testRenderInlineContentSuperscript() { |
| 62 | + let superscriptContent = RenderInlineContent.superscript(inlineContent: [.text("hello, world!")]).capitalizeFirstWord |
| 63 | + XCTAssertEqual("hello, world!", superscriptContent.plainText) |
| 64 | + } |
| 65 | + |
| 66 | + func testRenderInlineContentStrikethrough() { |
| 67 | + let strikethrough = RenderInlineContent.strikethrough(inlineContent: [.text("hello, world!")]).capitalizeFirstWord |
| 68 | + XCTAssertEqual("hello, world!", strikethrough.plainText) |
| 69 | + } |
| 70 | + |
| 71 | + // MARK: - Blocks |
| 72 | + // Paragraphs, asides, and small content are all auto-capitalized, and everything else defaults to not capitalized. |
| 73 | + |
| 74 | + func testRenderBlockContentParagraph() { |
| 75 | + let paragraph = RenderBlockContent.paragraph(.init(inlineContent: [.text("hello, world!")])).capitalizeFirstWord |
| 76 | + XCTAssertEqual("Hello, world!", paragraph.rawIndexableTextContent(references: [:])) |
| 77 | + } |
| 78 | + |
| 79 | + func testRenderBlockContentAside() { |
| 80 | + let aside = RenderBlockContent.aside(.init(style: .init(rawValue: "Experiment"), content: [.paragraph(.init(inlineContent: [.text("hello, world!")]))])).capitalizeFirstWord |
| 81 | + XCTAssertEqual("Hello, world!", aside.rawIndexableTextContent(references: [:])) |
| 82 | + } |
| 83 | + |
| 84 | + func testRenderBlockContentSmall() { |
| 85 | + let small = RenderBlockContent.small(.init(inlineContent: [.text("hello, world!")])).capitalizeFirstWord |
| 86 | + XCTAssertEqual("Hello, world!", small.rawIndexableTextContent(references: [:])) |
| 87 | + } |
| 88 | + |
| 89 | + func testRenderBlockContentUnorderedList() { |
| 90 | + let list = RenderBlockContent.unorderedList(.init(items: [ |
| 91 | + .init(content: [ |
| 92 | + .paragraph(.init(inlineContent: [.text("hello,")])), |
| 93 | + ]), |
| 94 | + .init(content: [ |
| 95 | + .paragraph(.init(inlineContent: [.text("world!")])), |
| 96 | + ]), |
| 97 | + ])).capitalizeFirstWord |
| 98 | + XCTAssertEqual("hello, world!", list.rawIndexableTextContent(references: [:])) |
| 99 | + } |
| 100 | + |
| 101 | + func testRenderBlockContentStep() { |
| 102 | + let step = RenderBlockContent.step(.init(content: [.paragraph(.init(inlineContent: [.text("hello, world!")]))], caption: [.paragraph(.init(inlineContent: [.text("Step caption")]))], media: RenderReferenceIdentifier("Media"), code: RenderReferenceIdentifier("Code"), runtimePreview: RenderReferenceIdentifier("Preview"))).capitalizeFirstWord |
| 103 | + XCTAssertEqual("hello, world! Step caption", step.rawIndexableTextContent(references: [:])) |
| 104 | + } |
| 105 | + |
| 106 | + |
| 107 | + func testRenderBlockContentOrderedList() { |
| 108 | + let list = RenderBlockContent.orderedList(.init(items: [ |
| 109 | + .init(content: [ |
| 110 | + .paragraph(.init(inlineContent: [.text("hello,")])), |
| 111 | + ]), |
| 112 | + .init(content: [ |
| 113 | + .paragraph(.init(inlineContent: [.text("world!")])), |
| 114 | + ]), |
| 115 | + ])).capitalizeFirstWord |
| 116 | + XCTAssertEqual("hello, world!", list.rawIndexableTextContent(references: [:])) |
| 117 | + } |
| 118 | + |
| 119 | +} |
0 commit comments