-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBase64.ts
More file actions
52 lines (40 loc) · 1.82 KB
/
Base64.ts
File metadata and controls
52 lines (40 loc) · 1.82 KB
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
import {expect} from 'chai';
import {Base64} from "../../src/helpers/Base64";
import {Utils} from "../../src/QueueITHelpers";
describe('Base64 encoding', () => {
it('should encode normal ascii text', () => {
const encoded = Base64.encode(Utils.stringToUint8Array("SomeText"));
expect(encoded).to.not.be.null
expect(encoded).to.equal("U29tZVRleHQ");
});
it('should encode utf-8 text', () => {
const encoded = Base64.encode(Utils.stringToUint8Array("14.95 €"));
expect(encoded).to.not.be.null
expect(encoded).to.equal("MTQuOTUg4oKs");
});
it('should encode utf-8 text 2', () => {
const encoded = Base64.encode(Utils.stringToUint8Array("⌷←⍳→⍴∆∇⊃‾⍎⍕⌈ 14.95 €"));
expect(encoded).to.not.be.null
expect(encoded).to.equal("4oy34oaQ4o2z4oaS4o204oiG4oiH4oqD4oC-4o2O4o2V4oyIIDE0Ljk1IOKCrA");
});
})
describe('Base64 decoding', () => {
it('should decode normal ascii text', ()=>{
const decoded = Base64.decode("U29tZVRleHQ");
expect(decoded).to.not.be.null;
expect(Utils.uint8ArrayToString(decoded)).to.equal('SomeText');
expect(decoded.length).to.be.equal(8);
});
it('should decode normal utf-8 text', ()=>{
const decoded = Base64.decode("MTQuOTUg4oKs");
expect(decoded).to.not.be.null;
expect(Utils.uint8ArrayToString(decoded)).to.equal('14.95 €')
expect(decoded.length).to.be.equal(9);
});
it('should decode normal utf-8 text 2', ()=>{
const decoded = Base64.decode("4oy34oaQ4o2z4oaS4o204oiG4oiH4oqD4oC-4o2O4o2V4oyIIDE0Ljk1IOKCrA");
expect(decoded).to.not.be.null;
expect(Utils.uint8ArrayToString(decoded)).to.equal('⌷←⍳→⍴∆∇⊃‾⍎⍕⌈ 14.95 €')
expect(decoded.length).to.be.equal(46);
});
})