Skip to content

Commit 9a2bd6a

Browse files
authored
Merge pull request #2762 from ahoppen/if-config-fixups
Make position marker in `ActiveRegionTests` be ascending
2 parents 26d84ab + b39ea52 commit 9a2bd6a

File tree

5 files changed

+28
-29
lines changed

5 files changed

+28
-29
lines changed

Sources/SwiftIfConfig/ActiveSyntaxVisitor.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ import SwiftSyntax
3737
/// it would not visit either `f` or `g`.
3838
///
3939
/// All notes visited by this visitor will have the "active" state, i.e.,
40-
/// `node.isActive(in: configuration)` will have evaluated to `.active`
41-
/// When errors occur, they will be recorded in the set of
42-
/// diagnostics.
40+
/// `node.isActive(in: configuration)` will have evaluated to `.active`.
41+
/// When errors occur, they will be recorded in the array of diagnostics.
4342
open class ActiveSyntaxVisitor<Configuration: BuildConfiguration>: SyntaxVisitor {
4443
/// The build configuration, which will be queried for each relevant `#if`.
4544
public let configuration: Configuration

Sources/SwiftIfConfig/SwiftIfConfig.docc/SwiftIfConfig.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The syntax tree and its parser do not reason about the build configuration. Rath
2727
The `SwiftIfConfig` library provides utilities to determine which syntax nodes are part of a particular build configuration. Each utility requires that one provide a specific build configuration (i.e., an instance of a type that conforms to the <doc:BuildConfiguration> protocol), and provides a different view on essentially the same information:
2828

2929
* <doc:ActiveSyntaxVisitor> and <doc:ActiveSyntaxAnyVisitor> are visitor types that only visit the syntax nodes that are included ("active") for a given build configuration, implicitly skipping any nodes within inactive `#if` clauses.
30-
* `SyntaxProtocol/removingInactive(in:)` produces a syntax node that removes all inactive regions (and their corresponding `IfConfigDeclSyntax` nodes) from the given syntax tree, returning a new tree that is free of `#if` conditions.
30+
* `SyntaxProtocol.removingInactive(in:)` produces a syntax node that removes all inactive regions (and their corresponding `IfConfigDeclSyntax` nodes) from the given syntax tree, returning a new tree that is free of `#if` conditions.
3131
* `IfConfigDeclSyntax.activeClause(in:)` determines which of the clauses of an `#if` is active for the given build configuration, returning the active clause.
3232
* `SyntaxProtocol.isActive(in:)` determines whether the given syntax node is active for the given build configuration. The result is one of "active"
3333
(the node is included in the program), "inactive" (the node is not included

Tests/SwiftIfConfigTest/ActiveRegionTests.swift

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,56 +29,56 @@ public class ActiveRegionTests: XCTestCase {
2929
func testActiveRegions() throws {
3030
try assertActiveCode(
3131
"""
32-
4️⃣
32+
1️⃣
3333
#if DEBUG
34-
0️⃣func f()
34+
2️⃣func f()
3535
#elseif ASSERTS
36-
1️⃣func g()
36+
3️⃣func g()
3737
3838
#if compiler(>=8.0)
39-
2️⃣func h()
39+
4️⃣func h()
4040
#else
41-
3️⃣var i
41+
5️⃣var i
4242
#endif
4343
#endif
44-
5️⃣token
44+
6️⃣token
4545
""",
4646
configuration: linuxBuildConfig,
4747
states: [
48-
"0️⃣": .active,
49-
"1️⃣": .inactive,
50-
"2️⃣": .unparsed,
48+
"1️⃣": .active,
49+
"2️⃣": .active,
5150
"3️⃣": .inactive,
52-
"4️⃣": .active,
53-
"5️⃣": .active,
51+
"4️⃣": .unparsed,
52+
"5️⃣": .inactive,
53+
"6️⃣": .active,
5454
]
5555
)
5656
}
5757

5858
func testActiveRegionsInPostfix() throws {
5959
try assertActiveCode(
6060
"""
61-
4️⃣a.b()
61+
1️⃣a.b()
6262
#if DEBUG
63-
0️⃣.c()
63+
2️⃣.c()
6464
#elseif ASSERTS
65-
1️⃣.d()
65+
3️⃣.d()
6666
#if compiler(>=8.0)
67-
2️⃣.e()
67+
4️⃣.e()
6868
#else
69-
3️⃣.f()
69+
5️⃣.f()
7070
#endif
7171
#endif
72-
5️⃣.g()
72+
6️⃣.g()
7373
""",
7474
configuration: linuxBuildConfig,
7575
states: [
76-
"0️⃣": .active,
77-
"1️⃣": .inactive,
78-
"2️⃣": .unparsed,
76+
"1️⃣": .active,
77+
"2️⃣": .active,
7978
"3️⃣": .inactive,
80-
"4️⃣": .active,
81-
"5️⃣": .active,
79+
"4️⃣": .unparsed,
80+
"5️⃣": .inactive,
81+
"6️⃣": .active,
8282
]
8383
)
8484
}
@@ -104,7 +104,7 @@ public class ActiveRegionTests: XCTestCase {
104104

105105
/// Assert that the various marked positions in the source code have the
106106
/// expected active states.
107-
func assertActiveCode(
107+
fileprivate func assertActiveCode(
108108
_ markedSource: String,
109109
configuration: some BuildConfiguration = TestingBuildConfiguration(),
110110
states: [String: IfConfigRegionState],

Tests/SwiftIfConfigTest/EvaluateTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public class EvaluateTests: XCTestCase {
234234

235235
/// Assert the results of evaluating the condition within an `#if` against the
236236
/// given build configuration.
237-
func assertIfConfig(
237+
fileprivate func assertIfConfig(
238238
_ condition: ExprSyntax,
239239
_ expectedState: IfConfigRegionState,
240240
configuration: some BuildConfiguration = TestingBuildConfiguration(),

Tests/SwiftIfConfigTest/VisitorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public class VisitorTests: XCTestCase {
257257

258258
/// Assert that applying the given build configuration to the source code
259259
/// returns the expected source and diagnostics.
260-
func assertRemoveInactive(
260+
fileprivate func assertRemoveInactive(
261261
_ source: String,
262262
configuration: some BuildConfiguration,
263263
diagnostics expectedDiagnostics: [DiagnosticSpec] = [],

0 commit comments

Comments
 (0)