Files
craft-anything/crates/formats/tests/swift_demangle_equatable.rs
Cr 3f4c54bdd4 Read the Swift standard type SQ as Equatable (R3.12) (#1350)
The two-letter standard type `SQ` in a Swift mangling is the protocol `Swift.Equatable`, and the demangler read it as the enum `ImplicitlyUnwrappedOptional`, so generic constraints named the wrong type and conformances to Equatable were reported invalid. It now reads `SQ` as `Swift.Equatable` in all three manglings.
2026-11-09 20:38:15 +07:00

39 lines
2.0 KiB
Rust

use craft_anything_formats::swift_demangle::{Status, demangle};
fn dm(symbol: &str) -> String {
let d = demangle(symbol);
assert_eq!(d.status, Status::Demangled, "{symbol}: {:?}", d.reason);
d.demangled.unwrap_or_default()
}
/// `SQ` is the standard protocol `Swift.Equatable`. Symbols from macOS 15.7 system binaries,
/// expected text from `swift-demangle`.
#[test]
fn sq_names_the_equatable_protocol() {
assert_eq!(dm("_$sSQMp"), "protocol descriptor for Swift.Equatable");
// `swift-demangle` also prints `(extension in PodcastsFoundation):`, which this demangler leaves out.
assert_eq!(
dm("_$sSo14NSUserDefaultsC18PodcastsFoundationE14queryPublishery7Combine03AnyF0Vyxs5NeverOGxycSQRzlF"),
"__C.NSUserDefaults.queryPublisher<A where A: Swift.Equatable>(() -> A) -> Combine.AnyPublisher<A, Swift.Never>"
);
}
/// Conformances to `Equatable` need `SQ` to be a protocol; they were reported invalid.
#[test]
fn equatable_conformances_decode() {
assert_eq!(dm("_$s10Foundation4UUIDVSQAAMc"), "protocol conformance descriptor for Foundation.UUID : Swift.Equatable in Foundation");
assert_eq!(dm("_$sSnyxGSQsMc"), "protocol conformance descriptor for Swift.Range<A> : Swift.Equatable in Swift");
assert_eq!(dm("_$sSo6CGSizeVSQ12CoreGraphicsMc"), "protocol conformance descriptor for __C.CGSize : Swift.Equatable in CoreGraphics");
assert_eq!(dm("_$sSiSQsWP"), "protocol witness table for Swift.Int : Swift.Equatable in Swift");
}
/// `swift-demangle` reads `SQ` as `Equatable` in the `$S` and `_T0` manglings too. A spelled-out
/// `ImplicitlyUnwrappedOptional` keeps its `!` form.
#[test]
fn other_manglings_read_sq_the_same_way() {
assert_eq!(dm("_T0SQMp"), "protocol descriptor for Swift.Equatable");
assert_eq!(dm("$SSiSQsMc"), "protocol conformance descriptor for Swift.Int : Swift.Equatable in Swift");
assert_eq!(dm("$S4main3fooyyxSQRzlF"), "main.foo<A where A: Swift.Equatable>(A) -> ()");
assert_eq!(dm("$s4main1xs27ImplicitlyUnwrappedOptionalOySiGvp"), "main.x : Swift.Int!");
}