@@ -77,6 +77,34 @@ StringBridgeTests.test("Constant NSString New SPI") {
7777 }
7878}
7979
80+ StringBridgeTests . test ( " Shared String SPI " )
81+ . require ( . stdlib_6_2)
82+ . code {
83+ guard #available( SwiftStdlib 6 . 2 , * ) else { return }
84+ func test( literal: String , isASCII: Bool ) {
85+ let baseCount = literal. utf8. count
86+ literal. withCString { intptr in
87+ intptr. withMemoryRebound ( to: UInt8 . self, capacity: baseCount) { ptr in
88+ let fullBuffer = UnsafeBufferPointer ( start: ptr, count: baseCount)
89+ let fullString = _SwiftCreateImmortalString_ForFoundation (
90+ buffer: fullBuffer,
91+ isASCII: isASCII
92+ )
93+ expectNotNil ( fullString)
94+ let bridgedFullString = ( fullString! as NSString )
95+ let fullCString = bridgedFullString. utf8String!
96+ expectEqual ( baseCount, strlen ( fullCString) )
97+ expectEqual ( strcmp ( ptr, fullCString) , 0 )
98+ let fullCString2 = bridgedFullString. utf8String!
99+ expectEqual ( fullCString, fullCString2) //if we're already terminated, we can return the contents pointer as-is
100+ withExtendedLifetime ( fullString) { }
101+ }
102+ }
103+ }
104+ test ( literal: " abcdefghijklmnopqrstuvwxyz " , isASCII: true )
105+ test ( literal: " abcdëfghijklmnopqrstuvwxyz " , isASCII: false )
106+ }
107+
80108StringBridgeTests . test ( " Bridging " ) {
81109 // Test bridging retains small string form
82110 func bridge( _ small: _SmallString ) -> String {
0 commit comments