Porting String APIs to Subtring and fixing some tests

This commit is contained in:
Max Moiseev
2017-02-16 16:10:22 -08:00
parent 9a40996253
commit b1898ab768
6 changed files with 230 additions and 99 deletions

View File

@@ -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(_:)") {