Files @ 51344a25b55d
Branch filter:

Location: CryptoJS/spec/test/utilSpec.js - annotation

Laman
array padding refactored into util
/* 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]]
	];
	
	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]));
		});
	});
});