]> git.vpit.fr Git - perl/modules/Test-Leaner.git/commitdiff
Test is_deeply against deep datastructures
authorVincent Pit <vince@profvince.com>
Tue, 28 Dec 2010 23:49:27 +0000 (00:49 +0100)
committerVincent Pit <vince@profvince.com>
Tue, 28 Dec 2010 23:49:27 +0000 (00:49 +0100)
MANIFEST
t/28-is_deeply-deep.t [new file with mode: 0644]

index 539d7a618129466081691e4e733378ee8f167a77..734c6e9ba1a26c0447063a71889ea3f20cc6e38b 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -27,6 +27,7 @@ t/22-is.t
 t/24-cmp_ok.t
 t/26-is_deeply.t
 t/27-is_deeply-failing.t
+t/28-is_deeply-deep.t
 t/91-pod.t
 t/92-pod-coverage.t
 t/95-portability-files.t
diff --git a/t/28-is_deeply-deep.t b/t/28-is_deeply-deep.t
new file mode 100644 (file)
index 0000000..2beae50
--- /dev/null
@@ -0,0 +1,46 @@
+#!perl -T
+
+use strict;
+use warnings;
+
+use Test::Leaner tests => 2;
+
+sub create_chain {
+ my ($l, $n) = @_;
+
+ $n = 1  unless defined $n;
+ $l = 45 unless defined $l;
+
+ return \(\$n) if $l <= 0;
+
+ [
+  [ 0, \(\$n) ],
+  1,
+  { a => create_chain($l - 1, $n + 1) },
+ ]
+}
+
+my $c1 = create_chain;
+my $c2 = create_chain;
+
+is_deeply $c1, $c2, 'a deep chain structure';
+
+sub create_tree {
+ my ($l, $n) = @_;
+
+ $n = 1  unless defined $n;
+ $l = 10 unless defined $l;
+
+ return \(\$n) if $l <= 0;
+
+ [
+  { a => create_tree($l - 1, 2 * $n) },
+  1,
+  { b => create_tree($l - 1, 2 * $n + 1) },
+ ]
+}
+
+my $t1 = create_tree;
+my $t2 = create_tree;
+
+is_deeply $t1, $t2, 'a deep tree structure';