Path: blob/master/node_modules/@protobufjs/base64/tests/index.js
2593 views
var tape = require("tape");12var base64 = require("..");34var strings = {5"": "",6"a": "YQ==",7"ab": "YWI=",8"abcdefg": "YWJjZGVmZw==",9"abcdefgh": "YWJjZGVmZ2g=",10"abcdefghi": "YWJjZGVmZ2hp"11};1213tape.test("base64", function(test) {1415Object.keys(strings).forEach(function(str) {16var enc = strings[str];1718test.equal(base64.test(enc), true, "should detect '" + enc + "' to be base64 encoded");1920var len = base64.length(enc);21test.equal(len, str.length, "should calculate '" + enc + "' as " + str.length + " bytes");2223var buf = new Array(len);24var len2 = base64.decode(enc, buf, 0);25test.equal(len2, len, "should decode '" + enc + "' to " + len + " bytes");2627test.equal(String.fromCharCode.apply(String, buf), str, "should decode '" + enc + "' to '" + str + "'");2829var enc2 = base64.encode(buf, 0, buf.length);30test.equal(enc2, enc, "should encode '" + str + "' to '" + enc + "'");3132});3334test.throws(function() {35var buf = new Array(10);36base64.decode("YQ!", buf, 0);37}, Error, "should throw if encoding is invalid");3839test.throws(function() {40var buf = new Array(10);41base64.decode("Y", buf, 0);42}, Error, "should throw if string is truncated");4344test.end();45});464748