Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make position marker in ActiveRegionTests be ascending #2762

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Sources/SwiftIfConfig/ActiveSyntaxVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ import SwiftSyntax
/// it would not visit either `f` or `g`.
///
/// All notes visited by this visitor will have the "active" state, i.e.,
/// `node.isActive(in: configuration)` will have evaluated to `.active`
/// When errors occur, they will be recorded in the set of
/// diagnostics.
/// `node.isActive(in: configuration)` will have evaluated to `.active`.
/// When errors occur, they will be recorded in the array of diagnostics.
open class ActiveSyntaxVisitor<Configuration: BuildConfiguration>: SyntaxVisitor {
/// The build configuration, which will be queried for each relevant `#if`.
public let configuration: Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The syntax tree and its parser do not reason about the build configuration. Rath
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:

* <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.
* `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.
* `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.
* `IfConfigDeclSyntax.activeClause(in:)` determines which of the clauses of an `#if` is active for the given build configuration, returning the active clause.
* `SyntaxProtocol.isActive(in:)` determines whether the given syntax node is active for the given build configuration. The result is one of "active"
(the node is included in the program), "inactive" (the node is not included
Expand Down
46 changes: 23 additions & 23 deletions Tests/SwiftIfConfigTest/ActiveRegionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,56 +29,56 @@ public class ActiveRegionTests: XCTestCase {
func testActiveRegions() throws {
try assertActiveCode(
"""
4️⃣
1️⃣
#if DEBUG
0️⃣func f()
2️⃣func f()
#elseif ASSERTS
1️⃣func g()
3️⃣func g()

#if compiler(>=8.0)
2️⃣func h()
4️⃣func h()
#else
3️⃣var i
5️⃣var i
#endif
#endif
5️⃣token
6️⃣token
""",
configuration: linuxBuildConfig,
states: [
"0️⃣": .active,
"1️⃣": .inactive,
"2️⃣": .unparsed,
"1️⃣": .active,
"2️⃣": .active,
"3️⃣": .inactive,
"4️⃣": .active,
"5️⃣": .active,
"4️⃣": .unparsed,
"5️⃣": .inactive,
"6️⃣": .active,
]
)
}

func testActiveRegionsInPostfix() throws {
try assertActiveCode(
"""
4️⃣a.b()
1️⃣a.b()
#if DEBUG
0️⃣.c()
2️⃣.c()
#elseif ASSERTS
1️⃣.d()
3️⃣.d()
#if compiler(>=8.0)
2️⃣.e()
4️⃣.e()
#else
3️⃣.f()
5️⃣.f()
#endif
#endif
5️⃣.g()
6️⃣.g()
""",
configuration: linuxBuildConfig,
states: [
"0️⃣": .active,
"1️⃣": .inactive,
"2️⃣": .unparsed,
"1️⃣": .active,
"2️⃣": .active,
"3️⃣": .inactive,
"4️⃣": .active,
"5️⃣": .active,
"4️⃣": .unparsed,
"5️⃣": .inactive,
"6️⃣": .active,
]
)
}
Expand All @@ -104,7 +104,7 @@ public class ActiveRegionTests: XCTestCase {

/// Assert that the various marked positions in the source code have the
/// expected active states.
func assertActiveCode(
fileprivate func assertActiveCode(
_ markedSource: String,
configuration: some BuildConfiguration = TestingBuildConfiguration(),
states: [String: IfConfigRegionState],
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftIfConfigTest/EvaluateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public class EvaluateTests: XCTestCase {

/// Assert the results of evaluating the condition within an `#if` against the
/// given build configuration.
func assertIfConfig(
fileprivate func assertIfConfig(
_ condition: ExprSyntax,
_ expectedState: IfConfigRegionState,
configuration: some BuildConfiguration = TestingBuildConfiguration(),
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftIfConfigTest/VisitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public class VisitorTests: XCTestCase {

/// Assert that applying the given build configuration to the source code
/// returns the expected source and diagnostics.
func assertRemoveInactive(
fileprivate func assertRemoveInactive(
_ source: String,
configuration: some BuildConfiguration,
diagnostics expectedDiagnostics: [DiagnosticSpec] = [],
Expand Down