Skip to content

Commit 31571a4

Browse files
authored
Add String tests from stdlib (#293)
* rdar://106770688 (Port test/stdlib/NSStringAPI.swift from the Swift repo) Batch add `String` and `Substring` tests for from stdlib to FCF. These were removed from stldlib in https://github.com/apple/swift/pull/67252/files and swiftlang/swift#67450. These tests were added to test Foundation's `StringProtocol` extension that called into `NSString` API. Now that some of the tests were implemented with Swift natively, they should be made available for FoundationPreview, but we'll track that in a separate PR. * Address review feedback: clean up availability annotations * Remove the need of swizzling current locale. Instead, add internal functions those localized functions can call into and pass in a locale explicitly for testing. * Remove the use of current locale in tests
1 parent 98e75de commit 31571a4

File tree

2 files changed

+1945
-1
lines changed

2 files changed

+1945
-1
lines changed

Sources/TestSupport/Utilities.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@ public func expectEqual(
8080
XCTAssertTrue(expected == actual, message(), file: file, line: line)
8181
}
8282

83+
public func expectEqualSequence< Expected: Sequence, Actual: Sequence>(
84+
_ expected: Expected, _ actual: Actual,
85+
_ message: @autoclosure () -> String = "",
86+
file: String = #file, line: UInt = #line,
87+
sameValue: (Expected.Element, Expected.Element) -> Bool
88+
) where Expected.Element == Actual.Element {
89+
if !expected.elementsEqual(actual, by: sameValue) {
90+
XCTFail("expected elements: \"\(expected)\"\n"
91+
+ "actual: \"\(actual)\" (of type \(String(reflecting: type(of: actual)))), \(message())")
92+
}
93+
}
94+
95+
public func expectEqualSequence< Expected: Sequence, Actual: Sequence>(
96+
_ expected: Expected, _ actual: Actual,
97+
_ message: @autoclosure () -> String = "",
98+
file: String = #file, line: UInt = #line
99+
) where Expected.Element == Actual.Element, Expected.Element: Equatable {
100+
expectEqualSequence(expected, actual, message()) {
101+
$0 == $1
102+
}
103+
}
104+
83105
func expectChanges<T: BinaryInteger>(_ check: @autoclosure () -> T, by difference: T? = nil, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line, _ expression: () throws -> ()) rethrows {
84106
let valueBefore = check()
85107
try expression()

0 commit comments

Comments
 (0)