File: 07_overload.t

package info (click to toggle)
libwx-perl 1%3A0.9909-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,912 kB
  • sloc: cpp: 9,728; perl: 8,182; ansic: 626; makefile: 41
file content (113 lines) | stat: -rwxr-xr-x 4,856 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/perl -w

use strict;
use Wx;
use lib './t';

use Tests_Helper qw(test_app);
use Test::More 'tests' => 110;

my $undef = undef;

my $app = test_app( sub { 1 } );

for my $i ( [ \&Wx::_match, 'match' ],
            [ \&Wx::_xsmatch, 'xsmatch' ] ) {
  my( $m, $t ) = @$i;
  local *xx = $m;

  # some simple cases
  ok(  xx( [ [] ], $Wx::_arr ), "$t: match an array" );
  ok(  xx( [ [], 1 ], $Wx::_arr ),
      "$t: more arguments than in prototype" );
  ok( !xx( [ '' ], $Wx::_arr ), "$t: wrong arguments" );
  ok(  xx( [ [] ], $Wx::_arr ), "$t: match with required arguments" );
  ok( !xx( [ [], 1 ], $Wx::_arr, 1 ),
      "$t: don't match with more than required" );
  ok(  xx( [ [] ], $Wx::_arr, 1, 1 ),
      "$t: match with required arguments and allow_more" );
  ok(  xx( [ [], 1 ], $Wx::_arr, 1, 1 ),
      "$t: match with more than required and allow_more" );

  # tests for boolean
  ok(  xx( [ [] ], $Wx::_b ), "$t: boolean matches reference" );
  ok(  xx( [ 1 ],  $Wx::_b ), "$t: boolean matches integer" );
  ok(  xx( [ 0 ],  $Wx::_b ), "$t: boolean matches zero" );
  ok(  xx( [ undef ], $Wx::_b ), "$t: boolean matches literal undef" );
  ok(  xx( [ $undef ], $Wx::_b ), "$t: boolean matches undefined variable" );
  ok(  xx( [ 'foo' ], $Wx::_b ), "$t: boolean matches string" );

  # test for string
  ok(  xx( [ [] ], $Wx::_s ), "$t: string matches reference" );
  ok(  xx( [ 1 ],  $Wx::_s ), "$t: string matches integer" );
  ok(  xx( [ 0 ],  $Wx::_s ), "$t: string matches zero" );
  ok(  xx( [ undef ], $Wx::_s ), "$t: string matches literal undef" );
  ok(  xx( [ $undef ], $Wx::_s ), "$t: string matches undefined variable" );
  ok(  xx( [ 'foo' ], $Wx::_s ), "$t: string matches string" );

  # test for number
  ok( !xx( [ [] ], $Wx::_n ), "$t: number does not match reference" );
  ok(  xx( [ 1 ],  $Wx::_n ), "$t: number matches integer" );
  ok(  xx( [ 0 ],  $Wx::_n ), "$t: number matches zero" );
  ok(  xx( [ 1.2 ],  $Wx::_n ), "$t: number matches floating point" );
  ok(  xx( [ 0.0 ],  $Wx::_n ), "$t: number matches floating point zero" );
  ok( !xx( [ undef ], $Wx::_n ), "$t: number does not match literal undef" );
  ok( !xx( [ $undef ], $Wx::_n ),
      "$t: number does not match undefined variable" );
  ok( !xx( [ 'foo' ], $Wx::_n ), "$t: number does not match string" );

  # test Wx::Sizer
  ok( !xx( [ [] ], $Wx::_wszr ),
      "$t: Wx::Sizer does not match reference" );
  ok( !xx( [ 1 ],  $Wx::_wszr ), "$t: Wx::Sizer does not match integer" );
  ok( !xx( [ 0 ],  $Wx::_wszr ), "$t: Wx::Sizer does not match zero" );
  ok(  xx( [ undef ], $Wx::_wszr ), "$t: Wx::Sizer matches literal undef" );
  ok(  xx( [ $undef ], $Wx::_wszr ),
       "$t: Wx::Sizer matches undefined variable" );
  ok( !xx( [ 'foo' ], $Wx::_wszr ), "$t: Wx::Sizer does not match string" );
  ok(  xx( [ Wx::BoxSizer->new( Wx::wxVERTICAL() ) ], $Wx::_wszr ),
       "$t: Wx::Sizer matches Wx::Sizer" );

  # test Wx::Image
  ok( !xx( [ [] ], $Wx::_wimg ),
      "$t: Wx::Image does not match reference" );
  ok( !xx( [ 1 ],  $Wx::_wimg ), "$t: Wx::Image does not match integer" );
  ok( !xx( [ 0 ],  $Wx::_wimg ), "$t: Wx::Image does not match zero" );
  ok(  xx( [ undef ], $Wx::_wimg ), "$t: Wx::Image matches literal undef" );
  ok(  xx( [ $undef ], $Wx::_wimg ),
       "$t: Wx::Image matches undefined variable" );
  ok( !xx( [ 'foo' ], $Wx::_wimg ), "$t: Wx::Image does not match string" );
  ok(  xx( [ Wx::Image->new( 1, 2 ) ], $Wx::_wimg ),
       "$t: Wx::Image matches Wx::Image" );

  # test for Wx::Point/Wx::Size
  ok(  xx( [ [] ], $Wx::_wpoi ),
      "$t: Wx::Point matches ARRAY reference" );
  ok( !xx( [ {} ], $Wx::_wpoi ),
      "$t: Wx::Point does not match other reference" );
  ok( !xx( [ 1 ],  $Wx::_wpoi ), "$t: Wx::Point does not match integer" );
  ok( !xx( [ 0 ],  $Wx::_wpoi ), "$t: Wx::Point does not match zero" );
  ok(  xx( [ $undef ], $Wx::_wpoi ),
      "$t: Wx::Point matches undefined variable" );
  ok( !xx( [ 'foo' ], $Wx::_wpoi ), "$t: Wx::Point does not match string" );
  ok(  xx( [ Wx::Point->new( 1, 1 ) ], $Wx::_wpoi ),
       "$t: Wx::Point matches Wx::Point" );
  ok(  xx( [ Wx::Size->new( 1, 2 ) ], $Wx::_wsiz ),
       "$t: Wx::Size matches Wx::Size" );

  # test for Wx::Input/OutputStream
  ok(  xx( [ [], 1 ], $Wx::_wist_n ),
      "$t: Wx::InputStream matches references" );
  ok(  xx( [ {}, 1 ], $Wx::_wist_n ),
      "$t: Wx::InputStream matches references (again)" );
  ok( !xx( [ 1, 1 ], $Wx::_wist_n ),
      "$t: Wx::InputStream does not match integer" );
  ok( !xx( [ 'foo', 1 ], $Wx::_wist_n ),
      "$t: Wx::InputStream does not match string" );
  ok(  xx( [ undef, 1 ], $Wx::_wist_n ),
      "$t: Wx::InputStream matches undef" );
  ok(  xx( [ *main::bar, 1 ], $Wx::_wist_n ),
      "$t: Wx::InputStream matches typeglobs" );
  *main::bar = *main::bar; # fool warning
}