3 # test that config ( trap_nan => 1, trap_inf => 1) really works/dies
12 unshift @INC, '../lib'; # for running manually
19 my $mbi = 'Math::BigInt'; my $mbf = 'Math::BigFloat';
22 foreach my $class ($mbi, $mbf)
24 # can do and defaults are okay?
25 ok ($class->can('config'), 'can config()');
26 is ($class->config()->{trap_nan}, 0, 'trap_nan defaults to 0');
27 is ($class->config()->{trap_inf}, 0, 'trap_inf defaults to 0');
30 $cfg = $class->config( trap_nan => 1 );
31 is ($cfg->{trap_nan},1, 'trap_nan now true');
33 # also test that new() still works normally
34 eval ("\$x = \$class->new('42'); \$x->bnan();");
35 like ($@, qr/^Tried to set/, 'died');
36 is ($x,42,'$x after new() never modified');
39 $cfg = $class->config( trap_nan => 0 );
40 is ($cfg->{trap_nan}, 0, 'trap_nan disabled');
43 $cfg = $class->config( trap_inf => 1 );
44 is ($cfg->{trap_inf}, 1, 'trap_inf enabled');
46 eval ("\$x = \$class->new('4711'); \$x->binf();");
47 like ($@, qr/^Tried to set/, 'died');
48 is ($x,4711,'$x after new() never modified');
50 eval ("\$x = \$class->new('inf');");
51 like ($@, qr/^Tried to set/, 'died');
52 is ($x,4711,'$x after new() never modified');
54 eval ("\$x = \$class->new('-inf');");
55 like ($@, qr/^Tried to set/, 'died');
56 is ($x,4711,'$x after new() never modified');
59 eval ("\$x = \$class->new('4711'); \$x->bdiv(0);");
60 like ($@, qr/^Tried to set/, 'died');
61 is ($x,4711,'$x after new() never modified');
64 eval ("\$x = \$class->new('-0815'); \$x->bdiv(0);");
65 like ($@, qr/^Tried to set/, 'died');
66 is ($x,'-815', '$x after new not modified');
68 $cfg = $class->config( trap_nan => 1 );
70 eval ("\$x = \$class->new('0'); \$x->bdiv(0);");
71 like ($@, qr/^Tried to set/, 'died');
72 is ($x,'0', '$x after new not modified');
75 ##############################################################################
78 $x = Math::BigInt->new(2);
79 eval ("\$x = \$mbi->new('0.1');");
80 is ($x,2,'never modified since it dies');
81 eval ("\$x = \$mbi->new('0a.1');");
82 is ($x,2,'never modified since it dies');
84 ##############################################################################
87 $x = Math::BigFloat->new(2);
88 eval ("\$x = \$mbf->new('0.1a');");
89 is ($x,2,'never modified since it dies');