Codebase list libdata-guid-perl / a6637ac
make the guid regexes public Ricardo Signes 13 years ago
2 changed file(s) with 15 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
100100 hex => [ 'hexstring', qr/\A0x$hex{32}\z/, ],
101101 base64 => [ 'b64string', qr/\A$base64{24}\z/, ],
102102 );
103
104 for my $key (keys %type) {
105 no strict 'refs';
106 my $subname = "$key\_guid_regex";
107 *$subname = sub { $type{ $key }[1] }
108 }
103109 }
104110
105111 # provided for test scripts
00 #!perl
1
21 use strict;
32 use warnings;
43
5 use Test::More tests => 32;
4 use Test::More 0.88;
65
76 BEGIN { use_ok('Data::GUID'); }
87
1110
1211 like(
1312 $guid->as_string,
14 Data::GUID->__type_regex('string'),
13 Data::GUID->string_guid_regex,
1514 "GUID as_string looks OK",
1615 );
1716
1817 like(
1918 "$guid",
20 Data::GUID->__type_regex('string'),
19 Data::GUID->string_guid_regex,
2120 "stringified GUID looks OK",
2221 );
2322
2423 like(
2524 $guid->as_hex,
26 Data::GUID->__type_regex('hex'),
25 Data::GUID->hex_guid_regex,
2726 "GUID as_hex looks OK",
2827 );
2928
3029 like(
3130 $guid->as_base64,
32 Data::GUID->__type_regex('base64'),
31 Data::GUID->base64_guid_regex,
3332 "GUID as_hex looks OK",
3433 );
3534
3736 ($guid <=> $guid) == 0,
3837 "guid is equal to itself",
3938 );
40
41 {
42 my $other_guid = Data::GUID->new;
43
44 ok(
45 ($guid <=> $other_guid) != 0,
46 "guid is not equal to a new guid",
47 );
48 }
4939
5040 {
5141 my $non_guid_value = 10;
7262 }
7363 }
7464
75
7665 for my $type (qw(hex string base64)) {
7766 my $as = "as_$type";
7867 my $from = "from_$type";
9281 like($@, qr/not a valid $type/, "invalid input to $from croaks");
9382 }
9483
95 like($guid_str, Data::GUID->__type_regex($type), "guid_$type method ok");
84 my $re_method = "$type\_guid_regex";
85 like($guid_str, Data::GUID->$re_method, "guid_$type method ok");
9686 }
9787
9888 {
10292 my $copy = Data::GUID->from_string($str);
10393 is($guid->as_string, $copy->as_string, "we can from_string a dash-less str");
10494 }
95
96 done_testing;