| 1 |
#!perl |
| 2 |
|
| 3 |
BEGIN { chdir 't' if -d 't' } |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
|
| 8 |
use Test::More tests => 9; |
| 9 |
use Test::NoWarnings; |
| 10 |
|
| 11 |
use_ok('Text::MediawikiFormat') or exit; |
| 12 |
|
| 13 |
my $full = { foo => { bar => 'baz' } }; |
| 14 |
my $empty = {}; |
| 15 |
my $nonempty = { foo => { a => 'b' } }; |
| 16 |
my $full_flat = { a => 'b' }; |
| 17 |
my $empty_flat = {}; |
| 18 |
my $zero = { foo => 0, bar => { baz => 0 } }; |
| 19 |
|
| 20 |
$nonempty = Text::MediawikiFormat::_merge_hashes( $full, $nonempty ); |
| 21 |
is_deeply $nonempty, { foo => { a => 'b', bar => 'baz' } }, "merge should work when all keys in from exist in to"; |
| 22 |
$full->{foo}->{bar} = 'boo'; |
| 23 |
is_deeply $nonempty, { foo => { a => 'b', bar => 'baz' } }, "merge should copy subhashes"; |
| 24 |
|
| 25 |
$empty_flat = Text::MediawikiFormat::_merge_hashes( $full_flat, $empty_flat ); |
| 26 |
is_deeply $empty_flat, $full_flat, '... in flat case when keys exist in from but not in to'; |
| 27 |
|
| 28 |
$empty = Text::MediawikiFormat::_merge_hashes( $full, $empty ); |
| 29 |
is_deeply $empty, $full, '... in non-flat case when keys exist in but not in to'; |
| 30 |
|
| 31 |
$empty = {}; |
| 32 |
$empty = Text::MediawikiFormat::_merge_hashes( $zero, $empty ); |
| 33 |
is_deeply $empty, $zero, '...and when value is zero but defined'; |
| 34 |
|
| 35 |
my $regexer = { a => "regex" }; |
| 36 |
my $arrayer = { a => [ "X", "Y", "Z" ] }; |
| 37 |
my $merged; |
| 38 |
$merged = Text::MediawikiFormat::_merge_hashes( $regexer, $arrayer ); |
| 39 |
is_deeply $merged, { a => "regex" }, "regexes should replace arrays"; |
| 40 |
$merged = Text::MediawikiFormat::_merge_hashes( $arrayer, $regexer ); |
| 41 |
is_deeply $merged, { a => [ "X", "Y", "Z" ] }, "...and vice versa"; |