Skip to content

Commit b3e14ad

Browse files
committed
Test CustomAttribute initializer in the context of variables
1 parent a5cd841 commit b3e14ad

File tree

1 file changed

+49
-22
lines changed

1 file changed

+49
-22
lines changed

Tests/SwiftSyntaxBuilderTest/VariableTests.swift

+49-22
Original file line numberDiff line numberDiff line change
@@ -107,29 +107,56 @@ final class VariableTests: XCTestCase {
107107
}
108108

109109
func testAttributedVariables() {
110-
let attributedVar = VariableDecl(
111-
attributes: CustomAttribute(attributeName: "Test", argumentList: nil),
112-
.var,
113-
name: "x",
114-
type: "Int"
115-
)
116-
117-
XCTAssertEqual(attributedVar.buildSyntax(format: Format()).description, """
118-
@Test var x: Int
119-
""")
110+
let testCases: [UInt: (VariableDecl, String)] = [
111+
#line: (
112+
VariableDecl(
113+
attributes: CustomAttribute("Test"),
114+
.var,
115+
name: "x",
116+
type: "Int"
117+
),
118+
"""
119+
@Test var x: Int
120+
"""
121+
),
122+
#line: (
123+
VariableDecl(
124+
attributes: CustomAttribute("Test"),
125+
name: "y",
126+
type: "String"
127+
) {
128+
StringLiteralExpr("Hello world!")
129+
},
130+
"""
131+
@Test var y: String {
132+
"Hello world!"
133+
}
134+
"""
135+
),
136+
#line: (
137+
VariableDecl(
138+
attributes: CustomAttribute("WithArgs") {
139+
TupleExprElement(expression: "value1")
140+
TupleExprElement(label: "label", expression: "value2")
141+
},
142+
name: "z",
143+
type: "Float"
144+
) {
145+
FloatLiteralExpr(0.0)
146+
},
147+
"""
148+
@WithArgs(value1, label: value2) var z: Float {
149+
0.0
150+
}
151+
"""
152+
),
153+
]
120154

121-
let attributedProperty = VariableDecl(
122-
attributes: CustomAttribute(attributeName: "Test", argumentList: nil),
123-
name: "y",
124-
type: "String"
125-
) {
126-
StringLiteralExpr("Hello world!")
127-
}
155+
for (line, testCase) in testCases {
156+
let (builder, expected) = testCase
157+
let syntax = builder.buildSyntax(format: Format())
128158

129-
XCTAssertEqual(attributedProperty.buildSyntax(format: Format()).description, """
130-
@Test var y: String {
131-
"Hello world!"
132-
}
133-
""")
159+
XCTAssertEqual(syntax.description, expected, line: line)
160+
}
134161
}
135162
}

0 commit comments

Comments
 (0)