forked from ninjatronic/angular-base64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
50 lines (35 loc) · 1.3 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var test = require('tape');
var constants = {};
global.angular = {
module: function (moduleName, deps) {
return {
constant: function (constantName, value) { constants[constantName] = value; }
}
}
}
var b64 = require('./angular-base64.js');
test('constant registered', function (t) {
t.plan(1);
t.notEqual(undefined, constants.$base64);
})
test('can encode and decode non-padded', function (t) {
t.plan(2);
var text = "The quick brown fox jumps over the lazy doges";
var b64 = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZ2Vz";
t.equal(b64, constants.$base64.encode(text));
t.equal(text, constants.$base64.decode(b64));
})
test('can encode and decode padded', function (t) {
t.plan(2);
var text = "The quick brown fox jumps over the lazy dog";
var b64 = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==";
console.log(constants.$base64.encode(text))
t.equal(b64, constants.$base64.encode(text));
t.equal(text, constants.$base64.decode(b64));
})
test('can decode with padding missing', function (t) {
t.plan(1);
var text = "The quick brown fox jumps over the lazy dog";
var b64 = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw";
t.equal(text, constants.$base64.decode(b64));
})