PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/perl5/default_args_runme.pl

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