5 use vars qw( $loaded );
10 # Returns either the value returned prefixed with 'OK:',
11 # or the caught exception (string expected)
14 $it = 'OK:' . C4::Boolean::true_p($x);
18 $it =~ s/ at \S+ line \d+$\.\n//s;
27 sub { C4::Boolean::INVALID_BOOLEAN_STRING_EXCEPTION },
28 'The given value does not seem to be interpretable as a Boolean value',
33 '"0"', \&f, 'OK:0', '0'
35 '"false"', \&f, 'OK:0', 'false'
37 '"off"', \&f, 'OK:0', 'off'
39 '"no"', \&f, 'OK:0', 'no'
43 '"1"', \&f, 'OK:1', '1'
45 '"true"', \&f, 'OK:1', 'true'
47 '"on"', \&f, 'OK:1', 'on'
49 '"yes"', \&f, 'OK:1', 'yes'
51 '"YES"', \&f, 'OK:1', 'YES' # verify case insensitivity
55 'undef', \&f, C4::Boolean::INVALID_BOOLEAN_STRING_EXCEPTION, undef
57 '"foo"', \&f, C4::Boolean::INVALID_BOOLEAN_STRING_EXCEPTION, 'foo'
62 BEGIN { $| = 1; printf "1..%d\n", scalar(@tests); }
63 END {print "not ok 1\n" unless $loaded;}
67 # Run all tests in sequence
68 for (my $i = 1; $i <= scalar @tests; $i += 1) {
69 my $test = $tests[$i - 1];
70 my($title, $f, $expected, $input) = @$test;
71 die "not ok $i (malformed test case)\n"
72 unless @$test == 4 && ref $f eq 'CODE';
74 my $output = &$f($input);
76 (!defined $output && !defined $expected)
77 || (defined $output && defined $expected && $output eq $expected)
79 print "ok $i - $title\n";
81 print "not ok $i - $title: got ",
82 (defined $output? "\"$output\"": 'undef'),
84 (defined $expected? "\"$expected\"": 'undef'),