]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/25-copy.t
Importing Variable-Magic-0.07_01.tar.gz
[perl/modules/Variable-Magic.git] / t / 25-copy.t
diff --git a/t/25-copy.t b/t/25-copy.t
new file mode 100644 (file)
index 0000000..58cf8e9
--- /dev/null
@@ -0,0 +1,63 @@
+#!perl -T
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use Variable::Magic qw/wizard cast MGf_COPY/;
+
+if (!MGf_COPY) {
+ plan skip_all => "this perl doesn't handle copy magic";
+} else {
+ plan tests => 16;
+}
+
+my $c = 0;
+my $wiz = wizard copy => sub { ++$c };
+ok($c == 0, 'copy : create wizard');
+
+use Tie::Array;
+
+tie my @a, 'Tie::StdArray';
+cast @a, $wiz;
+ok($c == 0, 'copy (array) : cast');
+
+my $n = time;
+$a[0] = $n;
+ok($c == 1, 'copy (array) : store element');
+
+my $e = exists $a[0];
+ok($c == 2, 'copy (array) : exists element');
+ok($e,      'copy (array) : exists element, really'); 
+
+my $b = $a[0];
+ok($c == 3, 'copy (array) : fetch element');
+ok($b == $n, 'copy (array) : fetch element correctly');
+
+use Tie::Hash;
+
+$c = 0;
+
+tie my %h, 'Tie::StdHash';
+cast %h, $wiz;
+ok($c == 0, 'copy (hash) : cast');
+
+my ($k, $v) = (time, int rand time);
+$h{$k} = $v;
+ok($c == 1, 'copy (hash) : store element');
+
+$e = exists $h{$k};
+ok($c == 2, 'copy (hash) : exists element');
+ok($e,      'copy (hash) : exists element, really');
+
+my $w = $h{$k};
+ok($c == 3, 'copy (hash) : fetch element');
+ok($w == $v, 'copy (hash) : fetch element correctly');
+
+my ($K, $V) = each %h;
+ok($c == 4, 'copy (hash) : iterate');
+ok($k == $K && $v == $V, 'copy (hash) : iterate correctly');
+
+delete $h{$k};
+ok($c == 5, 'copy (hash) : delete');