summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2020-07-22 09:38:39 -0400
committerAndreas Kling <kling@serenityos.org>2020-07-22 15:48:01 +0200
commit979e02c0a8b1bc63e9d825797631eb5ee5c6de6d (patch)
tree2753e6c0f407b4eabc6692baeb1237cd749e2ccf /Libraries/LibJS/Tests
parent7230b7aad7f47925d3b82dc8151662356b3a4e49 (diff)
downloadserenity-979e02c0a8b1bc63e9d825797631eb5ee5c6de6d.zip
LibJS: Implement String.prototype.charCodeAt
It's broken for strings with characters outside 7-bit ASCII, but it's broken in the same way as several existing functions (e.g. charAt()), so that's probably ok for now.
Diffstat (limited to 'Libraries/LibJS/Tests')
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js1
-rw-r--r--Libraries/LibJS/Tests/builtins/String/String.prototype.charCodeAt.js21
2 files changed, 22 insertions, 0 deletions
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js b/Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js
index 3d7d7468b6..f5c0ffa854 100644
--- a/Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype-generic-functions.js
@@ -1,6 +1,7 @@
test("basic functionality", () => {
const genericStringPrototypeFunctions = [
"charAt",
+ "charCodeAt",
"repeat",
"startsWith",
"indexOf",
diff --git a/Libraries/LibJS/Tests/builtins/String/String.prototype.charCodeAt.js b/Libraries/LibJS/Tests/builtins/String/String.prototype.charCodeAt.js
new file mode 100644
index 0000000000..e7ebd9d0d3
--- /dev/null
+++ b/Libraries/LibJS/Tests/builtins/String/String.prototype.charCodeAt.js
@@ -0,0 +1,21 @@
+test("basic functionality", () => {
+ expect(String.prototype.charAt).toHaveLength(1);
+
+ var s = "Foobar";
+ expect(typeof s).toBe("string");
+ expect(s).toHaveLength(6);
+
+ expect(s.charCodeAt(0)).toBe(70);
+ expect(s.charCodeAt(1)).toBe(111);
+ expect(s.charCodeAt(2)).toBe(111);
+ expect(s.charCodeAt(3)).toBe(98);
+ expect(s.charCodeAt(4)).toBe(97);
+ expect(s.charCodeAt(5)).toBe(114);
+ expect(s.charCodeAt(6)).toBe(NaN);
+ expect(s.charCodeAt(-1)).toBe(NaN);
+
+ expect(s.charCodeAt()).toBe(70);
+ expect(s.charCodeAt(NaN)).toBe(70);
+ expect(s.charCodeAt("foo")).toBe(70);
+ expect(s.charCodeAt(undefined)).toBe(70);
+});