79 lines
3.6 KiB
JavaScript
79 lines
3.6 KiB
JavaScript
var __values = (this && this.__values) || function(o) {
|
||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
||
if (m) return m.call(o);
|
||
if (o && typeof o.length === "number") return {
|
||
next: function () {
|
||
if (o && i >= o.length) o = void 0;
|
||
return { value: o && o[i++], done: !o };
|
||
}
|
||
};
|
||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
||
};
|
||
var __read = (this && this.__read) || function (o, n) {
|
||
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
||
if (!m) return o;
|
||
var i = m.call(o), r, ar = [], e;
|
||
try {
|
||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
||
}
|
||
catch (error) { e = { error: error }; }
|
||
finally {
|
||
try {
|
||
if (r && !r.done && (m = i["return"])) m.call(i);
|
||
}
|
||
finally { if (e) throw e.error; }
|
||
}
|
||
return ar;
|
||
};
|
||
import * as base64 from './base64';
|
||
// 测试用例来自以下地址
|
||
// https://github.com/LinusU/encode-utf8/blob/bd6c09b1c67baafc51853b1bea0e80bfe1e69ed0/test.js
|
||
var testCases = [
|
||
['正', '5q2j'],
|
||
['𝌆', '8J2Mhg'],
|
||
['💩', '8J-SqQ'],
|
||
['Hello, World!', 'SGVsbG8sIFdvcmxkIQ'],
|
||
['🐵 🙈 🙉 🙊', '8J-QtSDwn5mIIPCfmYkg8J-Zig'],
|
||
['åß∂ƒ©˙∆˚¬…æ', 'w6XDn-KIgsaSwqnLmeKIhsuawqzigKbDpg'],
|
||
['사회과학원 어학연구소', '7IKs7ZqM6rO87ZWZ7JuQIOyWtO2VmeyXsOq1rOyGjA'],
|
||
['゚・✿ヾ╲(。◕‿◕。)╱✿・゚', '776f772l4py_44O-4pWyKO-9oeKXleKAv-KXle-9oSnilbHinL_vvaXvvp8'],
|
||
['Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗', 'UG93ZXLZhNmP2YTZj9i12ZHYqNmP2YTZj9mE2LXZkdio2Y_Ysdix2Ysg4KWjIOClo2gg4KWjIOClo-WGlw'],
|
||
['𝕿𝖍𝖊 𝖖𝖚𝖎𝖈𝖐 𝖇𝖗𝖔𝖜𝖓 𝖋𝖔𝖝 𝖏𝖚𝖒𝖕𝖘 𝖔𝖛𝖊𝖗 𝖙𝖍𝖊 𝖑𝖆𝖟𝖞 𝖉𝖔𝖌', '8J2Vv_Cdlo3wnZaKIPCdlpbwnZaa8J2WjvCdlojwnZaQIPCdlofwnZaX8J2WlPCdlpzwnZaTIPCdlovwnZaU8J2WnSDwnZaP8J2WmvCdlpLwnZaV8J2WmCDwnZaU8J2Wm_CdlorwnZaXIPCdlpnwnZaN8J2WiiDwnZaR8J2WhvCdlp_wnZaeIPCdlonwnZaU8J2WjA']
|
||
];
|
||
describe('test base64', function () {
|
||
test('urlSafeBase64Encode', function () {
|
||
var e_1, _a;
|
||
try {
|
||
for (var testCases_1 = __values(testCases), testCases_1_1 = testCases_1.next(); !testCases_1_1.done; testCases_1_1 = testCases_1.next()) {
|
||
var _b = __read(testCases_1_1.value, 2), input = _b[0], expected = _b[1];
|
||
var actual = base64.urlSafeBase64Encode(input);
|
||
expect(actual).toMatch(expected);
|
||
}
|
||
}
|
||
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||
finally {
|
||
try {
|
||
if (testCases_1_1 && !testCases_1_1.done && (_a = testCases_1["return"])) _a.call(testCases_1);
|
||
}
|
||
finally { if (e_1) throw e_1.error; }
|
||
}
|
||
});
|
||
test('urlSafeBase64Decode', function () {
|
||
var e_2, _a;
|
||
try {
|
||
for (var testCases_2 = __values(testCases), testCases_2_1 = testCases_2.next(); !testCases_2_1.done; testCases_2_1 = testCases_2.next()) {
|
||
var _b = __read(testCases_2_1.value, 2), expected = _b[0], input = _b[1];
|
||
var actual = base64.urlSafeBase64Decode(input);
|
||
expect(actual).toMatch(expected);
|
||
}
|
||
}
|
||
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
||
finally {
|
||
try {
|
||
if (testCases_2_1 && !testCases_2_1.done && (_a = testCases_2["return"])) _a.call(testCases_2);
|
||
}
|
||
finally { if (e_2) throw e_2.error; }
|
||
}
|
||
});
|
||
});
|
||
//# sourceMappingURL=base64.test.js.map
|