Skip to content

Commit 25e9b4a

Browse files
committed
Added unit tests
1 parent b9f926b commit 25e9b4a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/core/format/Convert.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,49 @@ describe('convert', () => {
147147
});
148148
});
149149

150+
describe('hexToUint8Reverse', () => {
151+
it('can parse empty hex string into array', () => {
152+
// Act:
153+
const actual = convert.hexToUint8Reverse('');
154+
155+
// Assert:
156+
const expected = Uint8Array.of();
157+
expect(actual).to.deep.equal(expected);
158+
});
159+
160+
it('can parse valid hex string into array', () => {
161+
// Act:
162+
const actual = convert.hexToUint8Reverse('026ee415fc15');
163+
164+
// Assert:
165+
const expected = Uint8Array.of(0x15, 0xFC, 0x15, 0xE4, 0x6E, 0x02);
166+
expect(actual).to.deep.equal(expected);
167+
});
168+
169+
it('can parse valid hex string containing all valid hex characters into array', () => {
170+
// Act:
171+
const actual = convert.hexToUint8Reverse('abcdef0123456789ABCDEF');
172+
173+
// Assert:
174+
const expected = Uint8Array.of(0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB);
175+
expect(actual).to.deep.equal(expected);
176+
});
177+
178+
it('cannot parse hex string with invalid characters into array', () => {
179+
// Assert:
180+
expect(() => {
181+
convert.hexToUint8Reverse('abcdef012345G789ABCDEF');
182+
}).to.throw('unrecognized hex char');
183+
});
184+
185+
it('cannot parse hex string with invalid size into array', () => {
186+
// Assert:
187+
expect(() => {
188+
convert.hexToUint8Reverse('abcdef012345G789ABCDE');
189+
}).to.throw('hex string has unexpected size');
190+
});
191+
});
192+
150193
describe('uint8ToHex', () => {
151194
it('can format empty array into hex string', () => {
152195
// Act:

0 commit comments

Comments
 (0)