             let location = Int.random(in: 0..<(string.length - 1))
             let length = Int.random(in: 0..<(string.length - location))
             let range = NSRange(location: location, length: length)
-            let replacement = String("ab\nc".shuffled())
+            let replacement = String("ab\nc".prefix(Int.random(in: 0...4)).shuffled())
             
             lineString.string = lineString.string.replacingCharacters(in: range, with: replacement) as NSString
             lineString.invalidateLineRanges(from: range.location)
             
             for index in (0..<lineString.string.length).shuffled() {
-                XCTAssertEqual(lineString.lineNumber(at: index), (lineString.string as NSString).lineNumber(at: index))
-                XCTAssertEqual(lineString.lineRange(at: index), (lineString.string as NSString).lineRange(at: index))
-                XCTAssertEqual(lineString.lineStartIndex(at: index), (lineString.string as NSString).lineStartIndex(at: index), "At \(index) with string \"\(lineString.string)\"")
+                XCTAssertEqual(lineString.lineNumber(at: index), lineString.string.lineNumber(at: index),
+                               "At \(index) with string \"\(lineString.string)\"")
+                XCTAssertEqual(lineString.lineRange(at: index), lineString.string.lineRange(at: index),
+                               "At \(index) with string \"\(lineString.string)\"")
+                XCTAssertEqual(lineString.lineStartIndex(at: index), lineString.string.lineStartIndex(at: index),
+                               "At \(index) with string \"\(lineString.string)\"")
             }
         }
     }

    }
    
    
    func testStringModification() {
        
        let string = "\n🐶"

        XCTAssertEqual(lineString.lineNumber(at: 1), 2)
        XCTAssertEqual(lineString.lineRange(at: 1), NSRange(1..<3))  // "a\n"
        
        for _ in (0..<20) {
            let string = String(" dog \n cat \n cow \n".shuffled())
            let lineString = LineString(string)
            
