forked from joaquimserafim/base64-url
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
64 lines (49 loc) · 1.32 KB
/
test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict'
const test = require('tape')
const base64url = require('./index')
test('base64', function (assert) {
let text = 'Node.js is awesome.'
let encode = base64url.encode(text)
assert.ok(encode, 'encode: ' + encode)
let decode = base64url.decode(encode)
assert.deepEqual(decode, text, 'decode: ' + decode)
let textEscape = 'This+is/goingto+escape=='
let escape = base64url.escape(textEscape)
assert.equal(
escape.match(/\+|\//g),
null,
'escape (omit + and /): ' + escape
)
let unescape = base64url.unescape(escape)
assert.equal(
unescape.match(/-|_/g),
null,
'unescape (back to initial state): ' + unescape
)
assert.equal(
base64url.unescape('1234'),
'1234',
'unescape should print 1234'
)
assert.equal(
base64url.unescape('123'),
'123=',
'unescape should print 123='
)
assert.end()
})
test('using a different econding with the encode and decode methods',
function (assert) {
assert.equal(
base64url.encode('ride: dreams burn down', 'ascii'),
'cmlkZTogZHJlYW1zIGJ1cm4gZG93bg',
'should return `cmlkZTogZHJlYW1zIGJ1cm4gZG93bg`'
)
assert.equal(
base64url.decode('cmlkZTogZHJlYW1zIGJ1cm4gZG93bg', 'ascii'),
'ride: dreams burn down',
'should return `ride: dreams burn down`'
)
assert.end()
}
)