File: basic.t

package info (click to toggle)
libtext-brew-perl 0.02-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 80 kB
  • sloc: perl: 135; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 933 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
my @tests;
BEGIN {
	my $test_data = <<'EOT';
foo foo 0 INITIAL,MATCH,MATCH,MATCH
foo bar 3 INITIAL,SUBST,SUBST,SUBST
foo foobar 3 INITIAL,MATCH,MATCH,MATCH,INS,INS,INS
foobar foo 3 INITIAL,MATCH,MATCH,MATCH,DEL,DEL,DEL
abcd bcd 1 INITIAL,DEL,MATCH,MATCH,MATCH
bcd abcd 1 INITIAL,INS,MATCH,MATCH,MATCH
abde abcde 1 INITIAL,MATCH,MATCH,INS,MATCH,MATCH
abcde abde 1 INITIAL,MATCH,MATCH,DEL,MATCH,MATCH
EOT
	for ( split /\n/, $test_data ) {
		next unless /\S/ and !/^\s*\#/;
		my @r = split ' ';
		@r == 4 or die "Invalid DATA line";
		push @tests, {
			arg1 => $r[0],
			arg2 => $r[1],
			distance => $r[2],
			edits => [ split /,/, $r[3] ],
		};
	}
}

use Test::More tests => 2 * @tests;

use Text::Brew qw( distance );

for my $t (@tests) {
	my($distance, $edits) = distance( $t->{arg1}, $t->{arg2} );
	is($distance, $t->{distance}, "$t->{arg1}-$t->{arg2} distance");
	is_deeply($edits, $t->{edits}, "$t->{arg1}-$t->{arg2} edits");
}