blob: 73878f04fdc47884a1a8476377f631c782f85745 [file] [log] [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as Common from './common.js';
describe('Base64 decoder', () => {
function decode(str: string) {
const encoded = btoa(str);
const decoded = Common.Base64.decode(encoded);
const view = new DataView(decoded.buffer);
for (let idx = 0; idx < str.length; idx++) {
assert.strictEqual(view.getUint8(idx), str.charCodeAt(idx));
}
}
it('decodes correctly with double padding', () => {
decode('ABCDEFG'); // Double-equals padded: QUJDREVGRw==
});
it('decodes correctly with padding', () => {
decode('ABCDE'); // Single-equals padded: QUJDREU=
});
it('decodes correctly without padding', () => {
decode('ABCDEF'); // Unpadded: QUJDREVG
});
});