| 1 | use strictscip-perl cpan Config-MVP-Slicer 0.303 strict/; |
| 2 | use warningsscip-perl cpan Config-MVP-Slicer 0.303 warnings/; |
| 3 | use Test::More 0.96scip-perl cpan Config-MVP-Slicer 0.303 Test/`More 0.96`/; |
| 4 | |
| 5 | my $mod = 'Config::MVP::Slicer'; |
| 6 | eval "require $mod" or diescip-perl cpan Config-MVP-Slicer 0.303 main/die(). $@scip-perl cpan Config-MVP-Slicer 0.303 main/`$@`.; |
| 7 | |
| 8 | my $slicer = new_okscip-perl cpan Config-MVP-Slicer 0.303 main/new_ok().($mod, [{ |
| 9 | config => { |
| 10 | opt => 'main config val', |
| 11 | 'Plug.attr' => 'pa', |
| 12 | 'Mod::Name.opt' => 'val', |
| 13 | 'Moose.and[]' => 'squirrel', |
| 14 | 'Hunting.season[0]' => 'duck', |
| 15 | 'Hunting.season[1]' => 'wabbit', |
| 16 | 'Hunting.season[9]' => 'fudd', |
| 17 | # keys are sorted very simply (alphabetically) |
| 18 | 'Hunting2.season[1.09]' => 'bunny', |
| 19 | 'Hunting2.season[1.10]' => 'bird', |
| 20 | 'Hunting2.season[1.08]' => 'wabbit', |
| 21 | 'Hunting2.season[1.11]' => 'duck', |
| 22 | 'Hunting2.season[z]' => 'zombie', |
| 23 | }, |
| 24 | }]); |
| 25 | |
| 26 | is_deeplyscip-perl cpan Config-MVP-Slicer 0.303 main/is_deeply(). |
| 27 | $slicer->mergescip-perl cpan Config-MVP-Slicer 0.303 main/merge().([Plug => 'X::Plug' => {}]), |
| 28 | [Plug => 'X::Plug' => { attr => 'pa' }], |
| 29 | 'merge to empty hash'; |
| 30 | |
| 31 | my $previous = { previous => 'config' }; |
| 32 | is_deeplyscip-perl cpan Config-MVP-Slicer 0.303 main/is_deeply(). |
| 33 | $slicer->mergescip-perl cpan Config-MVP-Slicer 0.303 main/merge().([ModName => 'Mod::Name' => $previous ])->[2], |
| 34 | { previous => 'config', opt => 'val' }, |
| 35 | 'matches on class name'; |
| 36 | |
| 37 | is_deeplyscip-perl cpan Config-MVP-Slicer 0.303 main/is_deeply(). |
| 38 | $previous, |
| 39 | { previous => 'config', opt => 'val' }, |
| 40 | 'merge overwrites hash'; |
| 41 | |
| 42 | is_deeplyscip-perl cpan Config-MVP-Slicer 0.303 main/is_deeply(). |
| 43 | $slicer->mergescip-perl cpan Config-MVP-Slicer 0.303 main/merge().([Moose => Moose => { and => [qw(cow)] }])->[2], |
| 44 | { and => [qw(cow squirrel)] }, |
| 45 | 'merged array ref when specified as []'; |
| 46 | |
| 47 | is_deeplyscip-perl cpan Config-MVP-Slicer 0.303 main/is_deeply(). |
| 48 | $slicer->mergescip-perl cpan Config-MVP-Slicer 0.303 main/merge().([Hunting => 'X::Hunting' => { -shot => 'gun', season => 'looney' }])->[2], |
| 49 | { -shot => 'gun', season => [qw(looney duck wabbit fudd)] }, |
| 50 | 'convert previous string to array ref as specified'; |
| 51 | |
| 52 | is_deeplyscip-perl cpan Config-MVP-Slicer 0.303 main/is_deeply(). |
| 53 | $slicer->mergescip-perl cpan Config-MVP-Slicer 0.303 main/merge().([Hunting2 => 'X::Hunting' => { -shot => 'gun', season => ['looney'] }])->[2], |
| 54 | { -shot => 'gun', season => [qw(looney wabbit bunny bird duck zombie)] }, |
| 55 | 'merge arrayref in order'; |
| 56 | |
| 57 | is_deeplyscip-perl cpan Config-MVP-Slicer 0.303 main/is_deeply(). |
| 58 | $slicer->mergescip-perl cpan Config-MVP-Slicer 0.303 main/merge().([Plug => 'X::Plug' => { attr => [qw(ibute)] }])->[2], |
| 59 | { attr => [qw(ibute pa)] }, |
| 60 | 'merged array ref when previous value was arrayref'; |
| 61 | |
| 62 | is_deeplyscip-perl cpan Config-MVP-Slicer 0.303 main/is_deeply(). |
| 63 | $slicer->mergescip-perl cpan Config-MVP-Slicer 0.303 main/merge().([Plug => 'X::Plug' => { attr => 'ibute' }])->[2], |
| 64 | { attr => 'pa' }, |
| 65 | 'overwrite when neither is arrayref'; |
| 66 | |
| 67 | is_deeplyscip-perl cpan Config-MVP-Slicer 0.303 main/is_deeply(). |
| 68 | $slicer->mergescip-perl cpan Config-MVP-Slicer 0.303 main/merge().([Plug => 'X::Plug' => { attr => 'ibute' }], |
| 69 | {slice => {attr => 'x'}})->[2], |
| 70 | { attr => 'x' }, |
| 71 | 'overwrite with passed in slice'; |
| 72 | |
| 73 | is_deeplyscip-perl cpan Config-MVP-Slicer 0.303 main/is_deeply(). |
| 74 | $slicer->mergescip-perl cpan Config-MVP-Slicer 0.303 main/merge().([Hunting2 => 'X::Hunting' => { -shot => 'gun', season => ['looney'] }], |
| 75 | {slice => {season => [qw(tunes party)]}})->[2], |
| 76 | { -shot => 'gun', season => [qw(looney tunes party)] }, |
| 77 | 'merge arrayref with passed in slice'; |
| 78 | |
| 79 | done_testing; |