|
| 1 | +import SwiftSyntaxMacros |
| 2 | +import SwiftSyntaxMacrosTestSupport |
| 3 | +import XCTest |
| 4 | + |
| 5 | +import XCTestParametrizedMacroMacros |
| 6 | + |
| 7 | +final class EffectSpecifiersTests: XCTestCase { |
| 8 | + |
| 9 | + let testMacros: [String: Macro.Type] = [ |
| 10 | + "Parametrize": ParametrizeMacro.self, |
| 11 | + ] |
| 12 | + |
| 13 | + func testWithInputNoSpecifiers() throws { |
| 14 | + assertMacroExpansion( |
| 15 | + """ |
| 16 | + struct TestStruct { |
| 17 | + @Parametrize(input: [1]) |
| 18 | + func testMethod(input n: Int) { |
| 19 | + XCTAssertTrue(n>0) |
| 20 | + } |
| 21 | + } |
| 22 | + """, |
| 23 | + expandedSource: """ |
| 24 | + struct TestStruct { |
| 25 | + func testMethod(input n: Int) { |
| 26 | + XCTAssertTrue(n>0) |
| 27 | + } |
| 28 | +
|
| 29 | + func testMethod_N_1() { |
| 30 | + let n: Int = 1 |
| 31 | + XCTAssertTrue(n > 0) |
| 32 | + } |
| 33 | + } |
| 34 | + """, |
| 35 | + macros: testMacros |
| 36 | + ) |
| 37 | + } |
| 38 | + |
| 39 | + func testWithInputAsyncAndThrows() throws { |
| 40 | + assertMacroExpansion( |
| 41 | + """ |
| 42 | + struct TestStruct { |
| 43 | + @Parametrize(input: [1]) |
| 44 | + func testMethod(input n: Int) async throws { |
| 45 | + XCTAssertTrue(n>0) |
| 46 | + } |
| 47 | + } |
| 48 | + """, |
| 49 | + expandedSource: """ |
| 50 | + struct TestStruct { |
| 51 | + func testMethod(input n: Int) async throws { |
| 52 | + XCTAssertTrue(n>0) |
| 53 | + } |
| 54 | +
|
| 55 | + func testMethod_N_1() async throws { |
| 56 | + let n: Int = 1 |
| 57 | + XCTAssertTrue(n > 0) |
| 58 | + } |
| 59 | + } |
| 60 | + """, |
| 61 | + macros: testMacros |
| 62 | + ) |
| 63 | + } |
| 64 | + |
| 65 | + func testWithInputAsync() throws { |
| 66 | + assertMacroExpansion( |
| 67 | + """ |
| 68 | + struct TestStruct { |
| 69 | + @Parametrize(input: [1]) |
| 70 | + func testMethod(input n: Int) async { |
| 71 | + XCTAssertTrue(n>0) |
| 72 | + } |
| 73 | + } |
| 74 | + """, |
| 75 | + expandedSource: """ |
| 76 | + struct TestStruct { |
| 77 | + func testMethod(input n: Int) async { |
| 78 | + XCTAssertTrue(n>0) |
| 79 | + } |
| 80 | +
|
| 81 | + func testMethod_N_1() async { |
| 82 | + let n: Int = 1 |
| 83 | + XCTAssertTrue(n > 0) |
| 84 | + } |
| 85 | + } |
| 86 | + """, |
| 87 | + macros: testMacros |
| 88 | + ) |
| 89 | + } |
| 90 | + |
| 91 | + func testWithInputOutputNoSpecifiers() throws { |
| 92 | + assertMacroExpansion( |
| 93 | + """ |
| 94 | + struct TestStruct { |
| 95 | + @Parametrize(input: [1], output: [1]) |
| 96 | + func testMethod(input n: Int, output r: Int) { |
| 97 | + XCTAssertEqual(n,r) |
| 98 | + } |
| 99 | + } |
| 100 | + """, |
| 101 | + expandedSource: """ |
| 102 | + struct TestStruct { |
| 103 | + func testMethod(input n: Int, output r: Int) { |
| 104 | + XCTAssertEqual(n,r) |
| 105 | + } |
| 106 | +
|
| 107 | + func testMethod_N_1_R_1() { |
| 108 | + let n: Int = 1 |
| 109 | + let r: Int = 1 |
| 110 | + XCTAssertEqual(n, r) |
| 111 | + } |
| 112 | + } |
| 113 | + """, |
| 114 | + macros: testMacros |
| 115 | + ) |
| 116 | + } |
| 117 | + |
| 118 | + func testWithInputOutputAsync() throws { |
| 119 | + assertMacroExpansion( |
| 120 | + """ |
| 121 | + struct TestStruct { |
| 122 | + @Parametrize(input: [1], output: [1]) |
| 123 | + func testMethod(input n: Int, output r: Int) async { |
| 124 | + XCTAssertEqual(n,r) |
| 125 | + } |
| 126 | + } |
| 127 | + """, |
| 128 | + expandedSource: """ |
| 129 | + struct TestStruct { |
| 130 | + func testMethod(input n: Int, output r: Int) async { |
| 131 | + XCTAssertEqual(n,r) |
| 132 | + } |
| 133 | +
|
| 134 | + func testMethod_N_1_R_1() async { |
| 135 | + let n: Int = 1 |
| 136 | + let r: Int = 1 |
| 137 | + XCTAssertEqual(n, r) |
| 138 | + } |
| 139 | + } |
| 140 | + """, |
| 141 | + macros: testMacros |
| 142 | + ) |
| 143 | + } |
| 144 | + |
| 145 | + func testWithInputOutputLabelsAsyncThrows() throws { |
| 146 | + assertMacroExpansion( |
| 147 | + """ |
| 148 | + struct TestStruct { |
| 149 | + @Parametrize(input: [1], output: [1], labels: ["One"]) |
| 150 | + func testMethod(input n: Int, output r: Int) async throws { |
| 151 | + XCTAssertEqual(n,r) |
| 152 | + } |
| 153 | + } |
| 154 | + """, |
| 155 | + expandedSource: """ |
| 156 | + struct TestStruct { |
| 157 | + func testMethod(input n: Int, output r: Int) async throws { |
| 158 | + XCTAssertEqual(n,r) |
| 159 | + } |
| 160 | +
|
| 161 | + func testMethod_One() async throws { |
| 162 | + let n: Int = 1 |
| 163 | + let r: Int = 1 |
| 164 | + XCTAssertEqual(n, r) |
| 165 | + } |
| 166 | + } |
| 167 | + """, |
| 168 | + macros: testMacros |
| 169 | + ) |
| 170 | + } |
| 171 | +} |
0 commit comments