mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Porting String APIs to Subtring and fixing some tests
This commit is contained in:
@@ -530,8 +530,8 @@ NSStringAPIs.test("enumerateLinguisticTagsIn(_:scheme:options:orthography:_:") {
|
||||
(tag: String, tokenRange: Range<String.Index>, sentenceRange: Range<String.Index>, stop: inout Bool)
|
||||
in
|
||||
tags.append(tag)
|
||||
tokens.append(s[tokenRange])
|
||||
sentences.append(s[sentenceRange])
|
||||
tokens.append(String(s[tokenRange]))
|
||||
sentences.append(String(s[sentenceRange]))
|
||||
if tags.count == 3 {
|
||||
stop = true
|
||||
}
|
||||
@@ -540,7 +540,7 @@ NSStringAPIs.test("enumerateLinguisticTagsIn(_:scheme:options:orthography:_:") {
|
||||
[NSLinguisticTagWord, NSLinguisticTagWhitespace, NSLinguisticTagWord],
|
||||
tags)
|
||||
expectEqual(["Глокая", " ", "куздра"], tokens)
|
||||
let sentence = s[startIndex..<endIndex]
|
||||
let sentence = String(s[startIndex..<endIndex])
|
||||
expectEqual([sentence, sentence, sentence], sentences)
|
||||
}
|
||||
|
||||
@@ -550,14 +550,16 @@ NSStringAPIs.test("enumerateSubstringsIn(_:options:_:)") {
|
||||
let endIndex = s.index(s.startIndex, offsetBy: 5)
|
||||
do {
|
||||
var substrings: [String] = []
|
||||
// FIXME(strings): this API should probably change to accept a Substring?
|
||||
// instead of a String? and a range.
|
||||
s.enumerateSubstrings(in: startIndex..<endIndex,
|
||||
options: String.EnumerationOptions.byComposedCharacterSequences) {
|
||||
(substring: String?, substringRange: Range<String.Index>,
|
||||
enclosingRange: Range<String.Index>, stop: inout Bool)
|
||||
in
|
||||
substrings.append(substring!)
|
||||
expectEqual(substring, s[substringRange])
|
||||
expectEqual(substring, s[enclosingRange])
|
||||
expectEqual(substring, String(s[substringRange]))
|
||||
expectEqual(substring, String(s[enclosingRange]))
|
||||
}
|
||||
expectEqual(["\u{304b}\u{3099}", "お", "☺️", "😀"], substrings)
|
||||
}
|
||||
@@ -569,7 +571,7 @@ NSStringAPIs.test("enumerateSubstringsIn(_:options:_:)") {
|
||||
enclosingRange: Range<String.Index>, stop: inout Bool)
|
||||
in
|
||||
expectNil(substring_)
|
||||
let substring = s[substringRange]
|
||||
let substring = String(s[substringRange])
|
||||
substrings.append(substring)
|
||||
expectEqual(substring, s[enclosingRange])
|
||||
}
|
||||
@@ -873,7 +875,7 @@ NSStringAPIs.test("linguisticTagsIn(_:scheme:options:orthography:tokenRanges:)")
|
||||
[NSLinguisticTagWord, NSLinguisticTagWhitespace, NSLinguisticTagWord],
|
||||
tags)
|
||||
expectEqual(["Глокая", " ", "куздра"],
|
||||
tokenRanges.map { s[$0] } )
|
||||
tokenRanges.map { String(s[$0]) } )
|
||||
}
|
||||
|
||||
NSStringAPIs.test("localizedCaseInsensitiveCompare(_:)") {
|
||||
|
||||
Reference in New Issue
Block a user