portico/Tests/PorticoTests/ViewBuilderTests.swift

31 lines
798 B
Swift

import Testing
@_spi(Portico) import Portico
@Suite struct ViewBuilderTests {
@ViewBuilder private func mixed(_ flag: Bool) -> [AnyView] {
Label(str: "a")
if flag { Label(str: "b") }
}
@ViewBuilder private func either(_ flag: Bool) -> [AnyView] {
if flag { Label(str: "a") } else { Label(str: "b"); Label(str: "c") }
}
@ViewBuilder private func loop() -> [AnyView] {
for _ in 0..<3 { Label(str: "x") }
}
@Test func mixedPlainAndConditional() {
#expect(mixed(true).count == 2)
#expect(mixed(false).count == 1)
}
@Test func eitherBranches() {
#expect(either(true).count == 1)
#expect(either(false).count == 2)
}
@Test func forLoopFlattens() {
#expect(loop().count == 3)
}
}