@@ -16,19 +16,6 @@ fileprivate func cannedStructDecl() -> StructDeclSyntax {
1616 }
1717}
1818
19- fileprivate func infixOperationExprList( with operatorToken: TokenSyntax ) -> ExprListSyntax {
20- let first = IntegerLiteralExprSyntax {
21- $0. useDigits ( SyntaxFactory . makeIntegerLiteral ( " 1 " , trailingTrivia: . spaces( 1 ) ) )
22- }
23- let op = BinaryOperatorExprSyntax {
24- $0. useOperatorToken ( operatorToken. withTrailingTrivia ( . spaces( 1 ) ) )
25- }
26- let second = IntegerLiteralExprSyntax {
27- $0. useDigits ( SyntaxFactory . makeIntegerLiteral ( " 1 " ) )
28- }
29- return SyntaxFactory . makeExprList ( [ first, op, second] )
30- }
31-
3219public class SyntaxFactoryAPITestCase : XCTestCase {
3320
3421 public static let allTests = [
@@ -38,21 +25,7 @@ public class SyntaxFactoryAPITestCase: XCTestCase {
3825 ( " testWithOptionalChild " , testWithOptionalChild) ,
3926 ( " testUnknownSyntax " , testUnknownSyntax) ,
4027 ( " testMakeStringLiteralExpr " , testMakeStringLiteralExpr) ,
41- ( " testMakeNonEqualityOperator " , testMakeNonEqualityOperator) ,
42- ( " testMakeAdditionOperator " , testMakeAdditionOperator) ,
43- ( " testMakeSubtractionOperator " , testMakeSubtractionOperator) ,
44- ( " testMakeMultiplicationOperator " , testMakeMultiplicationOperator) ,
45- ( " testMakeDivisionOperator " , testMakeDivisionOperator) ,
46- ( " testMakeRemainderOperator " , testMakeRemainderOperator) ,
47- ( " testMakeAdditionAssignmentOperator " , testMakeAdditionAssignmentOperator) ,
48- ( " testMakeSubtractionAssignmentOperator " , testMakeSubtractionAssignmentOperator) ,
49- ( " testMakeMultiplicationAssignmentOperator " , testMakeMultiplicationAssignmentOperator) ,
50- ( " testMakeDivisionAssignmentOperator " , testMakeDivisionAssignmentOperator) ,
51- ( " testMakeRemainderAssignmentOperator " , testMakeRemainderAssignmentOperator) ,
52- ( " testMakeLessThanOperator " , testMakeLessThanOperator) ,
53- ( " testMakeGreaterThanOperator " , testMakeGreaterThanOperator) ,
54- ( " testMakeLessThanOrEqualToOperator " , testMakeLessThanOrEqualToOperator) ,
55- ( " testMakeGreaterThanOrEqualToOperator " , testMakeGreaterThanOrEqualToOperator) ,
28+ ( " testMakeBinaryOperator " , testMakeBinaryOperator) ,
5629 ]
5730
5831 public func testGenerated( ) {
@@ -202,78 +175,22 @@ public class SyntaxFactoryAPITestCase: XCTestCase {
202175 XCTAssertEqual ( expr. description, expected)
203176 }
204177
205- public func testMakeNonEqualityOperator( ) {
206- let exprList = infixOperationExprList ( with: SyntaxFactory . makeNonEqualityOperator ( ) )
207- XCTAssertEqual ( " \( exprList) " , " 1 != 1 " )
208- }
209-
210- public func testMakeAdditionOperator( ) {
211- let exprList = infixOperationExprList ( with: SyntaxFactory . makeAdditionOperator ( ) )
212- XCTAssertEqual ( " \( exprList) " , " 1 + 1 " )
213- }
214-
215- public func testMakeSubtractionOperator( ) {
216- let exprList = infixOperationExprList ( with: SyntaxFactory . makeSubtractionOperator ( ) )
217- XCTAssertEqual ( " \( exprList) " , " 1 - 1 " )
218- }
219-
220- public func testMakeMultiplicationOperator( ) {
221- let exprList = infixOperationExprList ( with: SyntaxFactory . makeMultiplicationOperator ( ) )
222- XCTAssertEqual ( " \( exprList) " , " 1 * 1 " )
223- }
224-
225- public func testMakeDivisionOperator( ) {
226- let exprList = infixOperationExprList ( with: SyntaxFactory . makeDivisionOperator ( ) )
227- XCTAssertEqual ( " \( exprList) " , " 1 / 1 " )
228- }
229-
230- public func testMakeRemainderOperator( ) {
231- let exprList = infixOperationExprList ( with: SyntaxFactory . makeRemainderOperator ( ) )
232- XCTAssertEqual ( " \( exprList) " , " 1 % 1 " )
233- }
234-
235- public func testMakeAdditionAssignmentOperator( ) {
236- let exprList = infixOperationExprList ( with: SyntaxFactory . makeAdditionAssignmentOperator ( ) )
237- XCTAssertEqual ( " \( exprList) " , " 1 += 1 " )
238- }
239-
240- public func testMakeSubtractionAssignmentOperator( ) {
241- let exprList = infixOperationExprList ( with: SyntaxFactory . makeSubtractionAssignmentOperator ( ) )
242- XCTAssertEqual ( " \( exprList) " , " 1 -= 1 " )
243- }
244-
245- public func testMakeMultiplicationAssignmentOperator( ) {
246- let exprList = infixOperationExprList ( with: SyntaxFactory . makeMultiplicationAssignmentOperator ( ) )
247- XCTAssertEqual ( " \( exprList) " , " 1 *= 1 " )
248- }
249-
250- public func testMakeDivisionAssignmentOperator( ) {
251- let exprList = infixOperationExprList ( with: SyntaxFactory . makeDivisionAssignmentOperator ( ) )
252- XCTAssertEqual ( " \( exprList) " , " 1 /= 1 " )
253- }
254-
255- public func testMakeRemainderAssignmentOperator( ) {
256- let exprList = infixOperationExprList ( with: SyntaxFactory . makeRemainderAssignmentOperator ( ) )
257- XCTAssertEqual ( " \( exprList) " , " 1 %= 1 " )
258- }
259-
260- public func testMakeLessThanOperator( ) {
261- let exprList = infixOperationExprList ( with: SyntaxFactory . makeLessThanOperator ( ) )
262- XCTAssertEqual ( " \( exprList) " , " 1 < 1 " )
263- }
264-
265- public func testMakeGreaterThanOperator( ) {
266- let exprList = infixOperationExprList ( with: SyntaxFactory . makeGreaterThanOperator ( ) )
267- XCTAssertEqual ( " \( exprList) " , " 1 > 1 " )
268- }
269-
270- public func testMakeLessThanOrEqualToOperator( ) {
271- let exprList = infixOperationExprList ( with: SyntaxFactory . makeLessThanOrEqualToOperator ( ) )
272- XCTAssertEqual ( " \( exprList) " , " 1 <= 1 " )
273- }
274-
275- public func testMakeGreaterThanOrEqualToOperator( ) {
276- let exprList = infixOperationExprList ( with: SyntaxFactory . makeGreaterThanOrEqualToOperator ( ) )
277- XCTAssertEqual ( " \( exprList) " , " 1 >= 1 " )
178+ public func testMakeBinaryOperator( ) {
179+ let first = IntegerLiteralExprSyntax {
180+ $0. useDigits ( SyntaxFactory . makeIntegerLiteral ( " 1 " , trailingTrivia: . spaces( 1 ) ) )
181+ }
182+ let second = IntegerLiteralExprSyntax {
183+ $0. useDigits ( SyntaxFactory . makeIntegerLiteral ( " 1 " ) )
184+ }
185+ let operatorNames = [ " == " , " != " , " + " , " - " , " * " , " / " , " < " , " > " , " <= " , " >= " ]
186+ operatorNames. forEach { operatorName in
187+ let operatorToken = SyntaxFactory . makeBinaryOperator ( operatorName, trailingTrivia: . spaces( 1 ) )
188+ let operatorExpr = BinaryOperatorExprSyntax {
189+ $0. useOperatorToken ( operatorToken)
190+ }
191+ let exprList = SyntaxFactory . makeExprList ( [ first, operatorExpr, second] )
192+
193+ XCTAssertEqual ( " \( exprList) " , " 1 \( operatorName) 1 " )
194+ }
278195 }
279196}
0 commit comments