Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jajbshjahavahh
GitHub Repository: jajbshjahavahh/Gojo-Satoru
Path: blob/master/node_modules/@protobufjs/base64/tests/index.js
2593 views
1
var tape = require("tape");
2
3
var base64 = require("..");
4
5
var strings = {
6
"": "",
7
"a": "YQ==",
8
"ab": "YWI=",
9
"abcdefg": "YWJjZGVmZw==",
10
"abcdefgh": "YWJjZGVmZ2g=",
11
"abcdefghi": "YWJjZGVmZ2hp"
12
};
13
14
tape.test("base64", function(test) {
15
16
Object.keys(strings).forEach(function(str) {
17
var enc = strings[str];
18
19
test.equal(base64.test(enc), true, "should detect '" + enc + "' to be base64 encoded");
20
21
var len = base64.length(enc);
22
test.equal(len, str.length, "should calculate '" + enc + "' as " + str.length + " bytes");
23
24
var buf = new Array(len);
25
var len2 = base64.decode(enc, buf, 0);
26
test.equal(len2, len, "should decode '" + enc + "' to " + len + " bytes");
27
28
test.equal(String.fromCharCode.apply(String, buf), str, "should decode '" + enc + "' to '" + str + "'");
29
30
var enc2 = base64.encode(buf, 0, buf.length);
31
test.equal(enc2, enc, "should encode '" + str + "' to '" + enc + "'");
32
33
});
34
35
test.throws(function() {
36
var buf = new Array(10);
37
base64.decode("YQ!", buf, 0);
38
}, Error, "should throw if encoding is invalid");
39
40
test.throws(function() {
41
var buf = new Array(10);
42
base64.decode("Y", buf, 0);
43
}, Error, "should throw if string is truncated");
44
45
test.end();
46
});
47
48