6 use Test::More tests => 6 + 5 + 4 + 1 + 9;
8 use Scope::Upper qw<uid validate_uid HERE UP>;
16 is $@, '', 'validate_uid(uid) does not croak';
25 my $line = __LINE__-2;
26 like $@, qr/^UID contains only one part at \Q$0\E line $line/,
27 'validate_uid("123") croaks';
30 for my $wrong ('1.23-4', 'abc-5') {
36 my $line = __LINE__-2;
37 like $@, qr/^First UID part is not an unsigned integer at \Q$0\E line $line/,
38 "validate_uid(\"$wrong\") croaks";
41 for my $wrong ('67-8.9', '001-def') {
47 my $line = __LINE__-2;
48 like $@, qr/^Second UID part is not an unsigned integer at \Q$0\E line $line/,
49 "validate_uid(\"$wrong\") croaks";
54 ok validate_uid($here), '$here is valid (same scope)';
56 ok validate_uid($here), '$here is valid (in block)';
59 ok validate_uid($here), '$here is valid (in sub)';
63 ok validate_uid($here), '$here is valid (in eval block)';
66 ok validate_uid($here), '$here is valid (in eval string)';
75 ok validate_uid($here), '$here is valid (below)';
77 ok validate_uid($here), '$here is valid (exact)';
79 ok !validate_uid($here), '$here is invalid (above)';
81 ok !validate_uid($here), '$here is invalid (new block)';
91 ok !validate_uid($first), 'a new UID for each loop iteration';
100 sub Scope::Upper::TestUIDDestructor::DESTROY {
101 ok !validate_uid($top),
102 '$top defined after the guard is not valid in destructor';
104 ok validate_uid($uid), '$uid is valid in destructor';
108 ok validate_uid($up), '$up is valid in destructor';
110 ok !validate_uid($up), '$up is no longer valid in destructor';
114 my $guard = bless [], 'Scope::Upper::TestUIDDestructor';
116 ok validate_uid($top), '$top defined after the guard is valid in block';
118 ok !validate_uid($top), '$top is no longer valid outside of the block';
119 ok !validate_uid($uid), '$uid is no longer valid outside of the destructor';
121 sub Scope::Upper::TestUIDDestructor2::DESTROY {
122 ok validate_uid($top), '$top defined before the guard is valid in destructor';
126 skip 'Destructors are always last before perl 5.8' => 2 if "$]" < 5.008;
129 my $guard = bless [], 'Scope::Upper::TestUIDDestructor2';
130 ok validate_uid($top), '$top defined before the guard is valid in block';