Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Tests/ElementaryTests/AsyncRenderingTests.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Elementary
import XCTest
import Testing

final class AsyncRenderingTests: XCTestCase {
func testRendersAsyncContent() async throws {
struct AsyncRenderingTests {
@Test func testRendersAsyncContent() async throws {
try await HTMLAssertEqualAsyncOnly(
AsyncContent {
let text = await getValue()
Expand All @@ -13,7 +13,7 @@ final class AsyncRenderingTests: XCTestCase {
)
}

func testAsyncElementInTuple() async throws {
@Test func testAsyncElementInTuple() async throws {
try await HTMLAssertEqualAsyncOnly(
div {
AwaitedP(number: 1)
Expand All @@ -24,7 +24,7 @@ final class AsyncRenderingTests: XCTestCase {
)
}

func testImplicitlyAsyncContent() async throws {
@Test func testImplicitlyAsyncContent() async throws {
try await HTMLAssertEqualAsyncOnly(
p(.id("hello")) {
let text = await getValue()
Expand All @@ -34,7 +34,7 @@ final class AsyncRenderingTests: XCTestCase {
)
}

func testNestedImplicitAsyncContent() async throws {
@Test func testNestedImplicitAsyncContent() async throws {
try await HTMLAssertEqualAsyncOnly(
div(attributes: [.class("c1")]) {
p {
Expand All @@ -49,7 +49,7 @@ final class AsyncRenderingTests: XCTestCase {
)
}

func testAsyncForEach() async throws {
@Test func testAsyncForEach() async throws {
try await HTMLAssertEqualAsyncOnly(
ul {
AsyncForEach(AsyncStream(testData: [1, 2, 3])) { number in
Expand All @@ -60,7 +60,7 @@ final class AsyncRenderingTests: XCTestCase {
)
}

func testAsyncForEachWithAsyncContent() async throws {
@Test func testAsyncForEachWithAsyncContent() async throws {
try await HTMLAssertEqualAsyncOnly(
AsyncForEach(AsyncStream(testData: ["foo", "bar"])) { text in
p {
Expand All @@ -71,22 +71,22 @@ final class AsyncRenderingTests: XCTestCase {
)
}

func testBufferFlushesWhenChunkSizeExceeded() async throws {
@Test func testBufferFlushesWhenChunkSizeExceeded() async throws {
let writer = TestBufferWriter()
try await div { "This is some content" }
.render(into: writer, chunkSize: 1)

XCTAssertEqual("<div>This is some content</div>", String(decoding: writer.result, as: UTF8.self), file: #filePath, line: #line)
XCTAssertGreaterThan(writer.writeCount, 1)
#expect("<div>This is some content</div>" == String(decoding: writer.result, as: UTF8.self))
#expect(writer.writeCount > 1)
}

func testBufferFlushesExactlyOnceOnSmallInput() async throws {
@Test func testBufferFlushesExactlyOnceOnSmallInput() async throws {
let writer = TestBufferWriter()
try await div { "This is some content" }
.render(into: writer, chunkSize: 1024)

XCTAssertEqual("<div>This is some content</div>", String(decoding: writer.result, as: UTF8.self), file: #filePath, line: #line)
XCTAssertEqual(writer.writeCount, 1)
#expect("<div>This is some content</div>" == String(decoding: writer.result, as: UTF8.self))
#expect(writer.writeCount == 1)
}
}

Expand Down
42 changes: 21 additions & 21 deletions Tests/ElementaryTests/AttributeRenderingTests.swift
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
import Elementary
import XCTest
import Testing

final class AttributeRenderingTests: XCTestCase {
func testRendersAnAttribute() async throws {
struct AttributeRenderingTests {
@Test func testRendersAnAttribute() async throws {
try await HTMLAssertEqual(
p(.id("foo")) {},
#"<p id="foo"></p>"#
)
}

func testRendersAttributes() async throws {
@Test func testRendersAttributes() async throws {
try await HTMLAssertEqual(
p(.id("foo"), .class("foo"), .hidden) {},
#"<p id="foo" class="foo" hidden></p>"#
)
}

func testEscapesAttributeValues() async throws {
@Test func testEscapesAttributeValues() async throws {
try await HTMLAssertEqual(
p(.id("foo\""), .class("&foo<>")) {},
#"<p id="foo&quot;" class="&amp;foo<>"></p>"#
)
}

func testRendersAppliedAttributes() async throws {
@Test func testRendersAppliedAttributes() async throws {
try await HTMLAssertEqual(
p {}.attributes(.id("foo"), .class("bar")),
#"<p id="foo" class="bar"></p>"#
)
}

func testKeepsAttributeOrder() async throws {
@Test func testKeepsAttributeOrder() async throws {
try await HTMLAssertEqual(
p(.id("1")) { "yo" }.attributes(.class("2")).attributes(.lang("de-AT")),
#"<p id="1" class="2" lang="de-AT">yo</p>"#
)
}

func testAppliesConditionalAttributes() async throws {
@Test func testAppliesConditionalAttributes() async throws {
try await HTMLAssertEqual(
img(.id("1")).attributes(.class("2"), .id("no"), when: false).attributes(.style("2"), when: true),
#"<img id="1" style="2">"#
)
}

func testMergesClassAndStyleByDefault() async throws {
@Test func testMergesClassAndStyleByDefault() async throws {
try await HTMLAssertEqual(
p(.class("first")) {}.attributes(.class("second"), .style("style1")).attributes(.style("style2")),
#"<p class="first second" style="style1;style2"></p>"#
)
}

func testOverridesByDefault() async throws {
@Test func testOverridesByDefault() async throws {
try await HTMLAssertEqual(
br(.id("foo")).attributes(.hidden, .id("bar")).attributes(.id("baz")),
#"<br id="baz" hidden>"#
)
}

func testRespectsCustomMergeMode() async throws {
@Test func testRespectsCustomMergeMode() async throws {
try await HTMLAssertEqual(
br(.id("1"), .data("bar", value: "baz"))
.attributes(.id("2").mergedBy(.appending(separatedBy: "-")))
Expand All @@ -68,70 +68,70 @@ final class AttributeRenderingTests: XCTestCase {
)
}

func testRendersMouseEventAttribute() async throws {
@Test func testRendersMouseEventAttribute() async throws {
try await HTMLAssertEqual(
p(.on(.click, "doIt()")) {},
#"<p onclick="doIt()"></p>"#
)
}

func testRendersKeyboardEventAttribute() async throws {
@Test func testRendersKeyboardEventAttribute() async throws {
try await HTMLAssertEqual(
p(.on(.keydown, "doIt()")) {},
#"<p onkeydown="doIt()"></p>"#
)
}

func testRendersFormEventAttribute() async throws {
@Test func testRendersFormEventAttribute() async throws {
try await HTMLAssertEqual(
p(.on(.blur, "doIt()")) {},
#"<p onblur="doIt()"></p>"#
)
}

func testRendersMetaCharset() async throws {
@Test func testRendersMetaCharset() async throws {
try await HTMLAssertEqual(
meta(.charset(.utf8)),
#"<meta charset="UTF-8">"#
)
}

func testRendersRequired() async throws {
@Test func testRendersRequired() async throws {
try await HTMLAssertEqual(
input(.type(.text), .required),
#"<input type="text" required>"#
)
}

func testRendersAttributesArray() async throws {
@Test func testRendersAttributesArray() async throws {
try await HTMLAssertEqual(
p(attributes: [.id("foo"), .class("foo"), .hidden]) {},
#"<p id="foo" class="foo" hidden></p>"#
)
}

func testRendersAttributesArrayOnVoidElement() async throws {
@Test func testRendersAttributesArrayOnVoidElement() async throws {
try await HTMLAssertEqual(
input(attributes: [.type(.text), .required]),
#"<input type="text" required>"#
)
}

func testRendersAppliedConditionalAttributesArray() async throws {
@Test func testRendersAppliedConditionalAttributesArray() async throws {
try await HTMLAssertEqual(
img(.id("1")).attributes(contentsOf: [.class("2"), .id("no")], when: false).attributes(contentsOf: [.style("2")], when: true),
#"<img id="1" style="2">"#
)
}

func testRendersWidthAndHeightAttributes() async throws {
@Test func testRendersWidthAndHeightAttributes() async throws {
try await HTMLAssertEqual(
img(.width(100), .height(200)),
#"<img width="100" height="200">"#
)
}

func testRendersAltForImg() async throws {
@Test func testRendersAltForImg() async throws {
try await HTMLAssertEqual(
img(.src("/path/to/dog.jpeg"), .alt("A happy dog"), .width(200), .height(200)),
#"<img src="/path/to/dog.jpeg" alt="A happy dog" width="200" height="200">"#
Expand Down
14 changes: 7 additions & 7 deletions Tests/ElementaryTests/ClassAndStyleRenderingTests.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Elementary
import XCTest
import Testing

final class ClassAndStyleRenderingTests: XCTestCase {
func testRendersClasses() async throws {
struct ClassAndStyleRenderingTests {
@Test func testRendersClasses() async throws {
try await HTMLAssertEqual(
p(.class(["foo", "bar"])) {},
#"<p class="foo bar"></p>"#
)
}

func testMergesClassesKeepingSequence() async throws {
@Test func testMergesClassesKeepingSequence() async throws {
try await HTMLAssertEqual(
p(
.class(["foo", "bar"]),
Expand All @@ -23,14 +23,14 @@ final class ClassAndStyleRenderingTests: XCTestCase {
)
}

func testRendersStyles() async throws {
@Test func testRendersStyles() async throws {
try await HTMLAssertEqual(
p(.style(["color": "red", "font-size": "16px"])) {},
#"<p style="color:red;font-size:16px"></p>"#
)
}

func testRendersStylesFromDictionary() async throws {
@Test func testRendersStylesFromDictionary() async throws {
let styles = [
"display": "flex"
]
Expand All @@ -40,7 +40,7 @@ final class ClassAndStyleRenderingTests: XCTestCase {
)
}

func testMergesStylesKeepingSequence() async throws {
@Test func testMergesStylesKeepingSequence() async throws {
try await HTMLAssertEqual(
p(.style(["color": "red", "font-size": "16px"])) {}
.attributes(
Expand Down
14 changes: 7 additions & 7 deletions Tests/ElementaryTests/CompositionRenderingTest.swift
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import Elementary
import XCTest
import Testing

final class CompositionRenderingTests: XCTestCase {
func testRendersADocument() async throws {
struct CompositionRenderingTests {
@Test func testRendersADocument() async throws {
try await HTMLAssertEqual(
MyPage(text: "my text"),
#"<!DOCTYPE html><html lang="en"><head><title>Foo</title><meta name="author" content="Me"><meta name="description" content="Test page"></head><body class="my-class" id="42"><div><h1>Hello, world!</h1><p>my text</p></div></body></html>"#
)
}

func testRendersARTLPage() async throws {
@Test func testRendersARTLPage() async throws {
try await HTMLAssertEqual(
MyRTLPage(),
#"<!DOCTYPE html><html lang="he" dir="rtl"><head><title>שלום עולם</title></head><body><h1>מה קורה?</h1></body></html>"#
)
}

func testRendersAComponent() async throws {
@Test func testRendersAComponent() async throws {
try await HTMLAssertEqual(
MyList(items: ["one", "two"], selectedIndex: 1),
#"<ul><li id="1">one</li><li class="selected" id="2">two</li></ul>"#
)
}

func testRendersForEachWithRange() async throws {
@Test func testRendersForEachWithRange() async throws {
try await HTMLAssertEqual(
ForEach(1...3) { index in
li { "Item \(index)" }
Expand All @@ -32,7 +32,7 @@ final class CompositionRenderingTests: XCTestCase {
)
}

func testRendersForEachWithLazyMap() async throws {
@Test func testRendersForEachWithLazyMap() async throws {
try await HTMLAssertEqual(
ForEach([1, 2, 3].lazy.map { $0 * 10 }) { index in
li { "Item \(index)" }
Expand Down
8 changes: 4 additions & 4 deletions Tests/ElementaryTests/EnvironmentRenderingTests.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Elementary
import XCTest
import Testing

final class EnvironmentRenderingTests: XCTestCase {
func testSetsEnvironment() async throws {
struct EnvironmentRenderingTests {
@Test func testSetsEnvironment() async throws {
try await HTMLAssertEqual(
div {
MyNumber()
Expand All @@ -14,7 +14,7 @@ final class EnvironmentRenderingTests: XCTestCase {
)
}

func testGetsOptionalEnvironment() async throws {
@Test func testGetsOptionalEnvironment() async throws {
try await HTMLAssertEqualAsyncOnly(
div {
MyDatabaseValue()
Expand Down
Loading
Loading