Acme-TextLayout

 view release on metacpan or  search on metacpan

t/01-test.t  view on Meta::CPAN

ok($tl->instantiate(text => $pattern));

# test fetching a particular line in pattern
ok(check([qw(J h r)], $tl->order(0)));
# test possible direction methods for right answers
ok(check([qw(h)], $tl->right('J')));
ok(check([qw(r)], $tl->right('h')));
ok(check([], $tl->right('A')));
ok(check([qw(C)], $tl->right('B')));
ok(check([], $tl->right('C')));
ok(check([qw(E)], $tl->right('D')));
ok(check([qw(F)], $tl->right('E')));
ok(check([], $tl->right('F')));

ok(check([], $tl->left('J')));
ok(check([], $tl->left('A')));
ok(check([], $tl->left('D')));
ok(check([qw(D)], $tl->left('E')));
ok(check([qw(E)], $tl->left('F')));
ok(check([qw(B)], $tl->left('C')));
ok(check([qw(h)], $tl->left('r')));
ok(check([qw(J)], $tl->left('h')));

ok(check([qw(B C)], $tl->above('E')));
ok(check([qw(C)], $tl->above('F')));
ok(check([qw(B)], $tl->above('D')));
ok(check([qw(A)], $tl->above('B')));
ok(check([qw(A)], $tl->above('C')));
ok(check([], $tl->above('J')));
ok(check([], $tl->above('h')));
ok(check([], $tl->above('r')));
ok(check([qw(A)], $tl->below('J')));
ok(check([qw(A)], $tl->below('h')));
ok(check([qw(A)], $tl->below('r')));
ok(check([qw(B C)], $tl->below('A')));
ok(check([qw(E D)], $tl->below('B')));
ok(check([qw(F E)], $tl->below('C')));
ok(check([], $tl->below('D')));
ok(check([], $tl->below('E')));
ok(check([], $tl->below('F')));

# be sure we get right answers from characters method
my @chars = $tl->characters();
@chars = sort(@chars);
@Characters = sort(@Characters);
ok(check(\@Characters, @chars));
#print STDERR Dumper(\@chars);

$tl = Acme::TextLayout->new;
$pattern = <<'EOF';
JJJhhhhhhhhrr
AAAAAAAAAAArr
BBBCCCCCCCCCC
DDEEEEEEEEEFF
DDEEEEEEEEEFF
EOF
$tl->instantiate(text => $pattern);
ok(check([qw(A h)], $tl->left('r')));

# request a line too big for our pattern
print STDERR "This should report error:\n";
eval q($tl->order(5));
print STDERR $@;
ok($@ ne '');

# test of a non-rectangular pattern
$pattern = <<'EOF';
aaaaaa
bb
EOF
$tl = Acme::TextLayout->new;
ok (!($tl->instantiate(text => $pattern)));

# single char pattern test
$pattern = <<'EOF';
A
EOF
$tl = Acme::TextLayout->new;
ok($tl->instantiate(text => $pattern));
ok($tl->width()==1 && $tl->height()==1);

# bad pattern tests
$pattern = <<'EOF';
ABBA
EOF
ok(!$tl->instantiate(text => $pattern));

$tl = Acme::TextLayout->new;
$pattern = <<'EOF';
BBBA
ABBB
EOF
eval q($tl->instantiate(text => $pattern));
ok($@);

$tl = Acme::TextLayout->new;
$pattern = <<'EOF';
BBBAAA
BBBAAA
CCCCCC
BBBAAA
EOF
ok(!$tl->instantiate(text => $pattern));

# be sure leading whitespace handled
$tl = Acme::TextLayout->new;
$pattern = <<'EOF';
            ABBBB
            ABBBB
            CCCCC
EOF
ok($tl->instantiate(text => $pattern));
ok(!$tl->only_one());

# single character pattern and test only_one method
$tl = Acme::TextLayout->new;
$pattern = <<'EOF';
    A
EOF
ok($tl->instantiate(text => $pattern));
ok($tl->only_one() == 1);



( run in 0.535 second using v1.01-cache-2.11-cpan-2398b32b56e )