annotate _test/Test/Lang.pm @ 168:6148f89bb7bf

IMPL::SQL::Schema::Traits::Diff alfa version IMPL::lang added hash traits
author sourcer
date Mon, 16 May 2011 04:30:38 +0400
parents
children d920d2b70230
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);
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
8 use IMPL::lang qw(:hash :compare);
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
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
77 1;