/
CodeTests.swift
76 lines (65 loc) · 1.99 KB
/
CodeTests.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Ink
* Copyright (c) John Sundell 2019
* MIT license, see LICENSE file for details
*/
import XCTest
import Ink
final class CodeTests: XCTestCase {
func testInlineCode() {
let html = MarkdownParser().html(from: "Hello `inline.code()`")
XCTAssertEqual(html, "<p>Hello <code>inline.code()</code></p>")
}
func testCodeBlockWithJustBackticks() {
let html = MarkdownParser().html(from: """
```
code()
block()
```
""")
XCTAssertEqual(html, "<pre><code>code()\nblock()</code></pre>")
}
func testCodeBlockWithBackticksAndLabel() {
let html = MarkdownParser().html(from: """
```swift
code()
```
""")
XCTAssertEqual(html, "<pre><code class=\"swift\">code()</code></pre>")
}
func testEncodingSpecialCharactersWithinCodeBlock() {
let html = MarkdownParser().html(from: """
```swift
Generic<T>() && expression()
```
""")
XCTAssertEqual(html, """
<pre><code class="swift">Generic<T>() && expression()</code></pre>
""")
}
func testIgnoringFormattingWithinCodeBlock() {
let html = MarkdownParser().html(from: """
```
# Not A Header
return View()
- Not a list
```
""")
XCTAssertEqual(html, """
<pre><code># Not A Header
return View()
- Not a list</code></pre>
""")
}
}
extension CodeTests {
static var allTests: [(String, TestClosure<CodeTests>)] {
return [
("testInlineCode", testInlineCode),
("testCodeBlockWithJustBackticks", testCodeBlockWithJustBackticks),
("testCodeBlockWithBackticksAndLabel", testCodeBlockWithBackticksAndLabel),
("testEncodingSpecialCharactersWithinCodeBlock", testEncodingSpecialCharactersWithinCodeBlock),
("testIgnoringFormattingWithinCodeBlock", testIgnoringFormattingWithinCodeBlock)
]
}
}