UNPKG

node-bcc

Version:

A simple Block Check Character library.

67 lines 3.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const hex_1 = require("./hex"); /* eslint-disable @typescript-eslint/no-explicit-any */ describe('Hex', () => { describe('split', () => { it('should return null if input string is null', () => { const str = null; chai_1.expect(hex_1.Hex.split(str)).to.be.null; }); it('should return null if input string is undefined', () => { const str = undefined; chai_1.expect(hex_1.Hex.split(str)).to.be.null; }); it('should return null if input string is empty', () => { chai_1.expect(hex_1.Hex.split('')).to.be.null; }); it('should return correctly split array', () => { chai_1.expect(hex_1.Hex.split('AABBCCDDEEFF')).to.deep.equal(['AA', 'BB', 'CC', 'DD', 'EE', 'FF']); }); }); describe('validate', () => { it('should return false if input string is null', () => { const str = null; chai_1.expect(hex_1.Hex.validate(str)).to.be.false; }); it('should return false if input string is undefined', () => { const str = undefined; chai_1.expect(hex_1.Hex.validate(str)).to.be.false; }); it('should return false if input string is empty', () => { chai_1.expect(hex_1.Hex.validate('')).to.be.false; }); it('should return false if input string is invalid hex string', () => { chai_1.expect(hex_1.Hex.validate('00112233445566778899AABBCCDDEEFFXX')).to.be.false; }); it('should return true if input string is valid hex string', () => { chai_1.expect(hex_1.Hex.validate('00112233445566778899AABBCCDDEEFF')).to.be.true; }); }); describe('toHexString', () => { it('should return null if input is of zero length', () => { chai_1.expect(hex_1.Hex.toHexString([])).to.be.null; }); it('should return null if input array is null', () => { const arr = null; chai_1.expect(hex_1.Hex.toHexString(arr)).to.be.null; }); it('should return null if input is undefined', () => { const arr = undefined; chai_1.expect(hex_1.Hex.toHexString(arr)).to.be.null; }); for (let i = 0; i < 16; i++) { it(`should return string prepended with 0 if input value is ${i}`, () => { chai_1.expect(hex_1.Hex.toHexString([i])).to.deep.equal(`0${i.toString(16)}`); }); } it('should return return valid hex string', () => { chai_1.expect(hex_1.Hex.toHexString([1, 15, 58, 96, 34])).to.deep.equal('010f3a6022'); }); it('should return the string in upopercase of the uppercase flag was set', () => { chai_1.expect(hex_1.Hex.toHexString([1, 15, 58, 96, 34], true)).to.deep.equal('010F3A6022'); }); }); }); //# sourceMappingURL=hex.spec.js.map