@@ -9,10 +9,9 @@ import { decodeTime, monotonicUlid, ulid } from "./mod.ts";
99import {
1010 encodeRandom ,
1111 encodeTime ,
12- ENCODING ,
13- ENCODING_LEN ,
1412 incrementBase32 ,
1513 monotonicFactory ,
14+ RANDOM_LEN ,
1615} from "./_util.ts" ;
1716
1817Deno . test ( "incrementBase32()" , async ( t ) => {
@@ -46,28 +45,20 @@ Deno.test("incrementBase32()", async (t) => {
4645
4746Deno . test ( "encodeTime()" , async ( t ) => {
4847 await t . step ( "should return expected encoded result" , ( ) => {
49- assertEquals ( "01ARYZ6S41" , encodeTime ( 1469918176385 , 10 ) ) ;
50- } ) ;
51-
52- await t . step ( "should change length properly" , ( ) => {
53- assertEquals ( "0001AS99AA60" , encodeTime ( 1470264322240 , 12 ) ) ;
54- } ) ;
55-
56- await t . step ( "should truncate time if not enough length" , ( ) => {
57- assertEquals ( "AS4Y1E11" , encodeTime ( 1470118279201 , 8 ) ) ;
48+ assertEquals ( "01ARYZ6S41" , encodeTime ( 1469918176385 ) ) ;
5849 } ) ;
5950
6051 await t . step ( "should throw an error" , async ( t ) => {
6152 await t . step ( "if time greater than (2 ^ 48) - 1" , ( ) => {
6253 assertThrows ( ( ) => {
63- encodeTime ( Math . pow ( 2 , 48 ) , 8 ) ;
54+ encodeTime ( Math . pow ( 2 , 48 ) ) ;
6455 } , Error ) ;
6556 } ) ;
6657
6758 await t . step ( "if time is not a number" , ( ) => {
6859 assertThrows ( ( ) => {
6960 // deno-lint-ignore no-explicit-any
70- encodeTime ( "test" as any , 3 ) ;
61+ encodeTime ( "test" as any ) ;
7162 } , Error ) ;
7263 } ) ;
7364
@@ -93,7 +84,7 @@ Deno.test("encodeTime()", async (t) => {
9384
9485Deno . test ( "encodeRandom()" , async ( t ) => {
9586 await t . step ( "should return correct length" , ( ) => {
96- assertEquals ( 12 , encodeRandom ( 12 ) . length ) ;
87+ assertEquals ( RANDOM_LEN , encodeRandom ( ) . length ) ;
9788 } ) ;
9889} ) ;
9990
@@ -146,13 +137,8 @@ Deno.test("ulid()", async (t) => {
146137} ) ;
147138
148139Deno . test ( "monotonicUlid() handles monotonicity" , async ( t ) => {
149- function encodeRandom ( len : number ) : string {
150- let str = "" ;
151- const randomBytes = new Array ( len ) . fill ( 30 ) ;
152- for ( let i = 0 ; i < len ; i ++ ) {
153- str += ENCODING [ randomBytes [ i ] % ENCODING_LEN ] ;
154- }
155- return str ;
140+ function encodeRandom ( ) : string {
141+ return "YYYYYYYYYYYYYYYY" ;
156142 }
157143
158144 await t . step ( "without seedTime" , async ( t ) => {
0 commit comments