Skip to content

Commit 9a182d8

Browse files
committed
SR-5829: Improve code conditions and make tests more explicit
(cherry picked from commit 908ffcb)
1 parent 7004959 commit 9a182d8

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Foundation/NSString.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,10 @@ extension NSString {
449449
guard let otherCh = otherIterator.next() else { break }
450450

451451
if ch != otherCh {
452-
if !caseInsensitive || (String(otherCh).lowercased() != String(ch).lowercased()) {
453-
break
454-
}
452+
guard caseInsensitive && String(ch).lowercased() == String(otherCh).lowercased() else { break }
455453
}
456454

457-
if literal, otherCh.unicodeScalars.count != ch.unicodeScalars.count { break }
455+
if literal && otherCh.unicodeScalars.count != ch.unicodeScalars.count { break }
458456
result.append(ch)
459457
}
460458

TestFoundation/TestNSString.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,10 +1217,13 @@ class TestNSString: LoopbackServerTest {
12171217
XCTAssertEqual("abcba".commonPrefix(with: "abcde"), "abc")
12181218
XCTAssertEqual("/path/to/file1".commonPrefix(with: "/path/to/file2"), "/path/to/file")
12191219
XCTAssertEqual("/a_really_long_path/to/a/file".commonPrefix(with: "/a_really_long_path/to/the/file"), "/a_really_long_path/to/")
1220-
XCTAssertEqual("Ma\u{308}dchen".commonPrefix(with: "Mädchenschule"), "Ma\u{308}dchen")
12211220
XCTAssertEqual("this".commonPrefix(with: "THAT", options: [.caseInsensitive]), "th")
1222-
XCTAssertEqual("this".commonPrefix(with: "THAT", options: [.caseInsensitive, .literal]), "th")
1223-
XCTAssertEqual("Ma\u{308}dchen".commonPrefix(with: "Mädchenschule", options: [.literal]), "M")
1221+
1222+
// Both forms of ä, a\u{308} decomposed and \u{E4} precomposed, should match without .literal and not match when .literal is used
1223+
XCTAssertEqual("Ma\u{308}dchen".commonPrefix(with: "M\u{E4}dchenschule"), "Ma\u{308}dchen")
1224+
XCTAssertEqual("Ma\u{308}dchen".commonPrefix(with: "M\u{E4}dchenschule", options: [.literal]), "M")
1225+
XCTAssertEqual("m\u{E4}dchen".commonPrefix(with: "M\u{E4}dchenschule", options: [.caseInsensitive, .literal]), "mädchen")
1226+
XCTAssertEqual("ma\u{308}dchen".commonPrefix(with: "M\u{E4}dchenschule", options: [.caseInsensitive, .literal]), "m")
12241227
}
12251228
}
12261229

0 commit comments

Comments
 (0)