summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-07-19 17:24:23 -0400
committerAndreas Kling <kling@serenityos.org>2021-07-22 09:10:44 +0200
commit0e25d2393f2a7f49ded730d4a11643005ae9b468 (patch)
tree65b726fc728f7321bee9ab211b6a6be9642fbf81
parent9b83cd1abf984676924d35cf58664c501b3849b4 (diff)
downloadserenity-0e25d2393f2a7f49ded730d4a11643005ae9b468.zip
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).
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringPrototype.cpp2
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js7
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js6
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.search.js8
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js5
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js4
6 files changed, 32 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
index 715b118221..c7588b2f7f 100644
--- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
@@ -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
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);
if (!string.has_value())
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
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);
if (!string.has_value())
return {};
diff --git a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js
index 7a38877e9e..3f4162a2bd 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.concat.js
@@ -15,3 +15,10 @@ test("basic functionality", () => {
expect("".concat(1, {})).toBe("1[object Object]");
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😀");
+});
diff --git a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js
index 8427698509..c343c694d5 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.repeat.js
@@ -23,3 +23,9 @@ test("throws correct range errors", () => {
"foo".repeat(Infinity);
}).toThrowWithMessage(RangeError, "repeat count must be a finite number");
});
+
+test("UTF-16", () => {
+ expect("😀".repeat(0)).toBe("");
+ expect("😀".repeat(1)).toBe("😀");
+ expect("😀".repeat(10)).toBe("😀😀😀😀😀😀😀😀😀😀");
+});
diff --git a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.search.js b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.search.js
index 8419a3cf1e..07480adb9c 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.search.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.search.js
@@ -45,3 +45,11 @@ test("override exec with non-function", () => {
re.exec = 3;
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);
+// });
diff --git a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js
index 418f2da5f8..387921daa6 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.toString.js
@@ -4,3 +4,8 @@ test("basic functionality", () => {
expect("".toString()).toBe("");
expect("hello friends".toString()).toBe("hello friends");
});
+
+test("UTF-16", () => {
+ expect("😀".toString()).toBe("😀");
+ expect("😀😀😀".toString()).toBe("😀😀😀");
+});
diff --git a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js
index d5f7a0bec0..bc0f9ee67d 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/String/String.prototype.trim.js
@@ -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("_😀".trim()).toBe("_😀");
+ expect("😀".trim()).toBe("😀");
+ expect("😀_".trim()).toBe("😀_");
});