Skip to content

Commit

Permalink
[Tests] add more coverage from tc39/test262#3994
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 12, 2024
1 parent 6adae55 commit b0d4dd8
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 78 deletions.
47 changes: 47 additions & 0 deletions test/Uint8Array.fromBase64.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,39 @@ module.exports = {
SyntaxError
);

// partial padding
s2t['throws'](
function () { method('ZXhhZg='); },
SyntaxError
);
s2t['throws'](
function () { method('ZXhhZg=', { lastChunkHandling: 'loose' }); },
SyntaxError
);
s2t.deepEqual(method('ZXhhZg=', { lastChunkHandling: 'stop-before-partial' }), new Uint8Array([101, 120, 97]));
s2t['throws'](
function () { method('ZXhhZg=', { lastChunkHandling: 'strict' }); },
SyntaxError
);

// excess padding
s2t['throws'](
function () { method('ZXhhZg==='); },
SyntaxError
);
s2t['throws'](
function () { method('ZXhhZg===', { lastChunkHandling: 'loose' }); },
SyntaxError
);
s2t['throws'](
function () { method('ZXhhZg===', { lastChunkHandling: 'stop-before-partial' }); },
SyntaxError
);
s2t['throws'](
function () { method('ZXhhZg===', { lastChunkHandling: 'strict' }); },
SyntaxError
);

s2t.end();
});

Expand All @@ -194,6 +227,16 @@ module.exports = {
);
s2t.deepEqual(results(), []);

s2t['throws'](
function () { method('Zg==', { alphabet: Object('base64') }); },
TypeError
);

s2t['throws'](
function () { method('Zg==', { lastChunkHandling: Object('loose') }); },
TypeError
);

s2t.test('getters', { skip: !defineProperties.supportsDescriptors }, function (s3t) {
var base64UrlOptions = {};
var alphabetResults = s3t.intercept(base64UrlOptions, 'alphabet', { get: function () { return 'base64url'; } });
Expand Down Expand Up @@ -246,6 +289,7 @@ module.exports = {
forEach(standardBase64Vectors, function (pair) {
var arr = method(pair[0]);
s2t.equal(getProto(arr), Uint8Array.prototype, 'decoding ' + pair[0]);
s2t.equal(arr.buffer.byteLength, pair[1].length, 'decoding ' + pair[0]);
s2t.deepEqual(arr, new Uint8Array(pair[1]), 'decoding ' + pair[0]);
});

Expand Down Expand Up @@ -303,6 +347,9 @@ module.exports = {
];
forEach(whitespaceKinds, function (pair) {
var arr = method(pair[0]);

s2t.equal(arr.length, 1);
s2t.equal(arr.buffer.byteLength, 1);
s2t.deepEqual(arr, new Uint8Array([102]), 'ascii whitespace: ' + pair[1]);
});

Expand Down
9 changes: 5 additions & 4 deletions test/Uint8Array.fromHex.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ module.exports = {
'a\x0Da',
'a\u00A0a', // nbsp
'a\u2009a', // thin space
'a\u2028a' // line separator
'a\u2028a', // line separator
'a' // odd length input
];
forEach(illegal, function (value) {
st['throws'](
Expand All @@ -87,6 +88,8 @@ module.exports = {
forEach(cases, function (pair) {
var arr = method(pair[0]);
st.equal(getProto(arr), Uint8Array.prototype, 'decoding ' + pair[0]);
st.equal(arr.length, pair[1].length, 'decoding ' + pair[0]);
st.equal(arr.buffer.byteLength, pair[1].length, 'decoding ' + pair[0]);
st.deepEqual(arr, new Uint8Array(pair[1]), 'decoding ' + pair[0]);
});

Expand All @@ -95,9 +98,7 @@ module.exports = {
var results = s2t.intercept(
throwyToString,
'toString',
{
value: function () { throw new EvalError('toString called'); }
}
{ value: function () { throw new EvalError('toString called'); } }
);

s2t['throws'](
Expand Down
Loading

0 comments on commit b0d4dd8

Please sign in to comment.