// RUN: %target-run-stdlib-swift // REQUIRES: executable_test,optimized_stdlib // UNSUPPORTED: freestanding // Some targeted tests for the breadcrumbs path. There is some overlap with // UTF16View tests for huge strings, but we want a simpler suite that targets // some corner cases specifically. import Swift import StdlibUnittest let smallASCII = "abcdefg" let smallUnicode = "abรฉร๐“€€" let largeASCII = "012345678901234567890" let largeUnicode = "abรฉร012345678901234567890๐“€€" let emoji = "๐Ÿ˜€๐Ÿ˜ƒ๐Ÿคข๐Ÿคฎ๐Ÿ‘ฉ๐Ÿฟโ€๐ŸŽค๐Ÿง›๐Ÿปโ€โ™‚๏ธ๐Ÿง›๐Ÿปโ€โ™‚๏ธ๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘ฆโ€๐Ÿ‘ฆ" let chinese = "Swift ๆ˜ฏ้ขๅ‘ Apple ๅนณๅฐ็š„็ผ–็จ‹่ฏญ่จ€๏ผŒๅŠŸ่ƒฝๅผบๅคงไธ”็›ด่ง‚ๆ˜“็”จ๏ผŒ่€Œๆœฌๆฌกๆ›ดๆ–ฐๅฏนๅ…ถ่ฟ›่กŒไบ†ๅ…จ้ขไผ˜ๅŒ–ใ€‚" let nonBMP = String(repeating: "๐“€€", count: 1 + (64 / 2)) let largeString: String = { var result = "" result += smallASCII result += smallUnicode result += largeASCII result += chinese result += largeUnicode result += emoji result += smallASCII result += result.reversed() return result }() extension FixedWidthInteger { var hexStr: String { return "0x\(String(self, radix: 16, uppercase: true))" } } let StringBreadcrumbsTests = TestSuite("StringBreadcrumbsTests") func validateBreadcrumbs(_ str: String) { var utf16CodeUnits = Array(str.utf16) var outputBuffer = Array(repeating: 0, count: utf16CodeUnits.count) // Include the endIndex, so we can test end conversions var utf16Indices = Array(str.utf16.indices) + [str.utf16.endIndex] for i in 0...utf16CodeUnits.count { for j in i...utf16CodeUnits.count { let range = Range(uncheckedBounds: (i, j)) let indexRange = str._toUTF16Indices(range) // Range <=> Range expectEqual(utf16Indices[i], indexRange.lowerBound) expectEqual(utf16Indices[j], indexRange.upperBound) expectEqualSequence( utf16CodeUnits[i.. String.Index expectEqual(indexRange.lowerBound, str._toUTF16Index(i)) expectEqual(indexRange.upperBound, str._toUTF16Index(j)) expectEqual(i, str._toUTF16Offset(indexRange.lowerBound)) expectEqual(j, str._toUTF16Offset(indexRange.upperBound)) // Copy characters outputBuffer.withUnsafeMutableBufferPointer { str._copyUTF16CodeUnits(into: $0, range: range) } expectEqualSequence(utf16CodeUnits[i..