/
HeadingTests.swift
62 lines (53 loc) · 1.97 KB
/
HeadingTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Ink
* Copyright (c) John Sundell 2019
* MIT license, see LICENSE file for details
*/
import XCTest
import Ink
final class HeadingTests: XCTestCase {
func testHeading() {
let html = MarkdownParser().html(from: "# Hello, world!")
XCTAssertEqual(html, "<h1>Hello, world!</h1>")
}
func testHeadingsSeparatedBySingleNewline() {
let html = MarkdownParser().html(from: "# Hello\n## World")
XCTAssertEqual(html, "<h1>Hello</h1><h2>World</h2>")
}
func testHeadingsWithLeadingNumbers() {
let html = MarkdownParser().html(from: """
# 1. First
## 2. Second
## 3. Third
### 4. Forth
""")
XCTAssertEqual(html, """
<h1>1. First</h1><h2>2. Second</h2><h2>3. Third</h2><h3>4. Forth</h3>
""")
}
func testHeadingWithPreviousWhitespace() {
let html = MarkdownParser().html(from: "Text \n## Heading")
XCTAssertEqual(html, "<p>Text</p><h2>Heading</h2>")
}
func testHeadingWithPreviousNewlineAndWhitespace() {
let html = MarkdownParser().html(from: "Hello\n \n## Heading\n\nWorld")
XCTAssertEqual(html, "<p>Hello</p><h2>Heading</h2><p>World</p>")
}
func testInvalidHeaderLevel() {
let markdown = String(repeating: "#", count: 7)
let html = MarkdownParser().html(from: markdown)
XCTAssertEqual(html, "<p>\(markdown)</p>")
}
}
extension HeadingTests {
static var allTests: [(String, TestClosure<HeadingTests>)] {
return [
("testHeading", testHeading),
("testHeadingsSeparatedBySingleNewline", testHeadingsSeparatedBySingleNewline),
("testHeadingsWithLeadingNumbers", testHeadingsWithLeadingNumbers),
("testHeadingWithPreviousWhitespace", testHeadingWithPreviousWhitespace),
("testHeadingWithPreviousNewlineAndWhitespace", testHeadingWithPreviousNewlineAndWhitespace),
("testInvalidHeaderLevel", testInvalidHeaderLevel)
]
}
}