Fix issues in Tests

t
This commit is contained in:
David Jennes
2018-09-21 00:00:56 +02:00
parent 3f4622f54f
commit 2d82dcb003
19 changed files with 2573 additions and 2454 deletions

View File

@@ -1,72 +1,68 @@
import XCTest
import Spectre
import Stencil
import XCTest
fileprivate struct CustomNode : NodeType {
private struct CustomNode: NodeType {
let token: Token?
func render(_ context:Context) throws -> String {
func render(_ context: Context) throws -> String {
return "Hello World"
}
}
fileprivate struct Article {
private struct Article {
let title: String
let author: String
}
class StencilTests: XCTestCase {
final class StencilTests: XCTestCase {
lazy var environment: Environment = {
let exampleExtension = Extension()
exampleExtension.registerSimpleTag("simpletag") { _ in
"Hello World"
}
exampleExtension.registerTag("customtag") { _, token in
CustomNode(token: token)
}
return Environment(extensions: [exampleExtension])
}()
func testStencil() {
describe("Stencil") {
let exampleExtension = Extension()
it("can render the README example") {
let templateString = """
There are {{ articles.count }} articles.
exampleExtension.registerSimpleTag("simpletag") { context in
return "Hello World"
}
{% for article in articles %}\
- {{ article.title }} by {{ article.author }}.
{% endfor %}
"""
exampleExtension.registerTag("customtag") { parser, token in
return CustomNode(token: token)
}
let environment = Environment(extensions: [exampleExtension])
$0.it("can render the README example") {
let templateString = """
There are {{ articles.count }} articles.
{% for article in articles %}\
- {{ article.title }} by {{ article.author }}.
{% endfor %}
"""
let context = [
"articles": [
Article(title: "Migrating from OCUnit to XCTest", author: "Kyle Fuller"),
Article(title: "Memory Management with ARC", author: "Kyle Fuller"),
]
let context = [
"articles": [
Article(title: "Migrating from OCUnit to XCTest", author: "Kyle Fuller"),
Article(title: "Memory Management with ARC", author: "Kyle Fuller")
]
]
let template = Template(templateString: templateString)
let result = try template.render(context)
let template = Template(templateString: templateString)
let result = try template.render(context)
try expect(result) == """
There are 2 articles.
try expect(result) == """
There are 2 articles.
- Migrating from OCUnit to XCTest by Kyle Fuller.
- Memory Management with ARC by Kyle Fuller.
- Migrating from OCUnit to XCTest by Kyle Fuller.
- Memory Management with ARC by Kyle Fuller.
"""
}
"""
}
$0.it("can render a custom template tag") {
let result = try environment.renderTemplate(string: "{% customtag %}")
try expect(result) == "Hello World"
}
it("can render a custom template tag") {
let result = try self.environment.renderTemplate(string: "{% customtag %}")
try expect(result) == "Hello World"
}
$0.it("can render a simple custom tag") {
let result = try environment.renderTemplate(string: "{% simpletag %}")
try expect(result) == "Hello World"
}
it("can render a simple custom tag") {
let result = try self.environment.renderTemplate(string: "{% simpletag %}")
try expect(result) == "Hello World"
}
}
}