### ----------------------------------------------------
### -- App::Rak
### -- Licenses: Artistic-2.0
### -- Authors: Elizabeth Mattijsen
### -- File: xt/04-pdf.rakutest
### ----------------------------------------------------
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


