devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
220 lines (219 loc) • 6.4 kB
JavaScript
/**
* DevExtreme (esm/__internal/core/license/byte_utils.test.js)
* Version: 24.2.7
* Build date: Mon Apr 28 2025
*
* Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import {
describe,
expect,
it
} from "@jest/globals";
import {
base64ToBytes,
bytesToHex,
bytesToWords,
concatBytes,
hexToBytes,
leftRotate,
stringToBytes,
wordsToBytes,
wordsToHex
} from "./byte_utils";
describe("byte utils", (() => {
it.each([{
value: 1,
count: 1,
expected: 2
}, {
value: 1,
count: 2,
expected: 4
}, {
value: 1,
count: 32,
expected: 1
}, {
value: 3758096382,
count: 4,
expected: 4294967277
}])("performs left rotation", (_ref => {
let {
value: value,
count: count,
expected: expected
} = _ref;
expect(leftRotate(value, count)).toBe(expected)
}));
it.each([{
value: "",
expected: []
}, {
value: "L",
expected: [76]
}, {
value: "abc",
expected: [97, 98, 99]
}, {
value: "Lorem ipsum dolor sit amet",
expected: [76, 111, 114, 101, 109, 32, 105, 112, 115, 117, 109, 32, 100, 111, 108, 111, 114, 32, 115, 105, 116, 32, 97, 109, 101, 116]
}])("gets bytes from string", (_ref2 => {
let {
value: value,
expected: expected
} = _ref2;
expect(stringToBytes(value).toString()).toBe(expected.toString())
}));
it.each([{
value: "",
expected: []
}, {
value: "TA==",
expected: [76]
}, {
value: "YWJj",
expected: [97, 98, 99]
}, {
value: "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ=",
expected: [76, 111, 114, 101, 109, 32, 105, 112, 115, 117, 109, 32, 100, 111, 108, 111, 114, 32, 115, 105, 116, 32, 97, 109, 101, 116]
}])("gets bytes from base64 string", (_ref3 => {
let {
value: value,
expected: expected
} = _ref3;
expect(base64ToBytes(value)).toEqual(new Uint8Array(expected))
}));
it.each([{
value: "",
expected: []
}, {
value: "4c",
expected: [76]
}, {
value: "616263",
expected: [97, 98, 99]
}, {
value: "4c6f72656d20697073756d20646f6c6f722073697420616d6574",
expected: [76, 111, 114, 101, 109, 32, 105, 112, 115, 117, 109, 32, 100, 111, 108, 111, 114, 32, 115, 105, 116, 32, 97, 109, 101, 116]
}])("gets bytes from hex string", (_ref4 => {
let {
value: value,
expected: expected
} = _ref4;
expect(hexToBytes(value)).toEqual(new Uint8Array(expected))
}));
it.each([{
value: [],
expected: []
}, {
value: [1275068416],
expected: [76, 0, 0, 0]
}, {
value: [1282342912],
expected: [76, 111, 0, 0]
}, {
value: [1282372096],
expected: [76, 111, 114, 0]
}, {
value: [1282372197],
expected: [76, 111, 114, 101]
}, {
value: [1282372197, 1828716544],
expected: [76, 111, 114, 101, 109, 0, 0, 0]
}, {
value: [107967077, 1830840688, 1937075456],
expected: [6, 111, 114, 101, 109, 32, 105, 112, 115, 117, 109, 0]
}])("converts words to bytes", (_ref5 => {
let {
value: value,
expected: expected
} = _ref5;
expect(wordsToBytes(new Uint32Array(value))).toEqual(new Uint8Array(expected))
}));
it.each([{
value: [],
expected: []
}, {
value: [76],
expected: [1275068416]
}, {
value: [76, 111],
expected: [1282342912]
}, {
value: [76, 111, 114],
expected: [1282372096]
}, {
value: [76, 111, 114, 101],
expected: [1282372197]
}, {
value: [76, 111, 114, 101, 109],
expected: [1282372197, 1828716544]
}, {
value: [6, 111, 114, 101, 109, 32, 105, 112, 115, 117, 109],
expected: [107967077, 1830840688, 1937075456]
}])("converts bytes to words", (_ref6 => {
let {
value: value,
expected: expected
} = _ref6;
expect(bytesToWords(new Uint8Array(value)).toString()).toBe(expected.toString())
}));
it.each([{
value: [],
expected: ""
}, {
value: [1282372197],
expected: "4c6f7265"
}, {
value: [107967077, 1830840688, 1937075456],
expected: "066f72656d20697073756d00"
}])("converts words to hex string", (_ref7 => {
let {
value: value,
expected: expected
} = _ref7;
expect(wordsToHex(new Uint32Array(value)).toString()).toBe(expected)
}));
it.each([{
value: [],
expected: ""
}, {
value: [76, 111, 114, 101],
expected: "4c6f7265"
}, {
value: [6, 111, 114, 101, 109, 32, 105, 112, 115, 117, 109],
expected: "066f72656d20697073756d"
}])("converts bytes to hex string", (_ref8 => {
let {
value: value,
expected: expected
} = _ref8;
expect(bytesToHex(new Uint8Array(value)).toString()).toBe(expected)
}));
it.each([{
value1: [],
value2: [],
expected: []
}, {
value1: [6, 111, 114, 101, 109, 32],
value2: [],
expected: [6, 111, 114, 101, 109, 32]
}, {
value1: [],
value2: [105, 112, 115, 117, 109],
expected: [105, 112, 115, 117, 109]
}, {
value1: [6, 111, 114, 101, 109, 32],
value2: [105, 112, 115, 117, 109],
expected: [6, 111, 114, 101, 109, 32, 105, 112, 115, 117, 109]
}])("concatenate byte arrays", (_ref9 => {
let {
value1: value1,
value2: value2,
expected: expected
} = _ref9;
expect(concatBytes(new Uint8Array(value1), new Uint8Array(value2))).toEqual(new Uint8Array(expected))
}))
}));