summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests
diff options
context:
space:
mode:
authorLuke <luke.wilde@live.co.uk>2021-06-18 17:27:07 +0100
committerLinus Groh <mail@linusgroh.de>2021-06-18 18:13:31 +0100
commit8be7bdaac371a26989f61b4fb7c2b61b77372bcc (patch)
tree22fbff72c57e6b63ff37fc5036b835c4e4fd4f3e /Userland/Libraries/LibJS/Tests
parent68f11a272b1c012c0e43708bef70c142f9b039e8 (diff)
downloadserenity-8be7bdaac371a26989f61b4fb7c2b61b77372bcc.zip
LibJS: Add %TypedArray%.prototype.some
Diffstat (limited to 'Userland/Libraries/LibJS/Tests')
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.some.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.some.js b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.some.js
new file mode 100644
index 0000000000..a09588dc38
--- /dev/null
+++ b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.some.js
@@ -0,0 +1,68 @@
+const TYPED_ARRAYS = [
+ Uint8Array,
+ Uint16Array,
+ Uint32Array,
+ Int8Array,
+ Int16Array,
+ Int32Array,
+ Float32Array,
+ Float64Array,
+];
+
+const BIGINT_TYPED_ARRAYS = [BigUint64Array, BigInt64Array];
+
+test("length is 1", () => {
+ TYPED_ARRAYS.forEach(T => {
+ expect(T.prototype.some).toHaveLength(1);
+ });
+
+ BIGINT_TYPED_ARRAYS.forEach(T => {
+ expect(T.prototype.some).toHaveLength(1);
+ });
+});
+
+describe("errors", () => {
+ function errorTests(T) {
+ test(`requires at least one argument (${T.name})`, () => {
+ expect(() => {
+ new T().some();
+ }).toThrowWithMessage(
+ TypeError,
+ "TypedArray.prototype.some() requires at least one argument"
+ );
+ });
+
+ test(`callback must be a function (${T.name})`, () => {
+ expect(() => {
+ new T().some(undefined);
+ }).toThrowWithMessage(TypeError, "undefined is not a function");
+ });
+ }
+
+ TYPED_ARRAYS.forEach(T => errorTests(T));
+ BIGINT_TYPED_ARRAYS.forEach(T => errorTests(T));
+});
+
+test("basic functionality", () => {
+ TYPED_ARRAYS.forEach(T => {
+ const typedArray = new T([2, 4, 6]);
+ expect(typedArray.some(value => value === 2)).toBeTrue();
+ expect(typedArray.some(value => value === 4)).toBeTrue();
+ expect(typedArray.some(value => value === 6)).toBeTrue();
+ expect(typedArray.some(value => value % 2 === 0)).toBeTrue();
+ expect(typedArray.some(value => value % 2 === 1)).toBeFalse();
+ expect(typedArray.some(value => value < 2)).toBeFalse();
+ expect(typedArray.some(value => value > 2)).toBeTrue();
+ });
+
+ BIGINT_TYPED_ARRAYS.forEach(T => {
+ const typedArray = new T([2n, 4n, 6n]);
+ expect(typedArray.some(value => value === 2n)).toBeTrue();
+ expect(typedArray.some(value => value === 4n)).toBeTrue();
+ expect(typedArray.some(value => value === 6n)).toBeTrue();
+ expect(typedArray.some(value => value % 2n === 0n)).toBeTrue();
+ expect(typedArray.some(value => value % 2n === 1n)).toBeFalse();
+ expect(typedArray.some(value => value < 2n)).toBeFalse();
+ expect(typedArray.some(value => value > 2n)).toBeTrue();
+ });
+});