Files
ladybird/Tests/LibJS/Runtime/string-rope-substrings.js
Andreas Kling a9bedc5a8d LibJS: Use Substring for string slices
Route the obvious substring-producing string operations through the
new PrimitiveString substring factory. Direct indexing, at(), charAt(),
slice(), substring(), substr(), and the plain-string split path can now
return lazy JS::Substring values backed by the original string.

Add runtime coverage for rope-backed string operations so these lazy
string slices stay exercised across both ASCII and UTF-16 inputs.
2026-04-11 00:35:36 +02:00

26 lines
910 B
JavaScript

test("string substring-producing operations work on ropes", () => {
let rope = "ab" + "cd";
expect(rope.at(1)).toBe("b");
expect(rope.charAt(2)).toBe("c");
expect(rope.slice(1, 3)).toBe("bc");
expect(rope.substring(1, 3)).toBe("bc");
expect(rope.substr(1, 2)).toBe("bc");
expect(rope.split("b")).toEqual(["a", "cd"]);
expect(rope[2]).toBe("c");
expect(new String(rope)[2]).toBe("c");
});
test("string substring-producing operations preserve UTF-16 code units on ropes", () => {
let rope = "😀" + "x";
expect(rope.at(0)).toBe("\ud83d");
expect(rope.charAt(1)).toBe("\ude00");
expect(rope.slice(1, 3)).toBe("\ude00x");
expect(rope.substring(1, 3)).toBe("\ude00x");
expect(rope.substr(1, 2)).toBe("\ude00x");
expect(rope.split("x")).toEqual(["😀", ""]);
expect(rope[1]).toBe("\ude00");
expect(new String(rope)[1]).toBe("\ude00");
});