mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Remove unreachable guard condition in String.asciified() (#4395)
This commit is contained in:
@@ -32,9 +32,6 @@ extension String {
|
|||||||
guard !isASCII else {
|
guard !isASCII else {
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
guard !canBeConverted(to: .ascii) else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
let mutableString = NSMutableString(string: self)
|
let mutableString = NSMutableString(string: self)
|
||||||
guard CFStringTransform(mutableString, nil, "Any-Latin; Latin-ASCII; [:^ASCII:] Remove" as CFString, false) else {
|
guard CFStringTransform(mutableString, nil, "Any-Latin; Latin-ASCII; [:^ASCII:] Remove" as CFString, false) else {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -30,24 +30,23 @@ class StringTests: XCTestCase {
|
|||||||
XCTAssertFalse("j🅾️hnny".isASCII)
|
XCTAssertFalse("j🅾️hnny".isASCII)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAsciiStaysAscii() {
|
func testAsciifiedMethod() {
|
||||||
|
// ASCII strings return themselves unchanged
|
||||||
XCTAssertEqual("johnny".asciified(), "johnny")
|
XCTAssertEqual("johnny".asciified(), "johnny")
|
||||||
}
|
XCTAssertEqual("hello".asciified(), "hello")
|
||||||
|
XCTAssertEqual("abc123".asciified(), "abc123")
|
||||||
|
XCTAssertEqual("".asciified(), "")
|
||||||
|
XCTAssertEqual(" ".asciified(), " ")
|
||||||
|
|
||||||
func testÖBecomesO() {
|
// Non-ASCII strings get converted or stripped
|
||||||
XCTAssertEqual("jöhnny".asciified(), "johnny")
|
XCTAssertEqual("jöhnny".asciified(), "johnny", "ö should become o")
|
||||||
}
|
XCTAssertEqual("jåhnny".asciified(), "jahnny", "å should become a")
|
||||||
|
XCTAssertEqual("café".asciified(), "cafe")
|
||||||
func testÅBecomesA() {
|
XCTAssertEqual("naïve".asciified(), "naive")
|
||||||
XCTAssertEqual("jåhnny".asciified(), "jahnny")
|
XCTAssertEqual("résumé".asciified(), "resume")
|
||||||
}
|
XCTAssertEqual("🚀".asciified(), "")
|
||||||
|
XCTAssertEqual("Heartbreak Hotel 🏩".asciified(), "Heartbreak Hotel", "The emoji should be stripped.")
|
||||||
func test1️⃣2️⃣3️⃣Becomes123() {
|
XCTAssertEqual("1️⃣2️⃣3️⃣".asciified(), "123", "The emoji should be converted to ASCII.")
|
||||||
XCTAssertEqual("1️⃣2️⃣3️⃣".asciified(), "123")
|
|
||||||
}
|
|
||||||
|
|
||||||
func testStripsTheHeartbreakHotel() {
|
|
||||||
XCTAssertEqual("Heartbreak Hotel 🏩".asciified(), "Heartbreak Hotel")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testGenerateBreakableWhitespaceEnd() {
|
func testGenerateBreakableWhitespaceEnd() {
|
||||||
|
|||||||
Reference in New Issue
Block a user