Permalink
Browse files

adding diff_arrays test

  • Loading branch information...
1 parent 890ab2d commit 5378ba064d5fc86702933daf2f2c0d25a45d24eb @xsawyerx committed May 5, 2010
Showing with 35 additions and 0 deletions.
  1. +35 −0 t/diff_arrays.t
View
@@ -0,0 +1,35 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+use Algorithm::Diff::Callback 'diff_arrays';
+
+my @old = qw( john jim james jackie jarule );
+my @new = qw( john jim james jojo jackie );
+
+diff_arrays(
+ \@old, \@new,
+ sub {
+ my $val = shift;
+ is( $val, 'jarule', 'Goodbye jarule!' );
+ },
+ sub {
+ my $val = shift;
+ is( $val, 'jojo', 'Hello jojo!');
+ },
+);
+
+my $empty_list = 0;
+diff_arrays( [], [], sub { $empty_list++ }, sub { $empty_list++ } );
+cmp_ok( $empty_list, '==', 0, 'Empty list does not get called' );
+
+my $no_change = 0;
+diff_arrays( \@old, \@old, sub { $no_change++ }, sub { $no_change++ } );
+cmp_ok( $no_change, '==', 0, 'No change does not get called' );
+
+my $new_count = 0;
+diff_arrays( [], \@new, sub { $new_count-- }, sub { $new_count++ } );
+cmp_ok( $new_count, '==', scalar @new, 'New from scratch' );
+

0 comments on commit 5378ba0

Please sign in to comment.