<commit_before>
use v5.14;
use strict;
use warnings;
use Test::More;
use File::Path qw(remove_tree);

use Keeper::Blob;
use Keeper::File;
use Keeper::Storage::File;

my $base = "/tmp/keeper-test";
remove_tree($base);

my $storage = Keeper::Storage::File->new( base => $base );

subtest "Store a blob" => sub {
    my $blob = Keeper::Blob->new( content => "123" );

    my $blob_key = $storage->put($blob);

    my $file = $storage->path_for($blob);
    ok -f $file;

    my $blob2 = $storage->get($blob_key);

    is $blob2->id, $blob->id;
    is $blob2->content, $blob->content;
};

subtest "Store a file" => sub {
    my $file = Keeper::File->new(
        name => "numbers.txt",
        blob => "31337",
    );
    my $file_key = $storage->put( $file );

    ok -f $storage->path_for($file), "the file object itself";
    ok -f $storage->path_for($file->blob), "referenced blob object";

    subtest "retriving the file" => sub {
        my $file2 = $storage->get( $file_key );
        is $file2->id, $file->id, "file id matches";
        is $file2->name, $file->name, "file name matches";
        is $file2->blob->id, $file->blob->id, "referenced blob id matches";
    };
};

done_testing;<commit_msg>test if multilpe identical Blob are mapped to the same file.<commit_after>
use v5.14;
use strict;
use warnings;
use Test::More;
use File::Path qw(remove_tree);

use Keeper::Blob;
use Keeper::File;
use Keeper::Storage::File;

my $base = "/tmp/keeper-test";
remove_tree($base);

my $storage = Keeper::Storage::File->new( base => $base );

subtest "Store a blob" => sub {
    my $blob = Keeper::Blob->new( content => "123" );

    my $blob_key = $storage->put($blob);

    my $file = $storage->path_for($blob);
    ok -f $file;

    my $blob2 = $storage->get($blob_key);
    is $blob2->id, $blob->id;
    is $blob2->content, $blob->content;
};

subtest "Store multiple identical blob" => sub {
    my $blob1 = Keeper::Blob->new( content => "123" );
    my $blob2 = Keeper::Blob->new( content => "123" );

    my $blob1_key = $storage->put($blob1);
    my $blob2_key = $storage->put($blob1);

    is $blob1_key, $blob2_key, "key should be identical";

    my $blob1_file = $storage->path_for($blob1);
    my $blob2_file = $storage->path_for($blob2);

    is $blob1_file, $blob2_file, "file path should be identical";
};

subtest "Store a file" => sub {
    my $file = Keeper::File->new(name => "numbers.txt", blob => "31337");
    my $file_key = $storage->put( $file );

    ok -f $storage->path_for($file), "the file object itself";
    ok -f $storage->path_for($file->blob), "referenced blob object";

    subtest "retriving the file" => sub {
        my $file2 = $storage->get( $file_key );
        is $file2->id, $file->id, "file id matches";
        is $file2->name, $file->name, "file name matches";
        is $file2->blob->id, $file->blob->id, "referenced blob id matches";
    };
};

done_testing;
{'fraction_non_alphanumeric': 0.1882312456985547, 'fraction_numerical': 0.019270474879559532, 'mean_word_length': 3.4045454545454548, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 72, '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': '6840000', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1028, 'n_words': 277}