6
if (default_args::anonymous() != 7771) {
7
die "anonymous (1) failed";
9
if (default_args::anonymous(1234) != 1234) {
10
die "anonymous (2) failed";
14
if (default_args::booltest() != $true) {
15
die "booltest (1) failed";
17
if (default_args::booltest($true) != $true) {
18
die "booltest (2) failed";
20
if (default_args::booltest($false) != $false) {
21
die "booltest (3) failed";
24
$ec = new default_args::EnumClass();
25
if ($ec->blah() != $true) {
26
die "EnumClass failed";
29
if (default_args::casts1() != null) {
33
if (default_args::casts2() ne "Hello") {
37
if (default_args::casts1("Ciao") ne "Ciao") {
38
die "casts1 not default failed";
41
if (default_args::chartest1() ne 'x') {
42
die "chartest1 failed";
45
if (default_args::chartest2() != '\0') {
46
die "chartest2 failed";
49
if (default_args::chartest1('y') ne 'y') {
50
die "chartest1 not default failed";
53
if (default_args::chartest1('y') ne 'y') {
54
die "chartest1 not default failed";
57
if (default_args::reftest1() != 42) {
58
die "reftest1 failed";
61
if (default_args::reftest1(400) != 400) {
62
die "reftest1 not default failed";
65
if (default_args::reftest2() ne "hello") {
66
die "reftest2 failed";
3
use Test::More tests => 40;
4
BEGIN { use_ok('default_args') }
5
require_ok('default_args');
10
is(default_args::anonymous(), 7771, "anonymous (1)");
11
is(default_args::anonymous(1234), 1234, "anonymous (2)");
13
is(default_args::booltest(), $true, "booltest (1)");
14
is(default_args::booltest($true), $true, "booltest (2)");
15
is(default_args::booltest($false), $false, "booltest (3)");
17
my $ec = new default_args::EnumClass();
18
is($ec->blah(), $true, "EnumClass");
20
is(default_args::casts1(), undef, "casts1");
21
is(default_args::casts2(), "Hello", "casts2");
22
is(default_args::casts1("Ciao"), "Ciao", "casts1 not default");
23
is(default_args::chartest1(), 'x', "chartest1");
24
is(default_args::chartest2(), "\0", "chartest2");
25
is(default_args::chartest1('y'), 'y', "chartest1 not default");
26
is(default_args::reftest1(), 42, "reftest1");
27
is(default_args::reftest1(400), 400, "reftest1 not default");
28
is(default_args::reftest2(), "hello", "reftest2");
70
$foo = new default_args::Foo();
73
$foo->renamed3arg(10, 10.0);
74
$foo->renamed2arg(10);
31
my $foo = new default_args::Foo();
32
can_ok($foo, qw(newname renamed3arg renamed2arg renamed1arg));
36
$foo->renamed3arg(10, 10.0);
37
$foo->renamed2arg(10);
40
ok(not($@), '%rename handling');
77
42
# exception specifications
78
43
eval { default_args::exceptionspec() };
80
die "exceptionspec 1 failed";
44
is($@, "ciao", "exceptionspec 1");
82
45
eval { default_args::exceptionspec(-1) };
84
die "exceptionspec 2 failed";
46
is($@, "ciao", "exceptionspec 2");
86
47
eval { default_args::exceptionspec(100) };
88
die "exceptionspec 3 failed";
91
$ex = new default_args::Except($false);
92
eval { $ex.exspec() };
94
die "exspec 1 failed";
96
eval { $ex.exspec(-1) };
98
die "exspec 2 failed";
100
eval { $ex.exspec(100) };
102
die "exspec 3 failed";
104
eval { $ex = new default_args::Except($true) };
106
die "Except constructor 1 failed";
108
eval { $ex = new default_args::Except($true, -2) };
110
die "Except constructor 2 failed";
48
is($@, '100', "exceptionspec 3");
50
my $ex = new default_args::Except($false);
53
eval { $ex->exspec(); $hit = 1; };
54
# a zero was thrown, an exception occured, but $@ is false
55
is($hit, 0, "exspec 1");
56
eval { $ex->exspec(-1) };
57
is($@, "ciao", "exspec 2");
58
eval { $ex->exspec(100) };
59
is($@, 100, "exspec 3");
60
eval { $ex = default_args::Except->new($true) };
61
is($@, -1, "Except constructor 1");
62
eval { $ex = default_args::Except->new($true, -2) };
63
is($@, -2, "Except constructor 2");
113
65
#Default parameters in static class methods
114
if (default_args::Statics::staticmethod() != 10+20+30) {
115
die "staticmethod 1 failed";
117
if (default_args::Statics::staticmethod(100) != 100+20+30) {
118
die "staticmethod 2 failed";
120
if (default_args::Statics::staticmethod(100,200,300) != 100+200+300) {
121
die "staticmethod 3 failed";
124
$tricky = new default_args::Tricky();
125
if ($tricky->privatedefault() != 200) {
126
die "privatedefault failed";
128
if ($tricky->protectedint() != 2000) {
129
die "protectedint failed";
131
if ($tricky->protecteddouble() != 987.654) {
132
die "protecteddouble failed";
134
if ($tricky->functiondefault() != 500) {
135
die "functiondefault failed";
137
if ($tricky->contrived() ne 'X') {
138
die "contrived failed";
141
if (default_args::constructorcall()->{val} != -1) {
142
die "constructorcall test 1 failed";
145
if (default_args::constructorcall(new default_args::Klass(2222))->{val} != 2222) {
146
die "constructorcall test 2 failed";
149
if (default_args::constructorcall(new default_args::Klass())->{val} != -1) {
150
die "constructorcall test 3 failed";
66
is(default_args::Statics::staticmethod(), 60, "staticmethod 1");
67
is(default_args::Statics::staticmethod(100), 150, "staticmethod 2");
68
is(default_args::Statics::staticmethod(100,200,300), 600, "staticmethod 3");
70
my $tricky = new default_args::Tricky();
71
is($tricky->privatedefault(), 200, "privatedefault");
72
is($tricky->protectedint(), 2000, "protectedint");
73
is($tricky->protecteddouble(), 987.654, "protecteddouble");
74
is($tricky->functiondefault(), 500, "functiondefault");
75
is($tricky->contrived(), 'X', "contrived");
76
is(default_args::constructorcall()->{val}, -1, "constructorcall test 1");
77
is(default_args::constructorcall(new default_args::Klass(2222))->{val},
78
2222, "constructorcall test 2");
79
is(default_args::constructorcall(new default_args::Klass())->{val},
80
-1, "constructorcall test 3");
154
$cm = new default_args::ConstMethods();
155
if ($cm->coo() != 20) {
156
die "coo test 1 failed";
158
if ($cm->coo(1.0) != 20) {
159
die "coo test 2 failed";
83
my $cm = new default_args::ConstMethods();
84
is($cm->coo(), 20, "coo test 1");
85
is($cm->coo(1.0), 20, "coo test 2");