File: merge-hash.t

package info (click to toggle)
libtext-wikiformat-perl 0.81-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 240 kB
  • sloc: perl: 1,218; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download | duplicates (4)
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
#!perl

use strict;
use warnings;

use Test::More tests => 6;
use_ok( 'Text::WikiFormat' ) or exit;

my $full       = { foo => { bar => 'baz' } };
my $empty      = {};
my $nonempty   = { foo => { a => 'b' } };
my $full_flat  = { a => 'b' };
my $empty_flat = {};
my $zero       = { foo => 0, bar => { baz => 0 } };

$nonempty = Text::WikiFormat::merge_hash( $full, $nonempty );
is_deeply( $nonempty, { foo => { a => 'b', bar => 'baz' } },
	"merge should work when all keys in from exist in to" );
$full->{foo}->{bar} = 'boo';
is_deeply( $nonempty, { foo => { a => 'b', bar => 'baz' } },
	"merge should copy subhashes" );

$empty_flat = Text::WikiFormat::merge_hash( $full_flat, $empty_flat );
is_deeply( $empty_flat, $full_flat,
	'... in flat case when keys exist in from but not in to' );

$empty = Text::WikiFormat::merge_hash( $full, $empty );
is_deeply( $empty, $full,
	'... in non-flat case when keys exist in but not in to' );

$empty = {};
$empty = Text::WikiFormat::merge_hash( $zero, $empty );
is_deeply( $empty, $zero, '... and when value is zero but defined' );