5 #use warnings; FIXME - Bug 2505
9 use vars qw( $loaded );
14 # Returns either the value returned prefixed with 'OK:',
15 # or the caught exception (string expected)
18 $it = 'OK:' . C4::Boolean::true_p($x);
22 $it =~ s/ at \S+ line \d+\.\n//s;
31 sub { C4::Boolean::INVALID_BOOLEAN_STRING_EXCEPTION },
32 'The given value does not seem to be interpretable as a Boolean value',
37 '"0"', \&f, 'OK:0', '0'
39 '"false"', \&f, 'OK:0', 'false'
41 '"off"', \&f, 'OK:0', 'off'
43 '"no"', \&f, 'OK:0', 'no'
47 '"1"', \&f, 'OK:1', '1'
49 '"true"', \&f, 'OK:1', 'true'
51 '"on"', \&f, 'OK:1', 'on'
53 '"yes"', \&f, 'OK:1', 'yes'
55 '"YES"', \&f, 'OK:1', 'YES' # verify case insensitivity
59 'undef', \&f, 'OK:', undef
61 '"foo"', \&f, 'OK:', 'foo'
66 BEGIN { $| = 1; printf "1..%d\n", scalar(@tests); }
67 END {print "not ok 1\n" unless $loaded;}
71 # Run all tests in sequence
72 for (my $i = 1; $i <= scalar @tests; $i += 1) {
73 my $test = $tests[$i - 1];
74 my($title, $f, $expected, $input) = @$test;
75 die "not ok $i (malformed test case)\n"
76 unless @$test == 4 && ref $f eq 'CODE';
78 my $output = &$f($input);
80 (!defined $output && !defined $expected)
81 || (defined $output && defined $expected && $output eq $expected)
83 print "ok $i - $title\n";
85 print "not ok $i - $title: got ",
86 (defined $output? "\"$output\"": 'undef'),
88 (defined $expected? "\"$expected\"": 'undef'),