File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Tests/SwiftSyntaxBuilderTest Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ import XCTest
2
+ import SwiftSyntax
3
+ import SwiftSyntaxBuilder
4
+
5
+ final class IfStmtTests : XCTestCase {
6
+ func testEmptyIfStmt( ) {
7
+ // Use the convenience initializer from IfStmtConvenienceInitializers. This is
8
+ // disambiguated by the absence of a labelName parameter and the use of a
9
+ // trailing closure.
10
+ let buildable = IfStmt ( conditions: ExprList ( [ BooleanLiteralExpr ( false ) ] ) ) { }
11
+ let syntax = buildable. buildSyntax ( format: Format ( ) )
12
+ XCTAssertEqual ( syntax. description, """
13
+ if false {
14
+ }
15
+ """ )
16
+ }
17
+
18
+ func testIfElseStmt( ) {
19
+ // Use the convenience initializer from IfStmtConvenienceInitializers
20
+ // with an else branch expressed by a second trailing closure.
21
+ let buildable = IfStmt ( conditions: ExprList ( [ BooleanLiteralExpr ( true ) ] ) ) {
22
+ FunctionCallExpr ( " print " ) {
23
+ TupleExprElement ( expression: StringLiteralExpr ( " Hello from the if-branch! " ) )
24
+ }
25
+ } elseBody: {
26
+ FunctionCallExpr ( " print " ) {
27
+ TupleExprElement ( expression: StringLiteralExpr ( " Hello from the else-branch! " ) )
28
+ }
29
+ }
30
+ let syntax = buildable. buildSyntax ( format: Format ( ) )
31
+ XCTAssertEqual ( syntax. description, """
32
+ if true {
33
+ print( " Hello from the if-branch! " )
34
+ } else {
35
+ print( " Hello from the else-branch! " )
36
+ }
37
+ """ )
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments