1#! /usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7
8my $alphabet = join '', map { chr } 32 .. 126;
9
10my %tmfa = (
11    null     => [],
12    empty    => [ '' ],
13    alphabet => [ $alphabet ],
14    prefixes => [ qw<foo foobar> ],
15);
16
17my @tests = (
18    [null     => '',            0],
19    [null     => 'foo',         0],
20    [empty    => '',            1],
21    [empty    => 'a',           0],
22    [empty    => 'abc',         0],
23    [empty    => $alphabet,     0],
24    [alphabet => '',            0],
25    [alphabet => $alphabet,     1],
26    [alphabet => " $alphabet",  0, 'left-padded alphabet'],
27    [alphabet => "$alphabet ",  0, 'right-padded alphabet'],
28    [alphabet => " $alphabet ", 0, 'both-padded alphabet'],
29    [prefixes => '',            0],
30    [prefixes => 'f',           0],
31    [prefixes => 'z',           0],
32    [prefixes => 'fo',          0],
33    [prefixes => 'foo',         1],
34    [prefixes => 'foob',        0],
35    [prefixes => 'fooba',       0],
36    [prefixes => 'foobar',      1],
37    [prefixes => 'foobarx',     0],
38);
39
40for my $matcher (keys %tmfa) {
41    push @tests, map { [$matcher => chr($_), 0, "character $_"] }
42        0x00, 0x0A, 0x1F, 0x7F, 0x80, 0xA0, 0xFF, 0x100, 0x200;
43}
44
45plan tests => 1 + @tests;
46
47use_ok('Text::Match::FastAlternatives');
48
49$_ = Text::Match::FastAlternatives->new(@$_) for values %tmfa;
50
51for my $t (@tests) {
52    my ($matcher, $target, $expected, $noun) = @$t;
53    $noun ||= $target eq ''        ? 'empty string'
54            : $target eq $alphabet ? 'alphabet'
55            :                        "'$target'";
56    my $message = $expected ? "$noun exact-matches $matcher"
57                :             "$noun doesn't exact-match $matcher";
58    my $result = $tmfa{$matcher}->exact_match($target);
59    ok(!$result == !$expected, $message);
60}
61