1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
use Test::More 'no_plan';
my %hash = (
top_1 => 'def val top 1',
top_2 => 'def val top 2',
top_3 => 'def val top 3',
Classname_1 => {
top_2 => 'class 1 val top 2',
},
Classname_2 => {
top_1 => 'class 2 val top 1',
top_2 => 'class 2 val top 2',
top_3 => 'class 2 val top 3',
},
Bad => 'class',
);
my %orig_hash = %hash;
my %expect_1 = (
top_1 => 'def val top 1',
top_2 => 'class 1 val top 2',
top_3 => 'def val top 3',
Classname_1 => {
top_2 => 'class 1 val top 2',
},
Classname_2 => {
top_1 => 'class 2 val top 1',
top_2 => 'class 2 val top 2',
top_3 => 'class 2 val top 3',
},
Bad => 'class',
);
my %expect_2 = (
top_1 => 'class 2 val top 1',
top_2 => 'class 2 val top 2',
top_3 => 'class 2 val top 3',
Classname_1 => {
top_2 => 'class 1 val top 2',
},
Classname_2 => {
top_1 => 'class 2 val top 1',
top_2 => 'class 2 val top 2',
top_3 => 'class 2 val top 3',
},
Bad => 'class',
);
package Classname_1;
use Class::Std::Utils;
my %args1 = extract_initializers_from(\%hash);
::is_deeply \%hash, \%orig_hash => 'Original args unchanged in class 1';
::is_deeply \%args1, \%expect_1 => 'Extracted as expected in class 1';
package Classname_2;
use Class::Std::Utils;
my %args2 = extract_initializers_from(\%hash);
::is_deeply \%hash, \%orig_hash => 'Original args unchanged in class 2';
::is_deeply \%args2, \%expect_2 => 'Extracted as expected in class 2';
package Classname_3;
use Class::Std::Utils;
my %args3 = extract_initializers_from(\%hash);
::is_deeply \%hash, \%orig_hash => 'Original args unchanged in class 2';
::is_deeply \%args3, \%hash => 'Extracted as expected in class 3';
package Bad;
use Class::Std::Utils;
::ok !eval { extract_initializers_from(\%hash); 1 }
=> 'Exception for bad specification';
::like $@, qr/^Bad initializer must be a nested hash/
=> 'Correct exception thrown';
|