11-- Start transaction and plan the tests.
22BEGIN ;
3- SELECT plan(41 );
3+ SELECT plan(42 );
44
55create table tests (
66 " tid" typeid
@@ -113,6 +113,26 @@ SELECT is(
113113 ' Print valid: valid-alphabet'
114114);
115115
116+ -- - name: valid-prefix-underscores
117+ -- typeid: "pre_fix_0123456789abcdefghjkmnpqrs"
118+ -- prefix: "pre_fix"
119+ -- uuid: "0110c853-1d09-52d8-d73e-1194e95b5f19"
120+ SELECT is(
121+ typeid_parse(' pre_fix_0123456789abcdefghjkmnpqrs' ),
122+ (' pre_fix' , ' 0110c853-1d09-52d8-d73e-1194e95b5f19' )::typeid,
123+ ' Parse valid: valid-prefix-underscores'
124+ );
125+ SELECT is(
126+ typeid_print((' pre_fix' , ' 0110c853-1d09-52d8-d73e-1194e95b5f19' )),
127+ ' pre_fix_0123456789abcdefghjkmnpqrs' ,
128+ ' Print valid: valid-alphabet-underscores'
129+ );
130+ SELECT is(
131+ typeid_print((' pre_____fix' , ' 0110c853-1d09-52d8-d73e-1194e95b5f19' )),
132+ ' pre_____fix_0123456789abcdefghjkmnpqrs' ,
133+ ' Print valid: valid-alphabet-underscores'
134+ );
135+
116136-- - name: valid-uuidv7
117137-- typeid: "prefix_01h455vb4pex5vsknk084sn02q"
118138-- prefix: "prefix"
@@ -135,13 +155,13 @@ SELECT is(
135155-- description: "The prefix should be lowercase with no uppercase letters"
136156SELECT throws_ok(
137157 $$ INSERT into tests (tid) VALUES (typeid_parse(' PREFIX_00000000000000000000000000' )); $$,
138- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
158+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
139159 ' Parse invalid: prefix-uppercase'
140160);
141161
142162SELECT throws_ok(
143163 $$ INSERT into tests (tid) VALUES (typeid_generate(' PREFIX' )); $$,
144- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
164+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
145165 ' Parse invalid: prefix-uppercase'
146166);
147167
@@ -150,13 +170,13 @@ SELECT throws_ok(
150170-- description: "The prefix can't have numbers, it needs to be alphabetic"
151171SELECT throws_ok(
152172 $$ INSERT into tests (tid) VALUES (typeid_parse(' 12345_00000000000000000000000000' )); $$,
153- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
173+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
154174 ' Parse invalid: prefix-numeric'
155175);
156176
157177SELECT throws_ok(
158178 $$ INSERT into tests (tid) VALUES (typeid_generate(' 12345' )); $$,
159- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
179+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
160180 ' Parse invalid: prefix-numeric'
161181);
162182
@@ -165,13 +185,13 @@ SELECT throws_ok(
165185-- description: "The prefix can't have symbols, it needs to be alphabetic"
166186SELECT throws_ok(
167187 $$ INSERT into tests (tid) VALUES (typeid_parse(' pre.fix_00000000000000000000000000' )); $$,
168- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
188+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
169189 ' Parse invalid: prefix-period'
170190);
171191
172192SELECT throws_ok(
173193 $$ INSERT into tests (tid) VALUES (typeid_generate(' pre.fix' )); $$,
174- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
194+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
175195 ' Parse invalid: prefix-period'
176196);
177197
@@ -185,8 +205,14 @@ SELECT throws_ok(
185205);
186206
187207SELECT throws_ok(
188- $$ INSERT into tests (tid) VALUES (typeid_generate(' pre_fix' )); $$,
189- ' typeid prefix must match the regular expression [a-z]{0,63}' ,
208+ $$ INSERT into tests (tid) VALUES (typeid_generate(' _prefix' )); $$,
209+ ' typeid prefix must match the regular expression ^([a-z]([a-z_]{0,61}[a-z])?)?$' ,
210+ ' Parse invalid: prefix-underscore'
211+ );
212+
213+ SELECT throws_ok(
214+ $$ INSERT into tests (tid) VALUES (typeid_generate(' prefix_' )); $$,
215+ ' typeid prefix must match the regular expression ^([a-z]([a-z_]{0,61}[a-z])?)?$' ,
190216 ' Parse invalid: prefix-underscore'
191217);
192218
@@ -195,13 +221,13 @@ SELECT throws_ok(
195221-- description: "The prefix can only have ascii letters"
196222SELECT throws_ok(
197223 $$ INSERT into tests (tid) VALUES (typeid_parse(' préfix_00000000000000000000000000' )); $$,
198- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
224+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
199225 ' Parse invalid: prefix-non-ascii'
200226);
201227
202228SELECT throws_ok(
203229 $$ INSERT into tests (tid) VALUES (typeid_generate(' préfix' )); $$,
204- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
230+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
205231 ' Parse invalid: prefix-non-ascii'
206232);
207233
@@ -210,13 +236,13 @@ SELECT throws_ok(
210236-- description: "The prefix can't have any spaces"
211237SELECT throws_ok(
212238 $$ INSERT into tests (tid) VALUES (typeid_parse(' prefix_00000000000000000000000000' )); $$,
213- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
239+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
214240 ' Parse invalid: prefix-spaces'
215241);
216242
217243SELECT throws_ok(
218244 $$ INSERT into tests (tid) VALUES (typeid_generate(' prefix' )); $$,
219- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
245+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
220246 ' Parse invalid: prefix-spaces'
221247);
222248
@@ -226,13 +252,13 @@ SELECT throws_ok(
226252-- description: "The prefix can't be 64 characters, it needs to be 63 characters or less"
227253SELECT throws_ok(
228254 $$ INSERT into tests (tid) VALUES (typeid_parse(' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl_00000000000000000000000000' )); $$,
229- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
255+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
230256 ' Parse invalid: prefix-64-chars'
231257);
232258
233259SELECT throws_ok(
234260 $$ INSERT into tests (tid) VALUES (typeid_generate(' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl' )); $$,
235- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
261+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
236262 ' Parse invalid: prefix-64-chars'
237263);
238264
0 commit comments