annotate _test/Test/Lang.pm @ 175:9057e4b95d10

corrected cloning method
author sourcer
date Wed, 05 Oct 2011 00:48:43 +0300
parents d920d2b70230
children 74c27daf2e7b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
1 package Test::Lang;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
2 use strict;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
3 use warnings;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
4
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
5 use parent qw(IMPL::Test::Unit);
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
6
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
7 use IMPL::Test qw(test failed assert);
174
d920d2b70230 minor changes
sergey
parents: 168
diff changeset
8 use IMPL::lang qw(:hash :compare clone);
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
9
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
10 __PACKAGE__->PassThroughArgs;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
11
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
12 test equals => sub {
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
13 assert( equals(1,1) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
14 assert( !equals(1,2) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
15
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
16 {
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
17 my $warns = 0;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
18 local $SIG{__WARN__} = sub { $warns++ };
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
19
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
20 assert( !equals("1","2") );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
21 assert( equals("sfds","zxcvgfd") );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
22 assert( $warns == 2);
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
23 }
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
24
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
25 assert( equals(undef,undef) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
26 assert( !equals(1,undef) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
27 assert( !equals(undef,"zcx") );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
28 };
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
29
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
30 test equals_s => sub {
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
31 assert( equals_s(1,1) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
32 assert( !equals_s(1,2) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
33
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
34 assert( !equals_s("1","2") );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
35 assert( !equals_s("sfds","zxcvgfd") );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
36
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
37 assert( equals_s(undef,undef) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
38 assert( !equals_s(1,undef) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
39 assert( !equals_s(undef,"zcx") );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
40
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
41 assert( equals_s("qwerty","qwerty") );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
42 };
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
43
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
44 test hash => sub {
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
45
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
46 my %a = (
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
47 a => 'a',
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
48 b => 'b',
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
49 c => 'c'
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
50 );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
51
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
52 my %b = (
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
53 a => 'a',
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
54 c => 'z',
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
55 x => 'x',
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
56 );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
57
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
58 my %diff = (
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
59 '-b' => 1,
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
60 '+c' => 'z',
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
61 '+x' => 'x'
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
62 );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
63
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
64
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
65 assert( ! hashCompare(\%a,\%b) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
66 assert( hashCompare(\%a,\%a) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
67
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
68 my $res = hashDiff(\%a,\%b);
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
69
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
70 assert( ! hashCompare({},$res) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
71 assert( hashCompare($res,\%diff) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
72
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
73 assert( hashCompare( \%b, hashMerge(\%a,\%diff) ) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
74
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
75 };
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
76
175
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
77 test clone => sub {
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
78
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
79 my $a;
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
80
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
81 my $b = clone($a);
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
82
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
83 assert(not defined $b);
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
84
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
85 my $lp = { a => '1' };
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
86 $lp->{b} = $lp;
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
87
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
88 my $c = clone($lp);
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
89
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
90 assert($c);
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
91 assert($c->{b});
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
92 assert($c->{b} == $c);
174
d920d2b70230 minor changes
sergey
parents: 168
diff changeset
93
d920d2b70230 minor changes
sergey
parents: 168
diff changeset
94 };
d920d2b70230 minor changes
sergey
parents: 168
diff changeset
95
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
96 1;