diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-01 21:05:25 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-01 21:05:25 +0100 |
commit | 3565d3c60c43d29f35f309063de6b6a5dc70929a (patch) | |
tree | 85ca7e136026d6b0a885ca701bb87ad655b9b20b /Libraries/LibJS/Tests/builtins | |
parent | 93feb7a81fe7c1ca9603d94d24eeb5822c0c56f7 (diff) | |
download | serenity-3565d3c60c43d29f35f309063de6b6a5dc70929a.zip |
LibJS: Add six typed arrays (signed and unsigned 8/16/32-bit)
This patch adds six of the standard type arrays and tries to share as
much code as possible:
- Uint8Array
- Uint16Array
- Uint32Array
- Int8Array
- Int16Array
- Int32Array
Diffstat (limited to 'Libraries/LibJS/Tests/builtins')
-rw-r--r-- | Libraries/LibJS/Tests/builtins/TypedArray/typed-array-basic.js | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/Libraries/LibJS/Tests/builtins/TypedArray/typed-array-basic.js b/Libraries/LibJS/Tests/builtins/TypedArray/typed-array-basic.js new file mode 100644 index 0000000000..aeefb5bb54 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/TypedArray/typed-array-basic.js @@ -0,0 +1,86 @@ +test("basic Uint8Array", () => { + var a = new Uint8Array(1); + expect(typeof a).toBe("object"); + expect(a instanceof Uint8Array).toBe(true); + expect(a.length).toBe(1); + a[0] = 1; + expect(a[0]).toBe(1); + a[0] -= 2; + expect(a[0]).toBe(0xff); + ++a[0]; + expect(a[0]).toBe(0); +}); + +test("basic Uint16Array", () => { + var a = new Uint16Array(1); + expect(typeof a).toBe("object"); + expect(a instanceof Uint16Array).toBe(true); + expect(a.length).toBe(1); + a[0] = 1; + expect(a[0]).toBe(1); + a[0] -= 2; + expect(a[0]).toBe(0xffff); + ++a[0]; + expect(a[0]).toBe(0); +}); + +test("basic Uint32Array", () => { + var a = new Uint32Array(1); + expect(typeof a).toBe("object"); + expect(a instanceof Uint32Array).toBe(true); + expect(a.length).toBe(1); + a[0] = 1; + expect(a[0]).toBe(1); + a[0] -= 2; + expect(a[0]).toBe(0xffffffff); + ++a[0]; + expect(a[0]).toBe(0); +}); + +test("basic Int8Array", () => { + var a = new Int8Array(1); + expect(typeof a).toBe("object"); + expect(a instanceof Int8Array).toBe(true); + expect(a.length).toBe(1); + a[0] = 1; + expect(a[0]).toBe(1); + a[0] -= 2; + expect(a[0]).toBe(-1); + ++a[0]; + expect(a[0]).toBe(0); + a[0] = 127; + a[0]++; + expect(a[0]).toBe(-128); +}); + +test("basic Int16Array", () => { + var a = new Int16Array(1); + expect(typeof a).toBe("object"); + expect(a instanceof Int16Array).toBe(true); + expect(a.length).toBe(1); + a[0] = 1; + expect(a[0]).toBe(1); + a[0] -= 2; + expect(a[0]).toBe(-1); + ++a[0]; + expect(a[0]).toBe(0); + a[0] = 32767; + a[0]++; + expect(a[0]).toBe(-32768); +}); + +test("basic Int32Array", () => { + var a = new Int32Array(1); + expect(typeof a).toBe("object"); + expect(a instanceof Int32Array).toBe(true); + expect(a.length).toBe(1); + a[0] = 1; + expect(a[0]).toBe(1); + a[0] -= 2; + expect(a[0]).toBe(-1); + ++a[0]; + expect(a[0]).toBe(0); + a[0] = 0x7fffffff; + a[0]++; + expect(a[0]).toBe(-0x80000000); +}); |