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
10BEGIN { $| = 1; print "1..7\n"; }
11END {print "not ok 1\n" unless $loaded;}
12use Clone qw( clone );
13use Data::Dumper;
14$loaded = 1;
15print "ok 1\n";
16
17######################### End of black magic.
18
19# Insert your test code below (better if it prints "ok 13"
20# (correspondingly "not ok 13") depending on the success of chunk 13
21# of the test code):
22
23package Test::Array;
24
25use vars @ISA;
26
27@ISA = qw(Clone);
28
29sub new
30  {
31    my $class = shift;
32    my @self = @_;
33    bless \@self, $class;
34  }
35
36package main;
37                                                
38sub ok     { print "ok $test\n"; $test++ }
39sub not_ok { print "not ok $test\n"; $test++ }
40
41$^W = 0;
42$test = 2;
43my $a = Test::Array->new(
44    1, 
45    [ 'two', 
46      [ 3,
47        ['four']
48      ],
49    ],
50  );
51my $b = $a->clone(0);
52my $c = $a->clone(2);
53
54# TEST 2
55$b->[1][0] eq 'two' ? ok : not_ok;
56
57# TEST 3
58$b->[1] == $a->[1] ? ok : not_ok;
59
60# TEST 4
61$c->[1] != $a->[1] ? ok : not_ok;
62
63# TEST 5
64$c->[1][1][1] == $a->[1][1][1] ? ok : not_ok;
65
66my @circ = ();
67$circ[0] = \@circ;
68$aref = clone(\@circ);
69Dumper(\@circ) eq Dumper($aref) ? ok : not_ok;
70
71# test for unicode support
72{
73  my $a = [ chr(256) => 1 ];
74  my $b = clone( $a );
75  ord( $a->[0] ) == ord( $b->[0] ) ? ok : not_ok;
76}
77