diff --git t/library/uuid.t t/library/uuid.t
index 3b2c1cd..edd3d6a 100644
|
|
|
1 | | #!perl |
| 1 | #!parrot |
2 | 2 | # Copyright (C) 2008, Parrot Foundation. |
3 | 3 | # $Id$ |
4 | 4 | |
5 | | use strict; |
6 | | use warnings; |
7 | | use lib qw( t . lib ../lib ../../lib ); |
8 | | use Test::More; |
9 | | use Parrot::Test tests => 9; |
10 | | |
11 | 5 | =head1 NAME |
12 | 6 | |
13 | 7 | t/library/uuid.t - uuid library tests |
… |
… |
|
18 | 12 | |
19 | 13 | =cut |
20 | 14 | |
21 | | pir_output_is( << 'CODE', << 'OUTPUT', 'generate' ); |
22 | | .sub test :main |
| 15 | .sub main :main |
| 16 | .include 'test_more.pir' |
| 17 | plan(20) |
| 18 | |
| 19 | test_generate_1() |
| 20 | test_generate_2() |
| 21 | test_generate_random() |
| 22 | test_generate_time() |
| 23 | test_parse_1() |
| 24 | test_parse_2() |
| 25 | test_time() |
| 26 | test_type() |
| 27 | test_variant() |
| 28 | .end |
| 29 | |
| 30 | .sub test_generate_1 |
23 | 31 | load_bytecode 'uuid.pbc' |
24 | 32 | $P0 = get_global ['uuid'], 'generate' |
25 | 33 | $P1 = $P0() |
26 | 34 | $S1 = typeof $P1 |
27 | | print $S1 |
28 | | print "\n" |
| 35 | is($S1,'uuid', 'generate 1') |
29 | 36 | .end |
30 | | CODE |
31 | | uuid |
32 | | OUTPUT |
33 | 37 | |
34 | | |
35 | | pir_output_like( << 'CODE', << 'OUTPUT', 'generate' ); |
36 | | .sub test :main |
| 38 | .sub test_generate_2 |
37 | 39 | load_bytecode 'uuid.pbc' |
38 | 40 | $P0 = get_global ['uuid'], 'generate' |
39 | 41 | $P1 = $P0() |
40 | | print $P1 |
| 42 | like($P1, '<[0..9a..f]>**8\-<[0..9a..f]>**4\-<[0..9a..f]>**4\-<[0..9a..f]>**4\-<[0..9a..f]>**12', 'generate 2' ) |
41 | 43 | .end |
42 | | CODE |
43 | | /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ |
44 | | OUTPUT |
45 | 44 | |
46 | 45 | |
47 | | pir_output_like( << 'CODE', << 'OUTPUT', 'generate_random' ); |
48 | | .sub test :main |
| 46 | .sub test_generate_random |
49 | 47 | load_bytecode 'uuid.pbc' |
50 | 48 | $P0 = get_global ['uuid'], 'generate_random' |
51 | 49 | $P1 = $P0() |
52 | | print $P1 |
| 50 | like($P1, '<[0..9a..f]>**8\-<[0..9a..f]>**4\-<[0..9a..f]>**4\-<[0..9a..f]>**4\-<[0..9a..f]>**12', 'generate random') |
53 | 51 | .end |
54 | | CODE |
55 | | /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ |
56 | | OUTPUT |
57 | | |
58 | 52 | |
59 | | pir_output_like( << 'CODE', << 'OUTPUT', 'generate_time' ); |
60 | | .sub test :main |
| 53 | .sub test_generate_time |
61 | 54 | load_bytecode 'uuid.pbc' |
62 | 55 | $P0 = get_global ['uuid'], 'generate_time' |
63 | 56 | $P1 = $P0() |
64 | | print $P1 |
| 57 | like($P1, '<[0..9a..f]>**8\-<[0..9a..f]>**4\-<[0..9a..f]>**4\-<[0..9a..f]>**4\-<[0..9a..f]>**12', 'generate random') |
65 | 58 | .end |
66 | | CODE |
67 | | /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ |
68 | | OUTPUT |
69 | 59 | |
70 | | |
71 | | pir_output_is( << 'CODE', << 'OUTPUT', 'parse' ); |
72 | | .sub test :main |
| 60 | .sub test_parse_1 |
73 | 61 | load_bytecode 'uuid.pbc' |
74 | 62 | $P0 = get_global ['uuid'], 'parse' |
75 | 63 | ($I0, $P1) = $P0("84949cc5-4701-4a84-895b-354c584a981b") |
76 | | print $I0 |
77 | | print "\n" |
| 64 | is($I0, 0, 'parse 1') |
78 | 65 | $S1 = typeof $P1 |
79 | | print $S1 |
80 | | print "\n" |
| 66 | is($S1, 'uuid', 'parse 1') |
81 | 67 | .end |
82 | | CODE |
83 | | 0 |
84 | | uuid |
85 | | OUTPUT |
86 | 68 | |
87 | 69 | |
88 | | pir_output_is( << 'CODE', << 'OUTPUT', 'parse' ); |
89 | | .sub test :main |
| 70 | .sub test_parse_2 |
90 | 71 | load_bytecode 'uuid.pbc' |
91 | 72 | $P0 = get_global ['uuid'], 'parse' |
92 | 73 | $I0 = $P0("84949cc5-4701-4a84-895b-354c584a981b") |
93 | | print $I0 |
94 | | print "\n" |
| 74 | is($I0, 0, 'parse 2') |
95 | 75 | $I0 = $P0("84949CC5-4701-4A84-895B-354C584A981B") |
96 | | print $I0 |
97 | | print "\n" |
| 76 | is($I0, 0, 'parse 2') |
98 | 77 | $I0 = $P0("84949cc5-4701-4a84-895b-354c584a981bc") |
99 | | print $I0 |
100 | | print "\n" |
| 78 | is($I0, -1, 'parse 2') |
101 | 79 | $I0 = $P0("84949cc5-4701-4a84-895b-354c584a981") |
102 | | print $I0 |
103 | | print "\n" |
| 80 | is($I0, -1, 'parse 2') |
104 | 81 | $I0 = $P0("84949cc5x4701-4a84-895b-354c584a981b") |
105 | | print $I0 |
106 | | print "\n" |
| 82 | is($I0, -1, 'parse 2') |
107 | 83 | $I0 = $P0("84949cc504701-4a84-895b-354c584a981b") |
108 | | print $I0 |
109 | | print "\n" |
| 84 | is($I0, -1, 'parse 2') |
110 | 85 | $I0 = $P0("84949cc5-470104a84-895b-354c584a981b") |
111 | | print $I0 |
112 | | print "\n" |
| 86 | is($I0, -1, 'parse 2') |
113 | 87 | $I0 = $P0("84949cc5-4701-4a840895b-354c584a981b") |
114 | | print $I0 |
115 | | print "\n" |
| 88 | is($I0, -1, 'parse 2') |
116 | 89 | $I0 = $P0("84949cc5-4701-4a84-895b0354c584a981b") |
117 | | print $I0 |
118 | | print "\n" |
| 90 | is($I0, -1, 'parse 2') |
119 | 91 | $I0 = $P0("g4949cc5-4701-4a84-895b-354c584a981b") |
120 | | print $I0 |
121 | | print "\n" |
| 92 | is($I0, -1, 'parse 2') |
122 | 93 | $I0 = $P0("84949cc5-4701-4a84-895b-354c584a981g") |
123 | | print $I0 |
124 | | print "\n" |
| 94 | is($I0, -1, 'parse 2') |
125 | 95 | .end |
126 | | CODE |
127 | | 0 |
128 | | 0 |
129 | | -1 |
130 | | -1 |
131 | | -1 |
132 | | -1 |
133 | | -1 |
134 | | -1 |
135 | | -1 |
136 | | -1 |
137 | | -1 |
138 | | OUTPUT |
139 | | |
140 | | |
141 | | pir_output_is( << 'CODE', << 'OUTPUT', 'time' ); |
142 | | .sub test :main |
| 96 | |
| 97 | |
| 98 | .sub test_time |
143 | 99 | load_bytecode 'uuid.pbc' |
144 | 100 | $P0 = get_global ['uuid'], 'parse' |
145 | 101 | ($I0, $P1) = $P0("84949cc5-4701-4a84-895b-354c584a981b") |
146 | 102 | $I1 = $P1.'time'() |
147 | | print $I1 |
148 | | print "\n" |
| 103 | is($I1, -1, 'time') |
149 | 104 | .end |
150 | | CODE |
151 | | -1 |
152 | | OUTPUT |
153 | 105 | |
154 | | |
155 | | pir_output_is( << 'CODE', << 'OUTPUT', 'type' ); |
156 | | .sub test :main |
| 106 | .sub test_type |
157 | 107 | load_bytecode 'uuid.pbc' |
158 | 108 | $P0 = get_global ['uuid'], 'generate' |
159 | 109 | $P1 = $P0() |
160 | 110 | $I0 = $P1.'type'() |
161 | | print $I0 |
162 | | print "\n" |
| 111 | is($I0, 4, 'type') |
163 | 112 | .end |
164 | | CODE |
165 | | 4 |
166 | | OUTPUT |
167 | 113 | |
168 | 114 | |
169 | | pir_output_is( << 'CODE', << 'OUTPUT', 'variant' ); |
170 | | .sub test :main |
| 115 | .sub test_variant |
171 | 116 | load_bytecode 'uuid.pbc' |
172 | 117 | $P0 = get_global ['uuid'], 'generate' |
173 | 118 | $P1 = $P0() |
174 | 119 | $I0 = $P1.'variant'() |
175 | | print $I0 |
176 | | print "\n" |
| 120 | is($I0, 1, 'variant') |
177 | 121 | .end |
178 | | CODE |
179 | | 1 |
180 | | OUTPUT |
181 | | |
182 | 122 | |
183 | 123 | # Local Variables: |
184 | 124 | # mode: cperl |
185 | 125 | # cperl-indent-level: 4 |
186 | 126 | # fill-column: 100 |
187 | 127 | # End: |
188 | | # vim: expandtab shiftwidth=4: |
| 128 | # vim: expandtab shiftwidth=4 filetype=pir: |