Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/core/format/IdGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
import {sha3_256} from 'js-sha3';
import * as utilities from './Utilities';
import { idGeneratorConst } from './Utilities';

export class IdGenerator {
/**
Expand Down
4 changes: 0 additions & 4 deletions src/core/format/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export const tryParseUint = (str) => {

export const idGeneratorConst = {
namespace_base_id: [0, 0],
namespace_max_depth: 3,
name_pattern: /^[a-z0-9][a-z0-9-_]*$/,
};

Expand All @@ -114,9 +113,6 @@ export const extractPartName = (name, start, size) => {
};

export const append = (path, id, name) => {
if (idGeneratorConst.namespace_max_depth === path.length) {
this.throwInvalidFqn('too many parts', name);
}
path.push(id);
};

Expand Down
43 changes: 43 additions & 0 deletions test/core/format/Convert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,49 @@ describe('convert', () => {
});
});

describe('hexToUint8Reverse', () => {
it('can parse empty hex string into array', () => {
// Act:
const actual = convert.hexToUint8Reverse('');

// Assert:
const expected = Uint8Array.of();
expect(actual).to.deep.equal(expected);
});

it('can parse valid hex string into array', () => {
// Act:
const actual = convert.hexToUint8Reverse('026ee415fc15');

// Assert:
const expected = Uint8Array.of(0x15, 0xFC, 0x15, 0xE4, 0x6E, 0x02);
expect(actual).to.deep.equal(expected);
});

it('can parse valid hex string containing all valid hex characters into array', () => {
// Act:
const actual = convert.hexToUint8Reverse('abcdef0123456789ABCDEF');

// Assert:
const expected = Uint8Array.of(0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB);
expect(actual).to.deep.equal(expected);
});

it('cannot parse hex string with invalid characters into array', () => {
// Assert:
expect(() => {
convert.hexToUint8Reverse('abcdef012345G789ABCDEF');
}).to.throw('unrecognized hex char');
});

it('cannot parse hex string with invalid size into array', () => {
// Assert:
expect(() => {
convert.hexToUint8Reverse('abcdef012345G789ABCDE');
}).to.throw('hex string has unexpected size');
});
});

describe('uint8ToHex', () => {
it('can format empty array into hex string', () => {
// Act:
Expand Down
7 changes: 0 additions & 7 deletions test/core/format/IdGenerator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,11 @@ describe('id generator', () => {
expect(idGenerator.generateNamespacePath('foo.bar.baz')).to.deep.equal(expected);
});

it('rejects names with too many parts', () => {
// Assert:
['a.b.c.d', 'a.b.c.d.e'].forEach((name) =>
expect(() => idGenerator.generateNamespacePath(name), `name ${name}`).to.throw('too many parts'));
});

it('rejects improper qualified names', () => {
// Assert:
['a:b:c', 'a::b'].forEach((name) =>
expect(() => idGenerator.generateNamespacePath(name), `name ${name}`).to.throw('invalid part name'));
});

addBasicTests(idGenerator.generateNamespacePath);
});
});