NAME=elf swift
FILE=bins/elf/analysis/hello-swift
CMDS=i~lang[1]
EXPECT=<<EOF
swift
EOF
RUN

NAME=one longsym
FILE=--
CMDS=<<EOF
iD swift _$s13PasswordCheck11ContentViewV4bodyQrvg7SwiftUI05TupleD0VyAE0D0PAEE7paddingyQrAE4EdgeO3SetV_12CoreGraphics7CGFloatVSgtFQOyAE4TextV_Qo__AiEEAJyQrAN_ARtFQOyAiEE14textFieldStyleyQrqd__AE0oqR0Rd__lFQOyAE06SecureQ0VyATG_AE013RoundedBorderoqR0VQo__Qo_AiEE5alert11isPresented7contentQrAE7BindingVySbG_AE5AlertVyXEtFQOyAE6ButtonVyAiEE12cornerRadius_11antialiasedQrAQ_SbtFQOyAiEE15foregroundColoryQrAE5ColorVSgFQOyAiEE10background_20ignoresSafeAreaEdgesQrqd___ANtAE05ShapeR0Rd__lFQOyAU_A17_Qo__Qo__Qo_G_Qo_tGyXEfU_yycfU_
EOF
EXPECT=<<EOF
PasswordCheck.ContentView.body.SwiftUI.Tuple...D0VyAE0D0PAEE7paddingyQrAE4EdgeO3SetV_12CoreGraphics7CGFloatVSgtFQOyAE4TextV_Qo__AiEEAJyQrAN_ARtFQOyAiEE14textFieldStyleyQrqd__AE0oqR0Rd__lFQOyAE06SecureQ0VyATG_AE013RoundedBorderoqR0VQo__Qo_AiEE5alert11isPresented7contentQrAE7BindingVySbG_AE5AlertVyXEtFQOyAE6ButtonVyAiEE12cornerRadius_11antialiasedQrAQ_SbtFQOyAiEE15foregroundColoryQrAE5ColorVSgFQOyAiEE10background_20ignoresSafeAreaEdgesQrqd___ANtAE05ShapeR0Rd__lFQOyAU_A17_Qo__Qo__Qo_G_Qo_tGyXEfU_yycfU_
EOF
RUN

NAME=more demangling
FILE=--
CMDS=<<EOF
iD swift _$s10HomeWallet0A13DeeplinkModelV10launchIDFASSSgvM
iD swift _$s10HomeWallet0A12FileProviderC013getContentsOfC04with4type10Foundation4DataVSgSS_SStF
iD swift _$s10HomeWallet0A13DeeplinkModelV6pageIdSSSgvpfi
EOF
EXPECT=<<EOF
HomeWallet.DeeplinkModel.launchIDFA(...SgvM)
HomeWallet.FileProvider.getContentsOf.with.type__String(...tF)
HomeWallet.DeeplinkModel.pageId(...Sgvpfi)
EOF
RUN

NAME=aB swift demangling cases
FILE=--
CMDS=<<EOF
iD swift _$s10CartFacade0aB13ModalItemViewC14moreItemsLabelSo7UILabelCSgvgTq
EOF
EXPECT=<<EOF
CartFacade: ', ModalItemView.moreItemsLabel: ', C.more.UILabel(...gvgTq)
EOF
RUN

NAME=aB swift compact symbol
FILE=--
CMDS=<<EOF
iD swift $s9CryptoKit4P384O12KeyAgreementO07PrivateD0V20compactRepresentableAGSb_tcfC
EOF
EXPECT=<<EOF
CryptoKit.P384.KeyAgreement.Private(...cfC)
EOF
RUN

NAME=1b34 longsym
FILE=bins/mach0/PasswordCheck-swift
CMDS=<<EOF
is~1b34
EOF
EXPECT=<<EOF
5   0x00001b34 0x100001b34 LOCAL  FUNC 0        _$s13PasswordCheck11ContentViewV4bodyQrvg7SwiftUI05TupleD0VyAE0D0PAEE7paddingyQrAE4EdgeO3SetV_12CoreGraphics7CGFloatVSgtFQOyAE4TextV_Qo__AiEEAJyQrAN_ARtFQOyAiEE14textFieldStyleyQrqd__AE0oqR0Rd__lFQOyAE06SecureQ0VyATG_AE013RoundedBorderoqR0VQo__Qo_AiEE5alert11isPresented7contentQrAE7BindingVySbG_AE5AlertVyXEtFQOyAE6ButtonVyAiEE12cornerRadius_11antialiasedQrAQ_SbtFQOyAiEE15foregroundColoryQrAE5ColorVSgFQOyAiEE10background_20ignoresSafeAreaEdgesQrqd___ANtAE05ShapeR0Rd__lFQOyAU_A17_Qo__Qo__Qo_G_Qo_tGyXEfU_yycfU_                                                                                               PasswordCheck.ContentView.body.SwiftUI.Tuple...D0VyAE0D0PAEE7paddingyQrAE4EdgeO3SetV_12CoreGraphics7CGFloatVSgtFQOyAE4TextV_Qo__AiEEAJyQrAN_ARtFQOyAiEE14textFieldStyleyQrqd__AE0oqR0Rd__lFQOyAE06SecureQ0VyATG_AE013RoundedBorderoqR0VQo__Qo_AiEE5alert11isPresented7contentQrAE7BindingVySbG_AE5AlertVyXEtFQOyAE6ButtonVyAiEE12cornerRadius_11antialiasedQrAQ_SbtFQOyAiEE15foregroundColoryQrAE5ColorVSgFQOyAiEE10background_20ignoresSafeAreaEdgesQrqd___ANtAE05ShapeR0Rd__lFQOyAU_A17_Qo__Qo__Qo_G_Qo_tGyXEfU_yycfU_
378 0x00001b34 0x100001b34 LOCAL  FUNC 0        func.100001b34
EOF
RUN

NAME=swift long method
FILE=--
CMDS=iD swift s16IOSSecuritySuiteAAC14denySymbolHook_2at10imageSlideySS_SPySo11mach_headerVGSitFZ
EXPECT=<<EOF
IOSSecuritySuite..denySymbolHook.at.imageSlide(...eaderVGSitFZ)
EOF
RUN

NAME=swift long method
FILE=--
CMDS=iD swift s16IOSSecuritySuiteAAC16amIRuntimeHooked13dyldAllowList14detectionClass8selector02isJ6MethodSbSaySSG_yXlXp10ObjectiveC8SelectorVSbtFZ
EXPECT=<<EOF
IOSSecuritySuite..amIRuntimeHooked.dyldAllowList(...XlXp10ObjectiveC8SelectorVSbtFZ)
EOF
RUN

NAME=swift long multiple dupes
FILE=--
CMDS=iD swift $s9CryptoKit8Curve448O7SigningO9PublicKeyV17rawRepresentationAGx_tKc10Foundation15ContiguousBytesRzlufC
EXPECT=<<EOF
CryptoKit.Curve448.Signing.PublicKey.rawRepresentation.Foundation.ContiguousBytes(...lufC)
EOF
RUN

NAME=swift long multiple dupes 2
FILE=--
CMDS=iD swift s9CryptoKit8Curve448O7SigningO9PublicKeyV16isValidSignature_3forSbx_q_t10Foundation12DataProtocolRzAjKR_r0_lF
EXPECT=<<EOF
CryptoKit.Curve448.Signing.PublicKey.isValidSignature.for.Foundation.DataProtocol...r0_lF
EOF
RUN

NAME=swift long multiple dupes 3
FILE=--
CMDS=iD swift s9CryptoKit8Curve448O7SigningO9PublicKeyV17rawRepresentation10Foundation4DataVvg
EXPECT=<<EOF
CryptoKit.Curve448.Signing.PublicKey.rawRepresentation.Foundation.Data...Vvg
EOF
RUN

NAME=swift missing A2CmFWC attributes
FILE=--
CMDS=iD swift s16IOSSecuritySuite11FailedCheckO30restrictedDirectoriesWriteableyA2CmFWC
EXPECT=<<EOF
IOSSecuritySuite.FailedCheck.restrictedDirectoriesWriteable(...A2CmFWC)
EOF
RUN

NAME=elf swift demangle (requires swift-demangle program)
FILE=bins/elf/analysis/hello-swift
ARGS=-e bin.demangle.trylib=false
CMDS=isq~0x004009e0
EXPECT=<<EOF
0x004009e0 16 Swift.String.init(_builtinStringLiteral: Builtin.RawPointer, byteSize: Builtin.Word, isASCII: Builtin.Int1) -> Swift.String
EOF
RUN

NAME=macho swift demangle
FILE=bins/mach0/swift/klass.orig
CMDS=ic
EXPECT=<<EOF
0x00003cb0 [0x100003cff - 0x100003d90]    145 swift class 1 SomeClass
0x100003cff swift   method   0      0
0x100003d08 swift   method   1      1
0x100003d0e swift   method   2      2
0x100003d17 swift   method   3      3
0x100003d20 swift   method   4      4
0x100003d24 swift   method   5      5
0x100003d1d swift   method   6      6
0x100003d90 swift   method   7      allocator.(...cfCTq)
0x100003d2c swift   method   8      8
0x100003d34 swift   method   9      9
0x100003e8d swift property   0      meh
0x100003e91 swift property   1      cow
0x00003d44 [0x1000028f0 - 0x100003d9c]   5292 swift class 2 SuperKlass
0x1000028f0 swift   method   0      superfield.allocator__Swift.Int: allocatorsuperfield: allocatorS(...vg)
0x100002950 swift   method   1      superfield.allocator__Swift.Int: allocatorsuperfield: allocatorS(...vs)
0x1000029b0 swift   method   2      superfield.allocator__Swift.Int: allocatorsuperfield: allocatorS(...vM)
0x100002a10 swift   method   3      allocator.(...cfC)
0x100003d9c swift   method   4      4
0x100003e95 swift property   0      superfield
0x100008260 [0x100008260 - 0x100008260]      0 objc class 3 klass.SomeClass :: klass.SuperKlass
0x00000000 objc      var   0      isa
0x100003c80 objc      var   1      meh
0x100003c88 objc      var   2      cow
0x100008288 [0x100008288 - 0x100008288]      0 objc class 4 klass.SuperKlass :: Swift._SwiftObject
0x00000000 objc      var   0      isa
0x100003d30 objc      var   1      superfield
0x100002ab0 [0x100002ab0 - 0x100002ab0]      0 ? class 4 _swiftoverride_class_getSuperclass(swift
0x100002ab0 ?   method   0      TargetMetadata<swift::InProcess> const*)
0x100003620 [0x100003620 - 0x100008558]  20280 ? class 5 getObjCClassMetadata(swift
0x100003620 ?   method   0      TargetClassMetadata<swift::InProcess> const*)::$_1::operator()() const::{lambda(void*)#1}::__invoke(void*)
0x100008558 ?   method   1      TargetClassMetadata<swift::InProcess> const*)::$_1::operator()() const::TheLazy
0x100003670 [0x100003670 - 0x100008578]  20232 ? class 6 getTypeContextDescriptor(swift
0x100003670 ?   method   0      TargetMetadata<swift::InProcess> const*)::$_2::operator()() const::{lambda(void*)#1}::__invoke(void*)
0x100008578 ?   method   1      TargetMetadata<swift::InProcess> const*)::$_2::operator()() const::TheLazy
0x1000036b0 [0x1000036b0 - 0x100008588]  20184 ? class 7 getExistentialTypeMetadata(swift
0x1000036b0 ?   method   0      ProtocolClassConstraint, swift::TargetMetadata<swift::InProcess> const*, unsigned long, swift::TargetProtocolDescriptorRef<swift::InProcess> const*)::$_3::operator()() const::{lambda(void*)#1}::__invoke(void*)
0x100008588 ?   method   1      ProtocolClassConstraint, swift::TargetMetadata<swift::InProcess> const*, unsigned long, swift::TargetProtocolDescriptorRef<swift::InProcess> const*)::$_3::operator()() const::TheLazy
0x00000000 [0x100003e7e - 0x100003e7e]      0 ? class 8 SuperKlass_1
0x100003e7e ?   method   0      symbolic klass.SuperKlass.allocator
0x00000000 [0x100003e84 - 0x100003e84]      0 ? class 9 SomeClass_1
0x100003e84 ?   method   0      symbolic klass.SomeClass.allocator
0x00000000 [0x100002b70 - 0x100008568]  23032 c++ class 10 swift
0x100002b70 c++   method   0      getRootSuperclass()
0x100002bb0 c++   method   1      swift51override_conformsToSwiftProtocol(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*, llvm::StringRef, swift::TargetProtocolConformanceDescriptor<swift::InProcess> const* (*)(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*, llvm::StringRef))
0x100002bb0 c++   method   2      swift51override_conformsToSwiftProtocol(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*, llvm::StringRef, swift::TargetProtocolConformanceDescriptor<swift::InProcess> const* (*)(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*, llvm::StringRef))
0x1000031f0 c++   method   3      Lazy<(anonymous namespace)::ConformanceState>::defaultInitCallback(void*)
0x100003650 c++   method   4      getRootSuperclass()::$_0::operator()() const::{lambda(void*)#1}::__invoke(void*)
0x100008568 c++   method   5      getRootSuperclass()::$_0::operator()() const::TheLazy
EOF
RUN
