mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:57:35 +00:00
LibJS: Add UTF-16 tests to String.prototype methods that already work
These methods did not require UTF-16 views, so just add test cases to ensure they remain correct. This also adds a couple of FIXME comments on tests that will fail even with UTF-16 String.prototype support (for reasons such as lack of UTF-16 support in RegExp.prototype and Unicode case folding).
This commit is contained in:
parent
9b83cd1abf
commit
0e25d2393f
6 changed files with 32 additions and 0 deletions
|
@ -298,6 +298,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::index_of)
|
||||||
// 22.1.3.26 String.prototype.toLowerCase ( ), https://tc39.es/ecma262/#sec-string.prototype.tolowercase
|
// 22.1.3.26 String.prototype.toLowerCase ( ), https://tc39.es/ecma262/#sec-string.prototype.tolowercase
|
||||||
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_lowercase)
|
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_lowercase)
|
||||||
{
|
{
|
||||||
|
// FIXME: Implement Unicode case folding: https://www.unicode.org/Public/13.0.0/ucd/CaseFolding.txt
|
||||||
auto string = ak_string_from(vm, global_object);
|
auto string = ak_string_from(vm, global_object);
|
||||||
if (!string.has_value())
|
if (!string.has_value())
|
||||||
return {};
|
return {};
|
||||||
|
@ -307,6 +308,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_lowercase)
|
||||||
// 22.1.3.28 String.prototype.toUpperCase ( ), https://tc39.es/ecma262/#sec-string.prototype.touppercase
|
// 22.1.3.28 String.prototype.toUpperCase ( ), https://tc39.es/ecma262/#sec-string.prototype.touppercase
|
||||||
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_uppercase)
|
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_uppercase)
|
||||||
{
|
{
|
||||||
|
// FIXME: Implement Unicode case folding: https://www.unicode.org/Public/13.0.0/ucd/CaseFolding.txt
|
||||||
auto string = ak_string_from(vm, global_object);
|
auto string = ak_string_from(vm, global_object);
|
||||||
if (!string.has_value())
|
if (!string.has_value())
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -15,3 +15,10 @@ test("basic functionality", () => {
|
||||||
expect("".concat(1, {})).toBe("1[object Object]");
|
expect("".concat(1, {})).toBe("1[object Object]");
|
||||||
expect("".concat(1, {}, false)).toBe("1[object Object]false");
|
expect("".concat(1, {}, false)).toBe("1[object Object]false");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("UTF-16", () => {
|
||||||
|
expect("😀".concat()).toBe("😀");
|
||||||
|
expect("😀".concat("a")).toBe("😀a");
|
||||||
|
expect("😀".concat("a", 4)).toBe("😀a4");
|
||||||
|
expect("😀".concat("a", "😀")).toBe("😀a😀");
|
||||||
|
});
|
||||||
|
|
|
@ -23,3 +23,9 @@ test("throws correct range errors", () => {
|
||||||
"foo".repeat(Infinity);
|
"foo".repeat(Infinity);
|
||||||
}).toThrowWithMessage(RangeError, "repeat count must be a finite number");
|
}).toThrowWithMessage(RangeError, "repeat count must be a finite number");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("UTF-16", () => {
|
||||||
|
expect("😀".repeat(0)).toBe("");
|
||||||
|
expect("😀".repeat(1)).toBe("😀");
|
||||||
|
expect("😀".repeat(10)).toBe("😀😀😀😀😀😀😀😀😀😀");
|
||||||
|
});
|
||||||
|
|
|
@ -45,3 +45,11 @@ test("override exec with non-function", () => {
|
||||||
re.exec = 3;
|
re.exec = 3;
|
||||||
expect("test".search(re)).toBe(0);
|
expect("test".search(re)).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// FIXME: RegExp.prototype [ @@search ] needs to support UTF-16.
|
||||||
|
// test("UTF-16", () => {
|
||||||
|
// var s = "😀";
|
||||||
|
// expect(s.search("😀")).toBe(0);
|
||||||
|
// expect(s.search("\ud83d")).toBe(0);
|
||||||
|
// expect(s.search("\ude00")).toBe(1);
|
||||||
|
// });
|
||||||
|
|
|
@ -4,3 +4,8 @@ test("basic functionality", () => {
|
||||||
expect("".toString()).toBe("");
|
expect("".toString()).toBe("");
|
||||||
expect("hello friends".toString()).toBe("hello friends");
|
expect("hello friends".toString()).toBe("hello friends");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("UTF-16", () => {
|
||||||
|
expect("😀".toString()).toBe("😀");
|
||||||
|
expect("😀😀😀".toString()).toBe("😀😀😀");
|
||||||
|
});
|
||||||
|
|
|
@ -61,4 +61,8 @@ test("multi-byte code point", () => {
|
||||||
expect("_\u180E".trim()).toBe("_\u180E");
|
expect("_\u180E".trim()).toBe("_\u180E");
|
||||||
expect("\u180E".trim()).toBe("\u180E");
|
expect("\u180E".trim()).toBe("\u180E");
|
||||||
expect("\u180E_".trim()).toBe("\u180E_");
|
expect("\u180E_".trim()).toBe("\u180E_");
|
||||||
|
|
||||||
|
expect("_😀".trim()).toBe("_😀");
|
||||||
|
expect("😀".trim()).toBe("😀");
|
||||||
|
expect("😀_".trim()).toBe("😀_");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue