mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:37:35 +00:00
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.
This commit is contained in:
parent
7230b7aad7
commit
979e02c0a8
4 changed files with 40 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
const genericStringPrototypeFunctions = [
|
||||
"charAt",
|
||||
"charCodeAt",
|
||||
"repeat",
|
||||
"startsWith",
|
||||
"indexOf",
|
||||
|
|
|
@ -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);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue