Skip to content

Commit 7262a36

Browse files
committed
Test if-let and if-case statements
1 parent 2d73721 commit 7262a36

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Tests/SwiftSyntaxBuilderTest/IfStmtTests.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,33 @@ final class IfStmtTests: XCTestCase {
3636
}
3737
""")
3838
}
39+
40+
func testIfLetStmt() {
41+
let buildable = IfStmt(
42+
conditions: OptionalBindingCondition(
43+
letOrVarKeyword: .let,
44+
pattern: "x",
45+
initializer: InitializerClause(value: "y")
46+
)
47+
) {}
48+
let syntax = buildable.buildSyntax(format: Format())
49+
XCTAssertEqual(syntax.description, """
50+
if let x = y {
51+
}
52+
""")
53+
}
54+
55+
func testIfCaseStmt() {
56+
let buildable = IfStmt(
57+
conditions: MatchingPatternCondition(
58+
pattern: ExpressionPattern(expression: MemberAccessExpr(name: "x")),
59+
initializer: InitializerClause(value: "y")
60+
)
61+
) {}
62+
let syntax = buildable.buildSyntax(format: Format())
63+
XCTAssertEqual(syntax.description, """
64+
if case .x = y {
65+
}
66+
""")
67+
}
3968
}

0 commit comments

Comments
 (0)