-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add symbolGraphMinimumAccessLevel option support (#82)
* Add symbolGraphMinimumAccessLevel option support * Remove experimental prefix * Fix CR suggestion
- Loading branch information
Showing
6 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Sources/SwiftDocCPluginUtilities/Arguments+symbolGraphMinimumAccessLevel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2022 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
|
||
import Foundation | ||
|
||
extension Arguments { | ||
/// The symbol graph minimum access level, if any, described by this set of command-line arguments. | ||
public var symbolGraphMinimumAccessLevel: String? { | ||
guard let accessLevelOptionIndex = firstIndex( | ||
where: { argument in | ||
return CommandLineOption.symbolGraphMinimumAccessLevel.possibleNames.contains(argument) | ||
} | ||
) else { | ||
return nil | ||
} | ||
let accessLevelIndex = index(after: accessLevelOptionIndex) | ||
guard indices.contains(accessLevelIndex) else { | ||
return nil | ||
} | ||
return self[accessLevelIndex] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Tests/SwiftDocCPluginUtilitiesTests/ArgumentsSymbolGraphMinimumAccessLevelTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
|
||
import Foundation | ||
import SwiftDocCPluginUtilities | ||
import XCTest | ||
|
||
final class ArgumentsSymbolGraphMinimumAccessLevelTests: XCTestCase { | ||
func testArgumentsThatContainAccessLevel() { | ||
XCTAssertEqual( | ||
Arguments(["--symbol-graph-minimum-access-level", "internal"]).symbolGraphMinimumAccessLevel, | ||
"internal" | ||
) | ||
|
||
XCTAssertEqual( | ||
Arguments(["other-arg", "--symbol-graph-minimum-access-level", "internal", "--other-flag"]).symbolGraphMinimumAccessLevel, | ||
"internal" | ||
) | ||
} | ||
|
||
func testArgumentsThatDoNotContainAccessLevel() { | ||
XCTAssertNil( | ||
Arguments(["--other-option", "/test-path"]).symbolGraphMinimumAccessLevel | ||
) | ||
|
||
XCTAssertNil( | ||
Arguments(["other-arg", "--other-option", "/test-path", "--other-flag"]).symbolGraphMinimumAccessLevel | ||
) | ||
} | ||
|
||
func testArgumentsThatContainTrailingAccessLevelFlag() { | ||
XCTAssertNil( | ||
Arguments(["--symbol-graph-minimum-access-level"]).symbolGraphMinimumAccessLevel | ||
) | ||
|
||
|
||
XCTAssertNil( | ||
Arguments(["other-arg", "--symbol-graph-minimum-access-level"]).symbolGraphMinimumAccessLevel | ||
) | ||
} | ||
} |