Skip to content

Commit 799609e

Browse files
vzsgloganwright
authored andcommitted
Add tests for the HTML escaping function, incl. crashing case
1 parent 02bf7a9 commit 799609e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Foundation
2+
import XCTest
3+
@testable import Leaf
4+
5+
class HTMLEscapeTests: XCTestCase {
6+
static let allTests = [
7+
("testHTMLEscape", testHTMLEscape),
8+
("testHTMLEscapeCRLFQuotes", testHTMLEscapeCRLFQuotes),
9+
]
10+
11+
func testHTMLEscape() throws {
12+
let input = "&\"'<>"
13+
let expected = "&amp;&quot;&#39;&lt;&gt;"
14+
15+
XCTAssertEqual(input.htmlEscaped(), expected)
16+
}
17+
18+
func testHTMLEscapeCRLFQuotes() throws {
19+
let input = "\r\n\""
20+
let expected = "\r\n&quot;"
21+
22+
XCTAssertEqual(input.htmlEscaped(), expected)
23+
}
24+
}

Tests/LinuxMain.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ XCTMain([
99
testCase(FileLoadTests.allTests),
1010
testCase(IfTests.allTests),
1111
testCase(IndexTests.allTests),
12+
testCase(HTMLEscapeTests.allTests),
1213
testCase(LinkTests.allTests),
1314
testCase(LoopTests.allTests),
1415
testCase(NodeRenderTests.allTests),

0 commit comments

Comments
 (0)