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

Adding deprecated to @Available directive #851

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public struct AvailabilityRenderItem: Codable, Hashable, Equatable {
let platformName = PlatformName(metadataPlatform: availability.platform)
name = platformName?.displayName
introduced = availability.introduced
deprecated = availability.deprecated
}

/// Creates a new item with the given platform name and version string.
Expand Down
14 changes: 8 additions & 6 deletions Sources/SwiftDocC/Semantics/Metadata/Availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ extension Metadata {
///
/// `@Available` is analogous to the `@available` attribute in Swift: It allows you to specify a
/// platform version that the page relates to. To specify a platform and version, list the platform
/// name and use the `introduced` argument:
/// name and use the `introduced` argument. In addition, you can also specify a deprecated
/// version, using the `deprecated` argument:
///
/// ```markdown
/// @Available(macOS, introduced: "12.0")
/// @Available(macOS, introduced: "12.0", deprecated: "14.0")
/// ```
///
/// Any text can be given to the first argument, and will be displayed in the page's
Expand Down Expand Up @@ -48,8 +50,6 @@ extension Metadata {
public static let introducedVersion = "5.8"

public enum Platform: RawRepresentable, Hashable, DirectiveArgumentValueConvertible {
// FIXME: re-add `case any = "*"` when `isBeta` and `isDeprecated` are implemented
// cf. https://github.com/apple/swift-docc/issues/441
case macOS, iOS, watchOS, tvOS

case other(String)
Expand Down Expand Up @@ -90,16 +90,18 @@ extension Metadata {
@DirectiveArgumentWrapped(name: .unnamed)
public var platform: Platform

/// The platform version that this page applies to.
/// The platform version that this page was introduced in.
@DirectiveArgumentWrapped
public var introduced: String

// FIXME: `isBeta` and `isDeprecated` properties/arguments
// cf. https://github.com/apple/swift-docc/issues/441
/// The platform version that this page was deprecated in.
@DirectiveArgumentWrapped
public var deprecated: String? = nil

static var keyPaths: [String : AnyKeyPath] = [
"platform" : \Availability._platform,
"introduced" : \Availability._introduced,
"deprecated" : \Availability._deprecated,
]

public let originalMarkup: Markdown.BlockDirective
Expand Down
14 changes: 3 additions & 11 deletions Tests/SwiftDocCTests/Semantics/MetadataAvailabilityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ class MetadataAvailabilityTests: XCTestCase {
func testValidDirective() throws {
// assemble all the combinations of arguments you could give
let validArguments: [String] = [
// FIXME: isBeta and isDeprecated are unused (https://github.com/apple/swift-docc/issues/441)
// "isBeta: true",
// "isDeprecated: true",
// "isBeta: true, isDeprecated: true",
"deprecated: \"1.0\"",
]
// separate those that give a version so we can test the `*` platform separately
var validArgumentsWithVersion = ["introduced: \"1.0\""]
Expand All @@ -90,17 +87,12 @@ class MetadataAvailabilityTests: XCTestCase {
try assertValidAvailability(source: "@Available(\"My Package\", \(args))")
}

// also test for giving no platform
for args in validArguments {
try assertValidAvailability(source: "@Available(\(args))")
}
Comment on lines 89 to -96
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this code since it was never called because validArguments was always empty before. However now we have deprecated as a value within the array

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. It looks like this loop wasn't really testing what the comment says.

It also seems unnecessary to have 3 loops in this test. The entire "My Package" loop could be removed if there was an checkPlatforms.append("\"My Package\"") before the first loop.


// basic validity test for giving several directives
// FIXME: re-add isBeta after that is implemented (https://github.com/apple/swift-docc/issues/441)
let source = """
@Metadata {
@Available(macOS, introduced: "11.0")
@Available(iOS, introduced: "15.0")
@Available(watchOS, introduced: "7.0", deprecated: "9.0")
@Available("My Package", introduced: "0.1", deprecated: "1.0")
}
"""
try assertValidMetadata(source: source)
Expand Down