Skip to content

Commit

Permalink
test(utils): enhance StringIdGenerator (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Apr 3, 2024
1 parent 20c38ba commit 16bd643
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/utils/StringIdGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO @Shinigami92 2024-04-03: Can this be fully rewritten to a generator function?

// credits to https://stackoverflow.com/a/12504061/4790644
export class StringIdGenerator {
private ids: number[] = [0];
Expand Down
11 changes: 10 additions & 1 deletion test/utils/StringIdGenerator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ import { StringIdGenerator } from '../../src/utils';

describe('utils', () => {
describe('StringIdGenerator', () => {
it('should generate correct sequence', () => {
it('should generate correct sequence with default chars', () => {
const ids = new StringIdGenerator();
const results = [...'abcdefghijklmnopqrstuvwxyz', 'aa', 'ab'];

results.forEach((res) => {
expect(ids.next()).toBe(res);
});
});

it('should generate correct sequence with custom chars', () => {
const chars = 'abcd';

const ids = new StringIdGenerator(chars);
Expand Down

0 comments on commit 16bd643

Please sign in to comment.