/
LinkTests.swift
82 lines (66 loc) · 2.47 KB
/
LinkTests.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
77
78
79
80
81
82
/**
* Ink
* Copyright (c) John Sundell 2019
* MIT license, see LICENSE file for details
*/
import XCTest
import Ink
final class LinkTests: XCTestCase {
func testLinkWithURL() {
let html = MarkdownParser().html(from: "[Title](url)")
XCTAssertEqual(html, #"<p><a href="url">Title</a></p>"#)
}
func testLinkWithReference() {
let html = MarkdownParser().html(from: """
[Title][url]
[url]: swiftbysundell.com
""")
XCTAssertEqual(html, #"<p><a href="swiftbysundell.com">Title</a></p>"#)
}
func testCaseMismatchedLinkWithReference() {
let html = MarkdownParser().html(from: """
[Title][Foo]
[Title][αγω]
[FOO]: /url
[ΑΓΩ]: /φου
""")
XCTAssertEqual(html, #"<p><a href="/url">Title</a> <a href="/φου">Title</a></p>"#)
}
func testNumericLinkWithReference() {
let html = MarkdownParser().html(from: """
[1][1]
[1]: swiftbysundell.com
""")
XCTAssertEqual(html, #"<p><a href="swiftbysundell.com">1</a></p>"#)
}
func testBoldLinkWithInternalMarkers() {
let html = MarkdownParser().html(from: "[**Hello**](/hello)")
XCTAssertEqual(html, #"<p><a href="/hello"><strong>Hello</strong></a></p>"#)
}
func testBoldLinkWithExternalMarkers() {
let html = MarkdownParser().html(from: "**[Hello](/hello)**")
XCTAssertEqual(html, #"<p><strong><a href="/hello">Hello</a></strong></p>"#)
}
func testLinkWithUnderscores() {
let html = MarkdownParser().html(from: "[He_llo](/he_llo)")
XCTAssertEqual(html, "<p><a href=\"/he_llo\">He_llo</a></p>")
}
func testUnterminatedLink() {
let html = MarkdownParser().html(from: "[Hello]")
XCTAssertEqual(html, "<p>[Hello]</p>")
}
}
extension LinkTests {
static var allTests: Linux.TestList<LinkTests> {
return [
("testLinkWithURL", testLinkWithURL),
("testLinkWithReference", testLinkWithReference),
("testCaseMismatchedLinkWithReference", testCaseMismatchedLinkWithReference),
("testNumericLinkWithReference", testNumericLinkWithReference),
("testBoldLinkWithInternalMarkers", testBoldLinkWithInternalMarkers),
("testBoldLinkWithExternalMarkers", testBoldLinkWithExternalMarkers),
("testLinkWithUnderscores", testLinkWithUnderscores),
("testUnterminatedLink", testUnterminatedLink)
]
}
}