1use strict;
2use warnings;
3use Test::More tests => 40;
4BEGIN { use_ok('default_args') }
5require_ok('default_args');
6
7my $true = 1;
8my $false = '';
9
10is(default_args::anonymous(), 7771, "anonymous (1)");
11is(default_args::anonymous(1234), 1234, "anonymous (2)");
12
13is(default_args::booltest(), $true, "booltest (1)");
14is(default_args::booltest($true), $true, "booltest (2)");
15is(default_args::booltest($false), $false, "booltest (3)");
16
17my $ec = new default_args::EnumClass();
18is($ec->blah(), $true, "EnumClass");
19
20is(default_args::casts1(), undef, "casts1");
21is(default_args::casts2(), "Hello", "casts2");
22is(default_args::casts1("Ciao"), "Ciao", "casts1 not default");
23is(default_args::chartest1(), 'x', "chartest1");
24is(default_args::chartest2(), "\0", "chartest2");
25is(default_args::chartest1('y'), 'y', "chartest1 not default");
26is(default_args::reftest1(), 42, "reftest1");
27is(default_args::reftest1(400), 400, "reftest1 not default");
28is(default_args::reftest2(), "hello", "reftest2");
29
30# rename
31my $foo = new default_args::Foo();
32can_ok($foo, qw(newname renamed3arg renamed2arg renamed1arg));
33eval {
34	$foo->newname();
35	$foo->newname(10);
36	$foo->renamed3arg(10, 10.0);
37	$foo->renamed2arg(10);
38	$foo->renamed1arg();
39};
40ok(not($@), '%rename handling');
41
42# exception specifications
43eval { default_args::exceptionspec() };
44like($@, qr/^ciao/, "exceptionspec 1");
45eval { default_args::exceptionspec(-1) };
46like($@, qr/^ciao/, "exceptionspec 2");
47eval { default_args::exceptionspec(100) };
48like($@, qr/^100/, "exceptionspec 3");
49
50my $ex = new default_args::Except($false);
51
52my $hit = 0;
53eval { $ex->exspec(); $hit = 1; };
54# a zero was thrown, an exception occurred, but $@ is false
55is($hit, 0, "exspec 1");
56eval { $ex->exspec(-1) };
57like($@, qr/^ciao/, "exspec 2");
58eval { $ex->exspec(100) };
59like($@, qr/^100/, "exspec 3");
60eval { $ex = default_args::Except->new($true) };
61like($@, qr/-1/, "Except constructor 1");
62eval { $ex = default_args::Except->new($true, -2) };
63like($@, qr/-2/, "Except constructor 2");
64
65#Default parameters in static class methods
66is(default_args::Statics::staticmethod(), 60, "staticmethod 1");
67is(default_args::Statics::staticmethod(100), 150, "staticmethod 2");
68is(default_args::Statics::staticmethod(100,200,300), 600, "staticmethod 3");
69
70my $tricky = new default_args::Tricky();
71is($tricky->privatedefault(), 200, "privatedefault");
72is($tricky->protectedint(), 2000, "protectedint");
73is($tricky->protecteddouble(), 987.654, "protecteddouble");
74is($tricky->functiondefault(), 500, "functiondefault");
75is($tricky->contrived(), 'X', "contrived");
76is(default_args::constructorcall()->{val}, -1, "constructorcall test 1");
77is(default_args::constructorcall(new default_args::Klass(2222))->{val},
78   2222, "constructorcall test 2");
79is(default_args::constructorcall(new default_args::Klass())->{val},
80   -1, "constructorcall test 3");
81
82# const methods
83my $cm = new default_args::ConstMethods();
84is($cm->coo(), 20, "coo test 1");
85is($cm->coo(1.0), 20, "coo test 2");
86