annotate _test/Test/Lang.pm @ 181:47dac58691ee

New templating system, small fixes
author sourcer
date Thu, 26 Jan 2012 01:15:57 +0400
parents d1676be8afcc
children 4d0e1962161c
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 {
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
14 assert( equals(1,1) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
15 assert( !equals(1,2) );
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 {
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
18 my $warns = 0;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
19 local $SIG{__WARN__} = sub { $warns++ };
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
20
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
21 assert( !equals("1","2") );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
22 assert( equals("sfds","zxcvgfd") );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
23 assert( $warns == 2);
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
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
26 assert( equals(undef,undef) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
27 assert( !equals(1,undef) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
28 assert( !equals(undef,"zcx") );
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 {
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
32 assert( equals_s(1,1) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
33 assert( !equals_s(1,2) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
34
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
35 assert( !equals_s("1","2") );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
36 assert( !equals_s("sfds","zxcvgfd") );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
37
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
38 assert( equals_s(undef,undef) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
39 assert( !equals_s(1,undef) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
40 assert( !equals_s(undef,"zcx") );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
41
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
42 assert( equals_s("qwerty","qwerty") );
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 {
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
46
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
47 my %a = (
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
48 a => 'a',
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
49 b => 'b',
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
50 c => 'c'
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
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
53 my %b = (
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
54 a => 'a',
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
55 c => 'z',
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
56 x => 'x',
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
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
59 my %diff = (
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
60 '-b' => 1,
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
61 '+c' => 'z',
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
62 '+x' => 'x'
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
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
66 assert( ! hashCompare(\%a,\%b) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
67 assert( hashCompare(\%a,\%a) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
68
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
69 my $res = hashDiff(\%a,\%b);
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
70
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
71 assert( ! hashCompare({},$res) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
72 assert( hashCompare($res,\%diff) );
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
73
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
74 assert( hashCompare( \%b, hashMerge(\%a,\%diff) ) );
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
175
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
78 test clone => sub {
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
79
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
80 my $a;
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
81
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
82 my $b = clone($a);
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
83
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
84 assert(not defined $b);
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
85
179
b3d91ff7aea9 minor changes
sourcer
parents: 176
diff changeset
86 my $lp = { a => '1', rx => qr/abc$/ };
175
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
87 $lp->{b} = $lp;
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
88
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
89 my $c = clone($lp);
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
90
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
91 assert($c);
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
92 assert($c->{b});
9057e4b95d10 corrected cloning method
sourcer
parents: 174
diff changeset
93 assert($c->{b} == $c);
179
b3d91ff7aea9 minor changes
sourcer
parents: 176
diff changeset
94 assert(reftype $c->{rx} eq 'REGEXP');
174
d920d2b70230 minor changes
sergey
parents: 168
diff changeset
95
d920d2b70230 minor changes
sergey
parents: 168
diff changeset
96 };
d920d2b70230 minor changes
sergey
parents: 168
diff changeset
97
176
74c27daf2e7b minor changes
sergey
parents: 175
diff changeset
98 test hashParse => sub {
74c27daf2e7b minor changes
sergey
parents: 175
diff changeset
99 my $res = hashParse("a = test a\nb = test b\nc c=test c");
74c27daf2e7b minor changes
sergey
parents: 175
diff changeset
100
74c27daf2e7b minor changes
sergey
parents: 175
diff changeset
101 assert($res->{a} eq "test a");
74c27daf2e7b minor changes
sergey
parents: 175
diff changeset
102 assert($res->{b} eq "test b");
74c27daf2e7b minor changes
sergey
parents: 175
diff changeset
103 assert($res->{"c c"} eq "test c");
74c27daf2e7b minor changes
sergey
parents: 175
diff changeset
104
74c27daf2e7b minor changes
sergey
parents: 175
diff changeset
105 $res = hashParse("a:b, c: d",qr/\s*:\s*/,qr/\s*,\s*/);
74c27daf2e7b minor changes
sergey
parents: 175
diff changeset
106
74c27daf2e7b minor changes
sergey
parents: 175
diff changeset
107 assert($res->{a} eq "b");
74c27daf2e7b minor changes
sergey
parents: 175
diff changeset
108 assert($res->{c} eq "d");
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;