Acme-EyeDrops
view release on metacpan or search on metacpan
#!/usr/bin/perl
# 07_a.t (was border.t). Test Border stuff.
use strict;
use Acme::EyeDrops qw(sightly get_eye_string);
select(STDERR);$|=1;select(STDOUT);$|=1; # autoflush
# --------------------------------------------------
sub build_file {
my ($f, $d) = @_;
local *F; open(F, '>'.$f) or die "open '$f': $!";
print F $d or die "write '$f': $!"; close(F);
}
# --------------------------------------------------
print "1..16\n";
my $hellostr = <<'HELLO';
print "hello world\n";
HELLO
my $camelstr = get_eye_string('camel');
my $camel2str = $camelstr . "\n\n\n" . $camelstr;
my $tmpf = 'bill.tmp';
# Test bailing out via InformHandler when presented with a
# diabolical shape which sends sightly() into an infinite loop.
my $max_shapes = 5;
my $exp_throw_str = "bailing out after " . ($max_shapes+1) . " shapes.\n";
sub throw_inform {
$_[0] =~ /^(\d+) / or die "oops, invalid ihandler string";
$1 > $max_shapes and die "bailing out after $1 shapes.\n";
}
# Simple test of InformHandler.
my $inform_string;
sub test_inform { $inform_string .= $_[0] }
# -------------------------------------------------
my $itest = 0;
my $prog;
# -------------------------------------------------
eval {
sightly( { ShapeString => "#\n#\n#\n#\n#\n",
SourceString => "# Example nasty shape\n;1;\n",
InformHandler => \&throw_inform,
Regex => 1 } );
};
$@ or print "not ";
++$itest; print "ok $itest - InformHandler throw\n";
$@ eq $exp_throw_str or print "not ";
++$itest; print "ok $itest - InformHandler throw string\n";
# -------------------------------------------------
$prog = sightly({ Shape => 'camel',
SourceString => $hellostr,
BorderWidth => 2,
BorderGap => 1,
InformHandler => \&test_inform,
Regex => 1 } );
build_file($tmpf, $prog);
( run in 0.850 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )