| 1 |
#!perl |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
|
| 5 |
=head1 TEST PURPOSE |
| 6 |
|
| 7 |
These tests test option list expansion (from an option list into a hashref). |
| 8 |
|
| 9 |
=cut |
| 10 |
|
| 11 |
use Sub::Install; |
| 12 |
use Test::More tests => 13; |
| 13 |
|
| 14 |
BEGIN { use_ok('Data::OptList'); } |
| 15 |
|
| 16 |
# let's get a convenient copy to use: |
| 17 |
Sub::Install::install_sub({ |
| 18 |
code => 'mkopt_hash', |
| 19 |
from => 'Data::OptList', |
| 20 |
as => 'OPTH', |
| 21 |
}); |
| 22 |
|
| 23 |
is_deeply( |
| 24 |
OPTH(), |
| 25 |
{}, |
| 26 |
"empty opt list expands properly", |
| 27 |
); |
| 28 |
|
| 29 |
is_deeply( |
| 30 |
OPTH(undef), |
| 31 |
{}, |
| 32 |
"undef opt list expands properly", |
| 33 |
); |
| 34 |
|
| 35 |
is_deeply( |
| 36 |
OPTH([]), |
| 37 |
{}, |
| 38 |
"empty arrayref opt list expands properly", |
| 39 |
); |
| 40 |
|
| 41 |
is_deeply( |
| 42 |
OPTH({}), |
| 43 |
{}, |
| 44 |
"empty hashref opt list expands properly", |
| 45 |
); |
| 46 |
|
| 47 |
is_deeply( |
| 48 |
OPTH([ qw(foo bar baz) ]), |
| 49 |
{ foo => undef, bar => undef, baz => undef }, |
| 50 |
"opt list of just names expands", |
| 51 |
); |
| 52 |
|
| 53 |
is_deeply( |
| 54 |
OPTH([ qw(foo :bar baz) ]), |
| 55 |
{ foo => undef, ':bar' => undef, baz => undef }, |
| 56 |
"opt list of names expands with :group names", |
| 57 |
); |
| 58 |
|
| 59 |
is_deeply( |
| 60 |
OPTH([ foo => { a => 1 }, ':bar', 'baz' ]), |
| 61 |
{ foo => { a => 1 }, ':bar' => undef, baz => undef }, |
| 62 |
"opt list of names and values expands", |
| 63 |
); |
| 64 |
|
| 65 |
is_deeply( |
| 66 |
OPTH([ foo => { a => 1 }, ':bar' => undef, 'baz' ]), |
| 67 |
{ foo => { a => 1 }, ':bar' => undef, baz => undef }, |
| 68 |
"opt list of names and values expands, ignoring undef", |
| 69 |
); |
| 70 |
|
| 71 |
is_deeply( |
| 72 |
OPTH({ foo => { a => 1 }, -bar => undef, baz => undef }, 0, 'HASH'), |
| 73 |
{ foo => { a => 1 }, -bar => undef, baz => undef }, |
| 74 |
"opt list of names and values expands with must_be", |
| 75 |
); |
| 76 |
|
| 77 |
is_deeply( |
| 78 |
OPTH({ foo => { a => 1 }, -bar => undef, baz => undef }, 0, ['HASH']), |
| 79 |
{ foo => { a => 1 }, -bar => undef, baz => undef }, |
| 80 |
"opt list of names and values expands with [must_be]", |
| 81 |
); |
| 82 |
|
| 83 |
eval { OPTH({ foo => { a => 1 }, -bar => undef, baz => undef }, 0, 'ARRAY'); }; |
| 84 |
like($@, qr/HASH-ref values are not/, "exception tossed on invaild ref value"); |
| 85 |
|
| 86 |
eval { OPTH({ foo => { a => 1 }, -bar => undef, baz => undef }, 0, ['ARRAY']); }; |
| 87 |
like($@, qr/HASH-ref values are not/, "exception tossed on invaild ref value"); |