Skip to content

Commit

Permalink
add tests for omitPadding option
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot committed Jul 8, 2024
1 parent ebee5f2 commit f2915a1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/built-ins/Uint8Array/prototype/toBase64/omit-padding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-uint8array.prototype.tobase64
description: Conversion of Uint8Arrays to base64 strings exercising the omitPadding option
features: [uint8array-base64, TypedArray]
---*/

// works with default alphabet
assert.sameValue((new Uint8Array([199, 239])).toBase64(), "x+8=");
assert.sameValue((new Uint8Array([199, 239])).toBase64({ omitPadding: false }), "x+8=");
assert.sameValue((new Uint8Array([199, 239])).toBase64({ omitPadding: true }), "x+8");
assert.sameValue((new Uint8Array([255])).toBase64({ omitPadding: true }), "/w");

// works with base64url alphabet
assert.sameValue((new Uint8Array([199, 239])).toBase64({ alphabet: "base64url" }), "x-8=");
assert.sameValue((new Uint8Array([199, 239])).toBase64({ alphabet: "base64url", omitPadding: false }), "x-8=");
assert.sameValue((new Uint8Array([199, 239])).toBase64({ alphabet: "base64url", omitPadding: true }), "x-8");
assert.sameValue((new Uint8Array([255])).toBase64({ alphabet: "base64url", omitPadding: true }), "_w");

// performs ToBoolean on the argument
assert.sameValue((new Uint8Array([255])).toBase64({ omitPadding: 0 }), "/w==");
assert.sameValue((new Uint8Array([255])).toBase64({ omitPadding: 1 }), "/w");

0 comments on commit f2915a1

Please sign in to comment.