8 use vars qw( $loaded );
13 # Returns either the value returned prefixed with 'OK:',
14 # or the caught exception (string expected)
17 $it = 'OK:' . C4::Boolean::true_p($x);
21 $it =~ s/ at \S+ line \d+$\.\n//s;
30 sub { C4::Boolean::INVALID_BOOLEAN_STRING_EXCEPTION },
31 'The given value does not seem to be interpretable as a Boolean value',
36 '"0"', \&f, 'OK:0', '0'
38 '"false"', \&f, 'OK:0', 'false'
40 '"off"', \&f, 'OK:0', 'off'
42 '"no"', \&f, 'OK:0', 'no'
46 '"1"', \&f, 'OK:1', '1'
48 '"true"', \&f, 'OK:1', 'true'
50 '"on"', \&f, 'OK:1', 'on'
52 '"yes"', \&f, 'OK:1', 'yes'
54 '"YES"', \&f, 'OK:1', 'YES' # verify case insensitivity
58 'undef', \&f, C4::Boolean::INVALID_BOOLEAN_STRING_EXCEPTION, undef
60 '"foo"', \&f, C4::Boolean::INVALID_BOOLEAN_STRING_EXCEPTION, 'foo'
65 BEGIN { $| = 1; printf "1..%d\n", scalar(@tests); }
66 END {print "not ok 1\n" unless $loaded;}
70 # Run all tests in sequence
71 for (my $i = 1; $i <= scalar @tests; $i += 1) {
72 my $test = $tests[$i - 1];
73 my($title, $f, $expected, $input) = @$test;
74 die "not ok $i (malformed test case)\n"
75 unless @$test == 4 && ref $f eq 'CODE';
77 my $output = &$f($input);
79 (!defined $output && !defined $expected)
80 || (defined $output && defined $expected && $output eq $expected)
82 print "ok $i - $title\n";
84 print "not ok $i - $title: got ",
85 (defined $output? "\"$output\"": 'undef'),
87 (defined $expected? "\"$expected\"": 'undef'),