Skip to content

Commit b1a0651

Browse files
committed
add unit tests
1 parent 7f7360d commit b1a0651

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 XCTest
12+
@testable import SwiftDocC
13+
14+
class String_CapitalizationTests: XCTestCase {
15+
16+
func testAllLowerCase() {
17+
let testString = "hello world"
18+
XCTAssertEqual("Hello world", testString.capitalizeFirstWord)
19+
}
20+
21+
func testAllLowerCaseWithPunctuation() {
22+
let testString1 = "hello, world"
23+
let testString2 = "hello-world"
24+
let testString3 = "hello! world"
25+
let testString4 = "hello: world"
26+
let testString5 = "l'ocean world"
27+
XCTAssertEqual("Hello, world", testString1.capitalizeFirstWord)
28+
XCTAssertEqual("Hello-world", testString2.capitalizeFirstWord)
29+
XCTAssertEqual("Hello! world", testString3.capitalizeFirstWord)
30+
XCTAssertEqual("Hello: world", testString4.capitalizeFirstWord)
31+
XCTAssertEqual("L'ocean world", testString5.capitalizeFirstWord)
32+
}
33+
34+
func testInvalidPunctuation() {
35+
let testString = "h`ello world"
36+
XCTAssertEqual(testString, testString.capitalizeFirstWord)
37+
}
38+
39+
func testHasUppercase() {
40+
let testString = "iPad iOS visionOS"
41+
XCTAssertEqual(testString, testString.capitalizeFirstWord)
42+
}
43+
44+
}

0 commit comments

Comments
 (0)