Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
petrpavlik committed Apr 9, 2019
1 parent 34f6378 commit 1b783ac
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion Tests/LeafMarkdownTests/LeafTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import LeafMarkdown
class LeafTests: XCTestCase {
static var allTests = [
("testRunTag", testRunTag),
("testNilParameterDoesNotCrashLeaf", testNilParameterDoesNotCrashLeaf)
("testNilParameterDoesNotCrashLeaf", testNilParameterDoesNotCrashLeaf),
("testStripHtml", testStripHtml),
("testDonotStripHtml", testDonotStripHtml)
]

var renderer: LeafRenderer!
Expand Down Expand Up @@ -41,4 +43,35 @@ class LeafTests: XCTestCase {
let resultString = String(data: result.data, encoding: .utf8)!
XCTAssertEqual(resultString, expectedHtml)
}

func testStripHtml() throws {
let inputMarkdown = "<br>"
let data = TemplateData.dictionary(["data": .string(inputMarkdown)])
let expectedHtml = "<!-- raw HTML omitted -->\n"

let result = try renderer.render(template: template.data(using: .utf8)!, data).wait()
let resultString = String(data: result.data, encoding: .utf8)!
XCTAssertEqual(resultString, expectedHtml)

}

func testDonotStripHtml() throws {

let queue = EmbeddedEventLoop()
let container = BasicContainer(config: .init(), environment: .testing, services: .init(), on: queue)
let tag = Markdown(options: [])
var leafTagConfig = LeafTagConfig.default()
leafTagConfig.use(tag, as: tag.name)
let renderer = LeafRenderer(config: LeafConfig(tags: leafTagConfig, viewsDir: "", shouldCache: false),
using: container)

let inputMarkdown = "<br>"
let data = TemplateData.dictionary(["data": .string(inputMarkdown)])
let expectedHtml = "<br>\n"

let result = try renderer.render(template: template.data(using: .utf8)!, data).wait()
let resultString = String(data: result.data, encoding: .utf8)!
XCTAssertEqual(resultString, expectedHtml)

}
}

0 comments on commit 1b783ac

Please sign in to comment.