Author: bdonlan
Date: 2004-06-27 14:31:46 -0400 (Sun, 27 Jun 2004)
New Revision: 257

Added:
   trunk/main/common/t/merge_struct.t
Modified:
   trunk/main/common/t/protocol-filter.t
   trunk/main/common/t/protocol.t
Log:
* Add tests for Haver::Util::Misc::merge_struct
* Make common/t/* executable
* Set svn:eol-style on common/t/*


Added: trunk/main/common/t/merge_struct.t
===================================================================
--- trunk/main/common/t/merge_struct.t  2004-06-27 03:49:09 UTC (rev 256)
+++ trunk/main/common/t/merge_struct.t  2004-06-27 18:31:46 UTC (rev 257)
@@ -0,0 +1,103 @@
+#!/usr/bin/perl
+# vim: set ft=perl ts=4 sw=4:
+use Test::More tests => 7;
+
+BEGIN {
+       use_ok('Haver::Util::Misc', qw(merge_struct));
+};
+
+{
+       # Basic hash merging
+       my $a = {
+               a => 42,
+               c => 11,
+       };
+       my $b = {
+               b => 42,
+               d => 22,
+       };
+       my $c = {
+               a => 42,
+               b => 42,
+               c => 11,
+               d => 22,
+       };
+       is_deeply(merge_struct($a, $b), $c, 'Basic hash merging');
+}
+
+{
+       # Basic list merging
+       my $a = [ 1, 2 ];
+       my $b = [ 3, 4 ];
+       my $c = [ 1, 2, 3, 4 ];
+       is_deeply(merge_struct($a, $b), $c, 'Basic list merging');
+}
+
+{
+       # Subhash merging
+       my $a = {
+               a => {
+                       a => 42,
+               }
+       };
+       my $b = {
+               a => {
+                       b => 42,
+               }
+       };
+       my $c = {
+               a => {
+                       a => 42,
+                       b => 42,
+               }
+       };
+       is_deeply(merge_struct($a, $b), $c, 'Subhash merging');
+}
+
+{
+       # Sublist merging
+       my $a = {
+               a => [ 1 ]
+       };
+       my $b = {
+               a => [ 2 ]
+       };
+       my $c = {
+               a => [ 1, 2 ]
+       };
+       is_deeply(merge_struct($a, $b), $c, 'Sublist merging');
+}
+
+{
+       # Precedence
+       my $a = {
+               a => 1,
+       };
+       my $b = {
+               a => 2,
+       };
+       my $c = {
+               a => 1,
+       };
+       is_deeply(merge_struct($a, $b), $c, 'Precedence');
+}
+
+{
+       # Deep precedence
+       my $a = {
+               a => {
+                       a => 1,
+               }
+       };
+       my $b = {
+               a => {
+                       a => 2,
+               }
+       };
+       my $c = {
+               a => {
+                       a => 1,
+               }
+       };
+       is_deeply(merge_struct($a, $b), $c, 'Deep precedence');
+}


Property changes on: trunk/main/common/t/merge_struct.t
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native


Property changes on: trunk/main/common/t/protocol-filter.t
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native


Property changes on: trunk/main/common/t/protocol.t
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native


Reply via email to