Skip to content
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
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
Copyright (c) 2021-2025 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
Expand Down Expand Up @@ -317,9 +317,10 @@ struct SymbolGraphLoader {

// Fill introduced versions when missing.
availability.availability = availability.availability.map {
$0.fillingMissingIntroducedVersion(
let availabilityPlatformName = $0.domain.map { PlatformName(operatingSystemName: $0.rawValue) } ?? platformName
return $0.fillingMissingIntroducedVersion(
from: defaultAvailabilityVersionByPlatform,
fallbackPlatform: DefaultAvailability.fallbackPlatforms[platformName]?.rawValue
fallbackPlatform: DefaultAvailability.fallbackPlatforms[availabilityPlatformName]?.rawValue
)
}
// Add the module availability information to each of the symbols availability mixin.
Expand Down
35 changes: 32 additions & 3 deletions Tests/SwiftDocCTests/Rendering/SymbolAvailabilityTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2024 Apple Inc. and the Swift project authors
Copyright (c) 2024-2025 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
Expand Down Expand Up @@ -45,6 +45,7 @@ class SymbolAvailabilityTests: XCTestCase {
private func renderNodeAvailability(
defaultAvailability: [DefaultAvailability.ModuleAvailability] = [],
symbolGraphOperatingSystemPlatformName: String,
symbolGraphEnvironmentName: String? = nil,
symbols: [SymbolGraph.Symbol],
symbolName: String
) throws -> [AvailabilityRenderItem] {
Expand All @@ -56,7 +57,7 @@ class SymbolAvailabilityTests: XCTestCase {
]),
JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph(
moduleName: "ModuleName",
platform: SymbolGraph.Platform(architecture: nil, vendor: nil, operatingSystem: SymbolGraph.OperatingSystem(name: symbolGraphOperatingSystemPlatformName), environment: nil),
platform: SymbolGraph.Platform(architecture: nil, vendor: nil, operatingSystem: SymbolGraph.OperatingSystem(name: symbolGraphOperatingSystemPlatformName), environment: symbolGraphEnvironmentName),
symbols: symbols,
relationships: []
)),
Expand All @@ -71,7 +72,7 @@ class SymbolAvailabilityTests: XCTestCase {

func testSymbolGraphSymbolWithoutDeprecatedVersionAndIntroducedVersion() throws {

let availability = try renderNodeAvailability(
var availability = try renderNodeAvailability(
defaultAvailability: [],
symbolGraphOperatingSystemPlatformName: "ios",
symbols: [
Expand All @@ -91,6 +92,34 @@ class SymbolAvailabilityTests: XCTestCase {
"iPadOS <nil> - 1.2.3",
"Mac Catalyst <nil> - 1.2.3",
])

availability = try renderNodeAvailability(
defaultAvailability: [
DefaultAvailability.ModuleAvailability(platformName: PlatformName(operatingSystemName: "iOS"), platformVersion: "1.2.3")
],
symbolGraphOperatingSystemPlatformName: "ios",
symbolGraphEnvironmentName: "macabi",
symbols: [
makeSymbol(
id: "platform-1-symbol",
kind: .class,
pathComponents: ["SymbolName"],
availability: [
makeAvailabilityItem(domainName: "iOS", deprecated: SymbolGraph.SemanticVersion(string: "1.2.3")),
makeAvailabilityItem(domainName: "visionOS", deprecated: SymbolGraph.SemanticVersion(string: "1.0.0"))
]
)
],
symbolName: "SymbolName"
)

XCTAssertEqual(availability.map { "\($0.name ?? "<nil>") \($0.introduced ?? "<nil>") - \($0.deprecated ?? "<nil>")" }, [
// The default availability for iOS shouldnt be copied to visionOS.
"iOS 1.2.3 - 1.2.3",
"iPadOS 1.2.3 - <nil>",
"Mac Catalyst 1.2.3 - 1.2.3",
"visionOS <nil> - 1.0",
])
}

func testSymbolGraphSymbolWithObsoleteVersion() throws {
Expand Down