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

Handle type names prefixed with any #225

Merged
merged 1 commit into from
Jan 16, 2025
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
4 changes: 3 additions & 1 deletion Sources/KnitCodeGen/TypeNamer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ enum TypeNamer {
// The naming doesn't work for function types, just return closure
return "closure"
}
// Drop any annotation
var type = type.replacingOccurrences(of: "any ", with: "")
let removedCharacters = CharacterSet(charactersIn: "?[]():&, ")
var type = type.components(separatedBy: removedCharacters).joined(separator: "")
type = type.components(separatedBy: removedCharacters).joined(separator: "")
let regex = try! NSRegularExpression(pattern: "<.*>")
let nsString = type as NSString
if let match = regex.firstMatch(in: type, range: .init(location: 0, length: type.count)) {
Expand Down
12 changes: 12 additions & 0 deletions Tests/KnitCodeGenTests/TypeNamerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ final class TypeNamerTests: XCTestCase {
)
}

func testAnyPrefix() {
assertComputedIdentifier(
type: "(any AppTransitionObservable)",
expectedIdentifier: "appTransitionObservable"
)

assertComputedIdentifier(
type: "any AppTransitionObservable",
expectedIdentifier: "appTransitionObservable"
)
}

}

private func assertComputedIdentifier(
Expand Down