Skip to content

Commit

Permalink
add some tests, rename
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jul 22, 2023
1 parent 5bc70f6 commit 2972525
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/core-js/stage/3.js
Expand Up @@ -6,7 +6,7 @@ require('../proposals/array-from-async-stage-2');
require('../proposals/array-grouping-v2');
require('../proposals/decorator-metadata-v2');
require('../proposals/explicit-resource-management');
require('../proposals/float16array');
require('../proposals/float16');
require('../proposals/iterator-helpers-stage-3-2');
require('../proposals/json-parse-with-source');
require('../proposals/promise-with-resolvers');
Expand Down
2 changes: 1 addition & 1 deletion tests/entries/unit.mjs
Expand Up @@ -920,7 +920,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
load('proposals/efficient-64-bit-arithmetic');
load('proposals/error-cause');
load('proposals/explicit-resource-management');
load('proposals/float16array');
load('proposals/float16');
load('proposals/function-demethodize');
load('proposals/function-is-callable-is-constructor');
load('proposals/function-un-this');
Expand Down
44 changes: 44 additions & 0 deletions tests/unit-global/esnext.data-view.set-float16.js
@@ -0,0 +1,44 @@
QUnit.test('DataView.prototype.{ getFloat16, setFloat16 }', assert => {
const { getFloat16, setFloat16 } = DataView.prototype;

assert.isFunction(getFloat16);
assert.arity(getFloat16, 1);
assert.name(getFloat16, 'getFloat16');

assert.isFunction(setFloat16);
assert.arity(setFloat16, 2);
assert.name(setFloat16, 'setFloat16');

assert.same(new DataView(new ArrayBuffer(8)).setFloat16(0, 0), undefined, 'void');

function toString(it) {
return it === 0 && 1 / it === -Infinity ? '-0' : it;
}

const data = [
[0b0000000000000000, 0],
[0b1000000000000000, -0],
[0b0011110000000000, 1],
[0b1011110000000000, -1],
[0b0100001001001000, 3.140625],
[0b0000001000000000, 0.000030517578125],
[0b0111101111111111, 65504],
[0b1111101111111111, -65504],
[0b0000000000000001, 2 ** -24],
[0b1000000000000001, -(2 ** -24)],
// [0b0111110000000001, NaN], <- what NaN should be used?
[0b0111110000000000, Infinity],
[0b1111110000000000, -Infinity],
];

const buffer = new ArrayBuffer(2);
const view = new DataView(buffer);

for (const [bin, f16] of data) for (const LE of [false, true]) {
view.setUint16(0, bin, LE);
assert.same(view.getFloat16(0, LE), f16, `DataView.prototype.setUint16 + DataView.prototype.getFloat16, LE: ${ LE }, ${ toString(bin) } -> ${ toString(f16) }`);
view.setFloat16(0, f16, LE);
assert.same(view.getUint16(0, LE), bin, `DataView.prototype.setFloat16 + DataView.prototype.getUint16, LE: ${ LE }, ${ toString(f16) } -> ${ toString(bin) }`);
assert.same(view.getFloat16(0, LE), f16, `DataView.prototype.setFloat16 + DataView.prototype.getFloat16, LE: ${ LE }, ${ toString(f16) }`);
}
});
4 changes: 2 additions & 2 deletions tests/unit-global/esnext.data-view.set-uint8-clamped.js
Expand Up @@ -74,8 +74,8 @@ QUnit.test('DataView.prototype.{ getUint8Clamped, setUint8Clamped }', assert =>

for (const [value, conversion, little] of data) {
view.setUint8Clamped(0, value);
assert.same(view.getUint8Clamped(0, value), conversion, `DataView.prototype.setUint8Clamped + DataView.prototype.getUint8Clamped, ${ toString(value) } -> ${ toString(conversion) }`);
assert.same(view.getUint8(0, value), conversion, `DataView.prototype.setUint8Clamped + DataView.prototype.getUint8, ${ toString(value) } -> ${ toString(conversion) }`);
assert.same(view.getUint8Clamped(0), conversion, `DataView.prototype.setUint8Clamped + DataView.prototype.getUint8Clamped, ${ toString(value) } -> ${ toString(conversion) }`);
assert.same(view.getUint8(0), conversion, `DataView.prototype.setUint8Clamped + DataView.prototype.getUint8, ${ toString(value) } -> ${ toString(conversion) }`);
if (DESCRIPTORS) assert.arrayEqual(array, little, `DataView.prototype.setUint8Clamped + Uint8Array ${ toString(value) } -> [${ little }]`);
}
});

0 comments on commit 2972525

Please sign in to comment.