annotate _test/Test/Lang.pm @ 215:77a9934a44af

sync, migrating to XML::Compile
author cin
date Sun, 19 Aug 2012 22:27:43 +0400
parents 4d0e1962161c
children
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);
179
b3d91ff7aea9 minor changes
sourcer
parents: 176
diff changeset
9 use Scalar::Util qw(reftype);
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
10
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
11 __PACKAGE__->PassThroughArgs;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
12
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
13 test equals => sub {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
14 assert( equals(1,1) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
15 assert( !equals(1,2) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
16
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
17 {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
18 my $warns = 0;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
19 local $SIG{__WARN__} = sub { $warns++ };
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
20
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
21 assert( !equals("1","2") );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
22 assert( equals("sfds","zxcvgfd") );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
23 assert( $warns == 2);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
24 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
25
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
26 assert( equals(undef,undef) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
27 assert( !equals(1,undef) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
28 assert( !equals(undef,"zcx") );
168
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
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
31 test equals_s => sub {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
32 assert( equals_s(1,1) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
33 assert( !equals_s(1,2) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
34
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
35 assert( !equals_s("1","2") );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
36 assert( !equals_s("sfds","zxcvgfd") );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
37
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
38 assert( equals_s(undef,undef) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
39 assert( !equals_s(1,undef) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
40 assert( !equals_s(undef,"zcx") );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
41
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
42 assert( equals_s("qwerty","qwerty") );
168
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
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
45 test hash => sub {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
46
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
47 my %a = (
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
48 a => 'a',
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
49 b => 'b',
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
50 c => 'c'
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
51 );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
52
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
53 my %b = (
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
54 a => 'a',
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
55 c => 'z',
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
56 x => 'x',
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
57 );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
58
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
59 my %diff = (
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
60 '-b' => 1,
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
61 '+c' => 'z',
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
62 '+x' => 'x'
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
63 );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
64
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
65
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
66 assert( ! hashCompare(\%a,\%b) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
67 assert( hashCompare(\%a,\%a) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
68
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
69 my $res = hashDiff(\%a,\%b);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
70
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
71 assert( ! hashCompare({},$res) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
72 assert( hashCompare($res,\%diff) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
73
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
74 assert( hashCompare( \%b, hashMerge(\%a,\%diff) ) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
75
168
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
175
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
78 test clone => sub {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
79
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
80 my $a;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
81
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
82 my $b = clone($a);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
83
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
84 assert(not defined $b);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
85
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
86 my $lp = { a => '1', rx => qr/abc$/ };
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
87 $lp->{b} = $lp;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
88
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
89 my $c = clone($lp);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
90
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
91 assert($c);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
92 assert($c->{b});
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
93 assert($c->{b} == $c);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
94 assert(reftype $c->{rx} eq 'REGEXP');
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
95
174
d920d2b70230 minor changes
sergey
parents: 168
diff changeset
96 };
d920d2b70230 minor changes
sergey
parents: 168
diff changeset
97
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
98 test hashParse => sub {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
99 my $res = hashParse("a = test a\nb = test b\nc c=test c");
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
100
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
101 assert($res->{a} eq "test a");
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
102 assert($res->{b} eq "test b");
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
103 assert($res->{"c c"} eq "test c");
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
104
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
105 $res = hashParse("a:b, c: d",qr/\s*:\s*/,qr/\s*,\s*/);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
106
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
107 assert($res->{a} eq "b");
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
108 assert($res->{c} eq "d");
176
74c27daf2e7b minor changes
sergey
parents: 175
diff changeset
109 };
74c27daf2e7b minor changes
sergey
parents: 175
diff changeset
110
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
111 1;