1# $Id: 01array.t,v 0.19 2006/10/08 03:37:29 ray Exp $
2# Before `make install' is performed this script should be runnable with
3# `make test'. After `make install' it should work as `perl test.pl'
4
5######################### We start with some black magic to print on failure.
6
7# Change 1..1 below to 1..last_test_to_print .
8# (It may become useful if the test is moved to ./t subdirectory.)
9
10my $has_data_dumper;
11BEGIN {
12  $| = 1;
13  my $tests = 6;
14  eval q[use Data::Dumper];
15  if (!$@) {
16    $has_data_dumper = 1;
17    $tests++;
18  }
19 print "1..$tests\n";
20}
21END {print "not ok 1\n" unless $loaded;}
22use Clone qw( clone );
23$loaded = 1;
24print "ok 1\n";
25
26######################### End of black magic.
27
28# Insert your test code below (better if it prints "ok 13"
29# (correspondingly "not ok 13") depending on the success of chunk 13
30# of the test code):
31
32package Test::Array;
33
34use vars @ISA;
35
36@ISA = qw(Clone);
37
38sub new
39  {
40    my $class = shift;
41    my @self = @_;
42    bless \@self, $class;
43  }
44
45package main;
46
47sub ok     { print "ok $test\n"; $test++ }
48sub not_ok { print "not ok $test\n"; $test++ }
49
50$^W = 0;
51$test = 2;
52my $a = Test::Array->new(
53    1,
54    [ 'two',
55      [ 3,
56        ['four']
57      ],
58    ],
59  );
60my $b = $a->clone(0);
61my $c = $a->clone(2);
62
63# TEST 2
64$b->[1][0] eq 'two' ? ok : not_ok;
65
66# TEST 3
67$b->[1] == $a->[1] ? ok : not_ok;
68
69# TEST 4
70$c->[1] != $a->[1] ? ok : not_ok;
71
72# TEST 5
73$c->[1][1][1] == $a->[1][1][1] ? ok : not_ok;
74
75my @circ = ();
76$circ[0] = \@circ;
77$aref = clone(\@circ);
78
79if ($has_data_dumper) {
80  Dumper(\@circ) eq Dumper($aref) ? ok : not_ok;
81}
82
83# test for unicode support
84{
85  my $a = [ chr(256) => 1 ];
86  my $b = clone( $a );
87  ord( $a->[0] ) == ord( $b->[0] ) ? ok : not_ok;
88}
89