11-- Start transaction and plan the tests.
22BEGIN ;
3- SELECT plan(41 );
3+ SELECT plan(44 );
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,28 +185,28 @@ 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
178198-- - name: prefix-underscore
179199-- typeid: "pre_fix_00000000000000000000000000"
180- -- description: "The prefix can't have symbols, it needs to be alphabetic "
200+ -- description: "The prefix can't have leading or trailing underscores "
181201SELECT throws_ok(
182- $$ INSERT into tests (tid) VALUES (typeid_parse( ' pre_fix_00000000000000000000000000 ' )); $$,
183- ' typeid suffix must be 26 characters ' ,
202+ $$ INSERT into tests (tid) VALUES (typeid_generate( ' _prefix ' )); $$,
203+ ' typeid prefix must match the regular expression ^([a-z]([a-z_]{0,61}[a-z])?)?$ ' ,
184204 ' Parse invalid: prefix-underscore'
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])?)?$ ' ,
190210 ' Parse invalid: prefix-underscore'
191211);
192212
@@ -195,13 +215,13 @@ SELECT throws_ok(
195215-- description: "The prefix can only have ascii letters"
196216SELECT throws_ok(
197217 $$ INSERT into tests (tid) VALUES (typeid_parse(' préfix_00000000000000000000000000' )); $$,
198- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
218+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
199219 ' Parse invalid: prefix-non-ascii'
200220);
201221
202222SELECT throws_ok(
203223 $$ INSERT into tests (tid) VALUES (typeid_generate(' préfix' )); $$,
204- ' 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])?)?$ ' ,
205225 ' Parse invalid: prefix-non-ascii'
206226);
207227
@@ -210,13 +230,13 @@ SELECT throws_ok(
210230-- description: "The prefix can't have any spaces"
211231SELECT throws_ok(
212232 $$ INSERT into tests (tid) VALUES (typeid_parse(' prefix_00000000000000000000000000' )); $$,
213- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
233+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
214234 ' Parse invalid: prefix-spaces'
215235);
216236
217237SELECT throws_ok(
218238 $$ INSERT into tests (tid) VALUES (typeid_generate(' prefix' )); $$,
219- ' 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])?)?$ ' ,
220240 ' Parse invalid: prefix-spaces'
221241);
222242
@@ -226,13 +246,13 @@ SELECT throws_ok(
226246-- description: "The prefix can't be 64 characters, it needs to be 63 characters or less"
227247SELECT throws_ok(
228248 $$ INSERT into tests (tid) VALUES (typeid_parse(' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl_00000000000000000000000000' )); $$,
229- ' typeid prefix must match the regular expression [a-z]{0,63} ' ,
249+ ' typeid prefix must match the regular expression ^( [a-z]([a-z_] {0,61}[a-z])?)?$ ' ,
230250 ' Parse invalid: prefix-64-chars'
231251);
232252
233253SELECT throws_ok(
234254 $$ INSERT into tests (tid) VALUES (typeid_generate(' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl' )); $$,
235- ' 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])?)?$ ' ,
236256 ' Parse invalid: prefix-64-chars'
237257);
238258
0 commit comments