diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2013-12-13 13:30:36 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2013-12-13 13:30:36 +0000 |
commit | aa2ab3d34edbee7e4fc832394136391fd5f87702 (patch) | |
tree | 0f2332dd7bfe5ee80ce6f8a6efd2739514da9bd4 /t/hash.t | |
download | Data-OptList-tarball-master.tar.gz |
Data-OptList-0.109HEADData-OptList-0.109master
Diffstat (limited to 't/hash.t')
-rw-r--r-- | t/hash.t | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/t/hash.t b/t/hash.t new file mode 100644 index 0000000..22b25e1 --- /dev/null +++ b/t/hash.t @@ -0,0 +1,87 @@ +#!/usr/bin/perl +use strict; +use warnings; + +=head1 TEST PURPOSE + +These tests test option list expansion (from an option list into a hashref). + +=cut + +use Sub::Install; +use Test::More tests => 13; + +BEGIN { use_ok('Data::OptList'); } + +# let's get a convenient copy to use: +Sub::Install::install_sub({ + code => 'mkopt_hash', + from => 'Data::OptList', + as => 'OPTH', +}); + +is_deeply( + OPTH(), + {}, + "empty opt list expands properly", +); + +is_deeply( + OPTH(undef), + {}, + "undef opt list expands properly", +); + +is_deeply( + OPTH([]), + {}, + "empty arrayref opt list expands properly", +); + +is_deeply( + OPTH({}), + {}, + "empty hashref opt list expands properly", +); + +is_deeply( + OPTH([ qw(foo bar baz) ]), + { foo => undef, bar => undef, baz => undef }, + "opt list of just names expands", +); + +is_deeply( + OPTH([ qw(foo :bar baz) ]), + { foo => undef, ':bar' => undef, baz => undef }, + "opt list of names expands with :group names", +); + +is_deeply( + OPTH([ foo => { a => 1 }, ':bar', 'baz' ]), + { foo => { a => 1 }, ':bar' => undef, baz => undef }, + "opt list of names and values expands", +); + +is_deeply( + OPTH([ foo => { a => 1 }, ':bar' => undef, 'baz' ]), + { foo => { a => 1 }, ':bar' => undef, baz => undef }, + "opt list of names and values expands, ignoring undef", +); + +is_deeply( + OPTH({ foo => { a => 1 }, -bar => undef, baz => undef }, 0, 'HASH'), + { foo => { a => 1 }, -bar => undef, baz => undef }, + "opt list of names and values expands with must_be", +); + +is_deeply( + OPTH({ foo => { a => 1 }, -bar => undef, baz => undef }, 0, ['HASH']), + { foo => { a => 1 }, -bar => undef, baz => undef }, + "opt list of names and values expands with [must_be]", +); + +eval { OPTH({ foo => { a => 1 }, -bar => undef, baz => undef }, 0, 'ARRAY'); }; +like($@, qr/HASH-ref values are not/, "exception tossed on invaild ref value"); + +eval { OPTH({ foo => { a => 1 }, -bar => undef, baz => undef }, 0, ['ARRAY']); }; +like($@, qr/HASH-ref values are not/, "exception tossed on invaild ref value"); |