devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
207 lines (206 loc) • 6.6 kB
JavaScript
/**
* DevExtreme (cjs/__internal/core/license/byte_utils.test.js)
* Version: 24.2.6
* Build date: Mon Mar 17 2025
*
* Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
"use strict";
var _globals = require("@jest/globals");
var _byte_utils = require("./byte_utils");
(0, _globals.describe)("byte utils", (() => {
_globals.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;
(0, _globals.expect)((0, _byte_utils.leftRotate)(value, count)).toBe(expected)
}));
_globals.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;
(0, _globals.expect)((0, _byte_utils.stringToBytes)(value).toString()).toBe(expected.toString())
}));
_globals.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;
(0, _globals.expect)((0, _byte_utils.base64ToBytes)(value)).toEqual(new Uint8Array(expected))
}));
_globals.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;
(0, _globals.expect)((0, _byte_utils.hexToBytes)(value)).toEqual(new Uint8Array(expected))
}));
_globals.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;
(0, _globals.expect)((0, _byte_utils.wordsToBytes)(new Uint32Array(value))).toEqual(new Uint8Array(expected))
}));
_globals.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;
(0, _globals.expect)((0, _byte_utils.bytesToWords)(new Uint8Array(value)).toString()).toBe(expected.toString())
}));
_globals.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;
(0, _globals.expect)((0, _byte_utils.wordsToHex)(new Uint32Array(value)).toString()).toBe(expected)
}));
_globals.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;
(0, _globals.expect)((0, _byte_utils.bytesToHex)(new Uint8Array(value)).toString()).toBe(expected)
}));
_globals.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;
(0, _globals.expect)((0, _byte_utils.concatBytes)(new Uint8Array(value1), new Uint8Array(value2))).toEqual(new Uint8Array(expected))
}))
}));