Skip to content

Commit

Permalink
Support possible values inside property enums. (swiftlang#1041)
Browse files Browse the repository at this point in the history
With this change enum values that appear in the Properties section will render the allowed values they support under the enum type.

This was being rendered before and was removed in [a08f470](swiftlang@a08f470)

rdar://136542713
  • Loading branch information
sofiaromorales authored Sep 30, 2024
1 parent f66f704 commit 3dbde14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,9 @@ public struct RenderNodeTranslator: SemanticVisitor {
if let constraint = symbol.maximumLength {
attributes.append(RenderAttribute.maximumLength(String(constraint)))
}
if let constraint = symbol.allowedValues {
attributes.append(RenderAttribute.allowedValues(constraint.map { String($0) } ))
}
if let constraint = symbol.typeDetails, constraint.count > 0 {
// Pull out the base-type details.
typeDetails = constraint.filter { $0.baseType != nil }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,16 @@ class SemaToRenderNodeDictionaryDataTests: XCTestCase {
XCTAssertEqual(genreProperty.name, "genre")
XCTAssertTrue(genreProperty.readOnly ?? false)
attributeTitles = genreProperty.attributes?.map{$0.title.lowercased()}.sorted() ?? []
XCTAssertEqual(attributeTitles, ["default value"])
genreProperty.attributes?.forEach { attribute in
XCTAssertEqual(attributeTitles, ["default value", "possible values"])
let genrePropertyAttributes = try XCTUnwrap(genreProperty.attributes)
let genrePropertyAllowedValues = genrePropertyAttributes.filter {
switch $0 {
case .allowedValues(_): return true
default: return false
}
}
XCTAssertEqual(genrePropertyAllowedValues.count, 1)
genrePropertyAllowedValues.forEach { attribute in
if case let .allowedValues(values) = attribute {
XCTAssertEqual(values.count, 3)
XCTAssertEqual(values[0], "Classic Rock")
Expand Down

0 comments on commit 3dbde14

Please sign in to comment.