Skip to content

Commit

Permalink
Add custom tag to verify casting works.
Browse files Browse the repository at this point in the history
  • Loading branch information
grantjbutler committed Oct 28, 2024
1 parent 142fcf4 commit b7076d5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Tests/LeafTests/LeafTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ final class LeafTests: XCTestCase {
func testContextUserInfo() throws {
var test = TestFiles()
test.files["/foo.leaf"] = """
Hello #custom()! @ #source()
Hello #custom()! @ #source() app nil? #application()
"""

struct CustomTag: LeafTag {
Expand All @@ -133,6 +133,12 @@ final class LeafTests: XCTestCase {
.string(ctx.request?.url.path ?? "application")
}
}

struct ApplicationTag: LeafTag {
func render(_ ctx: LeafContext) throws -> LeafData {
.string(ctx.application != nil ? "non-nil app" : "nil app")
}
}

let app = Application(.testing)
defer { app.shutdown() }
Expand All @@ -142,6 +148,7 @@ final class LeafTests: XCTestCase {
app.leaf.cache.isEnabled = false
app.leaf.tags["custom"] = CustomTag()
app.leaf.tags["source"] = SourceTag()
app.leaf.tags["application"] = ApplicationTag()
app.leaf.sources = .singleSource(test)
app.leaf.userInfo["info"] = "World"

Expand All @@ -152,7 +159,7 @@ final class LeafTests: XCTestCase {
try app.test(.GET, "test-file") { res in
XCTAssertEqual(res.status, .ok)
XCTAssertEqual(res.headers.contentType, .html)
XCTAssertEqual(res.body.string, "Hello World! @ /test-file")
XCTAssertEqual(res.body.string, "Hello World! @ /test-file app nil? non-nil app")
}

app.get("test-file-with-application-renderer") { req in
Expand All @@ -162,7 +169,7 @@ final class LeafTests: XCTestCase {
try app.test(.GET, "test-file-with-application-renderer") { res in
XCTAssertEqual(res.status, .ok)
XCTAssertEqual(res.headers.contentType, .html)
XCTAssertEqual(res.body.string, "Hello World! @ application")
XCTAssertEqual(res.body.string, "Hello World! @ application app nil? non-nil app")
}
}

Expand Down

0 comments on commit b7076d5

Please sign in to comment.