File: base64.js

package info (click to toggle)
jsxgraph 1.3.5%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 26,044 kB
  • sloc: xml: 5,869; java: 1,072; python: 747; php: 192; makefile: 146; sh: 47
file content (116 lines) | stat: -rw-r--r-- 3,440 bytes parent folder | download | duplicates (3)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
define([
    'intern!object',
    'intern/chai!assert',
    'utils/base64'
], function (registerSuite, assert, Base64) {
    registerSuite({
        encode_asciiWithoutPadding_encodedString: function () {
            var actual,
                input = 'JXG',
                expected = 'SlhH';

            actual = Base64.encode(input);
            assert.strictEqual(actual, expected);
        },

        encode_asciiWith1BytePadding_encodedString: function () {
            var actual,
                input = 'JSXGraph',
                expected = 'SlNYR3JhcGg=';

            actual = Base64.encode(input);
            assert.strictEqual(actual, expected);
        },

        encode_asciiWith2BytePadding_encodedString: function () {
            var actual,
                input = 'J',
                expected = 'Sg==';

            actual = Base64.encode(input);
            assert.strictEqual(actual, expected);
        },

        encode_utf8_encodedString: function () {
            var actual,
                input = '\u3053\u3093\u306B\u3061\u306F',
                expected = '44GT44KT44Gr44Gh44Gv';

            actual = Base64.encode(input);
            assert.strictEqual(actual, expected);
        },

        decode_asciiWithoutPadding_decodedString: function () {
            var actual,
                input = 'SlhH',
                expected = 'JXG';

            actual = Base64.decode(input);
            assert.strictEqual(actual, expected);
        },

        decode_asciiWith1BytePadding_decodedString: function () {
            var actual,
                input = 'SlNYR3JhcGg=',
                expected = 'JSXGraph';

            actual = Base64.decode(input);
            assert.strictEqual(actual, expected);
        },

        decode_asciiWith2BytePadding_decodedString: function () {
            var actual,
                input = 'Sg==',
                expected = 'J';

            actual = Base64.decode(input);
            assert.strictEqual(actual, expected);
        },

        decode_asciiWithoutPaddingUseUTF8_decodedString: function () {
            var actual,
                input = 'SlhH',
                expected = 'JXG';

            actual = Base64.decode(input, true);
            assert.strictEqual(actual, expected);
        },

        decode_utf8_decodedString: function () {
            var actual,
                input = '44GT44KT44Gr44Gh44Gv',
                expected = '\u3053\u3093\u306B\u3061\u306F';

            actual = Base64.decode(input, true);
            assert.strictEqual(actual, expected);
        },

        decode_asciiWith1BytePaddingMissing_throwsError: function () {
            var actual,
                input = 'SlNYR3JhcGg',
                decode = function () {
                    Base64.decode(input);
                };

            assert.throws(decode, Error, /.*?invalid input length.*/);
        },

        decode_withInvalidCharacters_stillWorks: function () {
            var actual,
                input = 'S~g!!=()=',
                expected = 'J';

            actual = Base64.decode(input);
            assert.strictEqual(actual, expected);
        },

        decodeAsArray_ascii_returnsArray: function () {
            var actual,
                input = 'SlhH',
                expected = [74, 88, 71];

            actual = Base64.decodeAsArray(input);
            assert.deepEqual(actual, expected);
        }
    });
});