Skip to content

Commit

Permalink
Add basic PDF file tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed May 8, 2024
1 parent 3814b21 commit 2803820
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Binary file added pdf/basic.pdf
Binary file not shown.
58 changes: 58 additions & 0 deletions xt/04-pdf.rakutest
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
BEGIN %*ENV<RAKU_TEST_DIE_ON_FAIL> = 1;
use Test;

plan 6;

my $dir = $*PROGRAM.parent;
my $dira = $dir.absolute ~ $*SPEC.dir-sep;
my $rel := $dir.relative ~ $*SPEC.dir-sep;
my $dot = $?FILE.IO.parent.parent;
my $rak := $dot.add("bin").add("rak").relative;

# using paths from here on out
$dot .= relative;
$dir .= absolute;

my sub query-ok(
*@query, # the actual parameters
:$ok is copy, # the expected result
:$head = 1, # whether to do the --only-first test with this number
:$add-human = True, # add human specification
) is test-assertion {
my @args = $*EXECUTABLE.absolute, "-I$dot", $rak, @query.Slip;
@args.push: "--human" if $add-human;
$ok .= chomp;

# Logic to run the query
my sub run-query() {
my $proc := run @args, :out, :err;
my $key = "huh?";

is $proc.err.slurp(:close), "", "is '@query[]' STDERR clean?";
$proc.out.lines.map(*.subst($rel, :g)).join("\n")
}

# Base query
is run-query, $ok, "is '@query[]' result ok?";
}

query-ok '--pdf-info', Q/*.<Author>/, 'pdf', ok => qq:to/OK/;
pdf/basic.pdf
Philip Hutchison
OK

query-ok <--pdf-per-line varius pdf --/highlight>, ok => qq:to/OK/;
pdf/basic.pdf
8:erat dolor, blandit in, rutrum quis, semper pulvinar, enim. Nullam varius congue risus.
24:varius. Donec lacinia, neque a luctus aliquet, pede massa imperdiet ante, at varius lorem
33:penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus varius. Ut sit
34:amet diam suscipit mauris ornare aliquam. Sed varius. Duis arcu. Etiam tristique massa
OK

query-ok <--pdf-per-file /eget.pharetra/ pdf --matches-only>, ok => qq:to/OK/;
pdf/basic.pdf
eget
pharetra
OK

# vim: expandtab shiftwidth=4

0 comments on commit 2803820

Please sign in to comment.