Skip to content

Commit 908ffcb

Browse files
committed
SR-5829: Improve code conditions and make tests more explicit
1 parent 944c109 commit 908ffcb

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
@@ -1240,10 +1240,13 @@ class TestNSString: LoopbackServerTest {
12401240
XCTAssertEqual("abcba".commonPrefix(with: "abcde"), "abc")
12411241
XCTAssertEqual("/path/to/file1".commonPrefix(with: "/path/to/file2"), "/path/to/file")
12421242
XCTAssertEqual("/a_really_long_path/to/a/file".commonPrefix(with: "/a_really_long_path/to/the/file"), "/a_really_long_path/to/")
1243-
XCTAssertEqual("Ma\u{308}dchen".commonPrefix(with: "Mädchenschule"), "Ma\u{308}dchen")
12441243
XCTAssertEqual("this".commonPrefix(with: "THAT", options: [.caseInsensitive]), "th")
1245-
XCTAssertEqual("this".commonPrefix(with: "THAT", options: [.caseInsensitive, .literal]), "th")
1246-
XCTAssertEqual("Ma\u{308}dchen".commonPrefix(with: "Mädchenschule", options: [.literal]), "M")
1244+
1245+
// Both forms of ä, a\u{308} decomposed and \u{E4} precomposed, should match without .literal and not match when .literal is used
1246+
XCTAssertEqual("Ma\u{308}dchen".commonPrefix(with: "M\u{E4}dchenschule"), "Ma\u{308}dchen")
1247+
XCTAssertEqual("Ma\u{308}dchen".commonPrefix(with: "M\u{E4}dchenschule", options: [.literal]), "M")
1248+
XCTAssertEqual("m\u{E4}dchen".commonPrefix(with: "M\u{E4}dchenschule", options: [.caseInsensitive, .literal]), "mädchen")
1249+
XCTAssertEqual("ma\u{308}dchen".commonPrefix(with: "M\u{E4}dchenschule", options: [.caseInsensitive, .literal]), "m")
12471250
}
12481251
}
12491252

0 commit comments

Comments
 (0)