<commit_before>
use strict;
use warnings;

use lib 'tests/perl_tests/lib';
use JBlibs;

use Test::More;

use Capture::Tiny 'tee';

use File::Copy 'copy';
use File::Copy::Recursive 'dircopy';
use File::Path qw( rmtree );
use File::Temp;

use FileSlurping qw( slurp slurp_tree );

use Bio::JBrowse::Cmd::IndexNames;

sub run_with {
    my @args = @_;
    return tee {
        Bio::JBrowse::Cmd::IndexNames->new( @args )->run;
    };
}

my $tempdir = new_volvox_sandbox();
my $temp2 = File::Temp->newdir( CLEANUP => $ENV{KEEP_ALL} ? 0 : 1 );
my ( $stdout ) = run_with (
    '--out'   => "$tempdir",
    '--workdir' => $temp2,
    '--hashBits' => 16,
    '--completionLimit' => 15
    );
{
    my $got = read_names($tempdir);
    my $expected = read_names('tests/data/volvox_formatted_names');
    is_deeply( $got, $expected, 'got right data from volvox test data run' );
        #or diag explain read_names($tempdir);
#    diag explain $got->{'c12/9.json'}{apple2}{exact};
#    diag explain $expected->{'c12/9.json'}{apple2}{exact};
}

#system "echo TEMPDIR IS $tempdir; cat $tempdir/names/2be/0.json; echo;";

run_with (
    '--out'   => "$tempdir",
    '--workdir' => $temp2,
    '--hashBits' => 16,
    '--incremental',
    '--tracks' => 'ExampleFeatures,NameTest',
    '--completionLimit' => 15
    );
{
    my $got = read_names($tempdir);
    my $expected = read_names('tests/data/volvox_formatted_names');
    is_deeply( $got, $expected, 'same data after incremental run' );# or diag explain read_names($tempdir);
}


run_with(
    '--out'   => "$tempdir",
    '--workdir' => $temp2,
    '--hashBits' => 16,
    '--incremental',
    '--safeMode',
    '--tracks' => 'ExampleFeatures,NameTest',
    '--completionLimit' => 15
    );<commit_msg>Add an incremental test to update a partial name store. Requires Test::Deep to use eq_deeply<commit_after>
use strict;
use warnings;

use lib 'tests/perl_tests/lib';
use JBlibs;

use Test::More;
use Test::Deep;
use Capture::Tiny 'tee';

use File::Copy 'copy';
use File::Copy::Recursive 'dircopy';
use File::Path qw( rmtree );
use File::Temp;

use FileSlurping qw( slurp slurp_tree );

use Bio::JBrowse::Cmd::IndexNames;

sub run_with {
    my @args = @_;
    return tee {
        Bio::JBrowse::Cmd::IndexNames->new( @args )->run;
    };
}

my $tempdir = new_volvox_sandbox();
my $temp2 = File::Temp->newdir( CLEANUP => $ENV{KEEP_ALL} ? 0 : 1 );
my ( $stdout ) = run_with (
    '--out'   => "$tempdir",
    '--workdir' => $temp2,
    '--hashBits' => 16,
    '--completionLimit' => 15
    );
{
    my $got = read_names($tempdir);
    my $expected = read_names('tests/data/volvox_formatted_names');
    is_deeply( $got, $expected, 'got right data from volvox test data run' );
        #or diag explain read_names($tempdir);
#    diag explain $got->{'c12/9.json'}{apple2}{exact};
#    diag explain $expected->{'c12/9.json'}{apple2}{exact};
}

#system "echo TEMPDIR IS $tempdir; cat $tempdir/names/2be/0.json; echo;";
my $tempdir2 = new_volvox_sandbox();

run_with (
    '--out'   => "$tempdir2",
    '--workdir' => $temp2,
    '--hashBits' => 16,
    '--tracks' => 'ExampleFeatures,NameTest',
    '--completionLimit' => 15
    );
{
    my $got = read_names($tempdir2);
    my $expected = read_names('tests/data/volvox_formatted_names');
    ok( !eq_deeply( $got, $expected ), 'expected partial name index to not match full name index' );
}


run_with (
    '--out'   => "$tempdir2",
    '--workdir' => $temp2,
    '--hashBits' => 16,
    '--incremental',
    '--completionLimit' => 15
    );
{
    my $got = read_names($tempdir);
    my $expected = read_names('tests/data/volvox_formatted_names');
    is_deeply( $got, $expected, 'incremental index of the previous partial names index matched' );
}

run_with(
    '--out'   => "$tempdir",
    '--workdir' => $temp2,
    '--hashBits' => 16,
    '--incremental',
    '--safeMode',
    '--tracks' => 'ExampleFeatures,NameTest',
    '--completionLimit' => 15
    );
{'fraction_non_alphanumeric': 0.18906605922551253, 'fraction_numerical': 0.01645153125790939, 'mean_word_length': 3.3765227021040976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6702866', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1470, 'n_words': 332}