/
04_nodat.t
30 lines (24 loc) · 896 Bytes
/
04_nodat.t
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
use Test;
plan *;
use Text::Fortune;
let $*CWD = 't/test_data';
my Buf $b = do { my $f = 'with_dat.dat'.IO; my $s = $f.s; $f.open(:bin).read($s); };
my Buf $be = do { my $f = 'empty.dat'.IO; my $s = $f.s; $f.open(:bin).read($s); };
given Text::Fortune::Index.new.load-fortune( 'with_dat' ) {
is .offset-at(0), 0, 'first offset correct';
is .offset-at(2), 9, 'last offset correct';
is .offset-at(3), 17, 'final offset correct';
is .bytelength-of(0), 2, 'first length correct';
is .bytelength-of(2), 6, 'last length correct';
throws-like { .bytelength-of(3) },
X::Index::OutOfBounds;
is .Buf, $b, 'serializes correctly';
}
given Text::Fortune::Index.new.load-fortune( 'empty' ) {
is .offset-at(0), 0, 'first/last/final offset correct';
throws-like { .bytelength-of(0) },
X::Index::OutOfBounds;
is .Buf, $be, 'serializes correctly';
}
done-testing;
# vim: ft=perl6