Skip to content

Commit f7f8231

Browse files
Add base32 tests
1 parent 7c59165 commit f7f8231

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

source/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export { isValid, monotonicFactory, ulid } from "./ulid.js";
22
export { ulidToUUID, uuidToULID } from "./uuid.js";
3-
export { fixULIDBase32 } from "./crockford.js";
3+
export { fixULIDBase32, incrementBase32 } from "./crockford.js";
44
export { ULIDError, ULIDErrorCode } from "./error.js";
55
export { MAX_ULID, MIN_ULID } from "./constants.js";
66
export * from "./types.js";

test/node/crockford.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, expect, it } from "vitest";
2+
import { incrementBase32 } from "../../";
3+
4+
describe("incrementBase32", () => {
5+
it("increments correctly", () => {
6+
expect(incrementBase32("A109C")).toEqual("A109D");
7+
})
8+
9+
it("carries correctly", () => {
10+
expect(incrementBase32("A1YZZ")).toEqual("A1Z00");
11+
})
12+
13+
it("double increments correctly", () => {
14+
expect(incrementBase32(incrementBase32("A1YZZ"))).toEqual("A1Z01");
15+
})
16+
17+
it("throws when it cannot increment", () => {
18+
expect(() => {
19+
incrementBase32("ZZZ")
20+
}).toThrow(/B32_ENC_INVALID/);
21+
})
22+
});

0 commit comments

Comments
 (0)