Files
@ 5c8fceb4e291
Branch filter:
Location: CryptoJS/spec/test/utilSpec.js - annotation
5c8fceb4e291
1.7 KiB
text/javascript
I/O, user interface
9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e bcd08758ec7c bcd08758ec7c f425e00a94c6 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 9f2498ffdd4e ff3879ba7270 ff3879ba7270 ff3879ba7270 ff3879ba7270 ff3879ba7270 ff3879ba7270 ff3879ba7270 ff3879ba7270 ff3879ba7270 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 9f2498ffdd4e 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 90018dea7eac 9f2498ffdd4e | /* global expect */
describe("Util",function(){
let cryptoJS=require("../../dist/main.js");
let util=cryptoJS.util;
let utf=[ // https://tools.ietf.org/html/rfc3629#page-8
["",[]],
["abc",[97,98,99]],
["å",[195,165]],
["🚅",[240,159,154,133]],
["žír",[0xc5,0xbe,0xc3,0xad,114]],
["A\u2262\u0391.",[0x41,0xE2,0x89,0xA2,0xCE,0x91,0x2E]],
["\uD55C\uAD6D\uC5B4",[0xED,0x95,0x9C,0xEA,0xB5,0xAD,0xEC,0x96,0xB4]],
["\ud84c\udfb4",[0xf0,0xa3,0x8e,0xb4]]
];
let base64=[
[[],""],
[[102],"Zg=="],
[[102,111],"Zm8="],
[[102,111,111],"Zm9v"],
[[102,111,111,98],"Zm9vYg=="],
[[102,111,111,98,97],"Zm9vYmE="],
[[102,111,111,98,97,114],"Zm9vYmFy"]
];
describe("bytes2int32s",function(){
it("should pack bytes into 32b integers",function(){
expect(util.bytes2int32s([])).toEqual([]);
expect(util.bytes2int32s([0])).toEqual([0]);
expect(util.bytes2int32s([1])).toEqual([1]);
expect(util.bytes2int32s([0x12,0x34,0x56,0x78,0x9a])).toEqual([0x78563412,0x9a]);
});
});
describe("str2utf8",function(){
it("should encode a String into bytes in UTF-8",function(){
utf.forEach(couple=>expect(util.str2utf8(couple[0])).toEqual(couple[1]));
});
});
describe("utf82str",function(){
it("should decode a String from UTF-8 bytes",function(){
utf.forEach(couple=>expect(util.utf82str(couple[1])).toEqual(couple[0]));
});
});
describe("bytes2base64",function(){
it("should correctly encode bytes into base64",function(){
base64.forEach(couple=>expect(util.bytes2base64(couple[0])).toEqual(couple[1]));
});
});
describe("base642bytes",function(){
it("should correctly decode bytes from base64",function(){
base64.forEach(couple=>expect(util.base642bytes(couple[1])).toEqual(couple[0]));
});
});
});
|