<commit_before>use strict;
use warnings;
#~ use diagnostics;

use Test::More;
use Cwd;                # Get current working directory = cwd();
use File::Spec;         # Portable OO methods on filenames
use YAML::XS;           # Perl YAML Serialization using XS and libyaml

use App::Rhea;
my $QRTRUE       = $App::Rhea::QRTRUE    ;
my $QRFALSE      = $App::Rhea::QRFALSE   ;

#----------------------------------------------------------------------------#
# load-yaml.t
#
# Load arbitrary data structure from a file in YAML format.
#
my $unit        = q{App::Rhea::_load_yaml};
my $base        = $unit . q{: };

#~ diag(q{&### This test normally generates warnings. ###&});

#----------------------------------------------------------------------------#
# CONSTANTS
my $fixed_test_dir      = 'rheatmp';
my $working_dir         = cwd();
my $rhea_dir            = '.rhea';
my $yaml_fn             = 'test.yaml';
my $href                = {
    hoge    => 42,
    piyo    => 'foo',
    aref    => [ 'bar', 17 ],
};
my $serialized          = << 'HERE';
hoge: 42
piyo: foo
aref: 
    - bar
    - 17
HERE

#----------------------------------------------------------------------------#
# GLOBALS

#----------------------------------------------------------------------------#
# SETUP
my $prove_dir       = cwd();    # save CWD to restore on teardown

#----------------------------------------------------------------------------#
# CASES

my @td  = (
    
    # Fixed cases leave a mess; so disable in production.
    {
        -case       => 'fixed-setup',
#~         -skip       => 1,
        -code       => qq{
            `rm -rf '$fixed_test_dir' 2>&1`;            # backticks
            App::Rhea::_setup('$fixed_test_dir');
            chdir "$fixed_test_dir";
                    },
        -need       => 1,       # perl okay
    },
    {
        -case       => 'fixed-dump-load',
#~         -skip       => 1,
        -code       => q|
            App::Rhea::init();
            my $filename    = File::Spec->catfile( $rhea_dir, $yaml_fn );
            App::Rhea::_dump_yaml({
                filename    => $filename,
                data        => $href,
            });
            -f $filename or die "Did not write $filename";
            my $restored    = App::Rhea::_load_yaml($filename);
            return $restored;
        |,
        -deep       => $href,
    },
    
    # Temp cases clean up after themselves automatically.
    {
        -case       => 'temp-setup',
        -skip       => 1,
        -code       => q|
            my $dir = App::Rhea::_setup();
            chdir "$dir";
        |,
        -need       => 1,       # perl okay
    },
    {
        -case       => 'temp-dump-href',
        -skip       => 1,
        -code       => q|
            App::Rhea::init();
            my $filename    = File::Spec->catfile( $rhea_dir, $yaml_fn );
            App::Rhea::_dump_yaml({
                filename    => $filename,
                data        => $href,
            });
            -f $filename or die "Did not write $filename";
            open my $fh, '<', $filename or die "Failed open $filename";
            local $/        = undef;            # slurp
            my $data        = <$fh>;
            close $fh or die "Failed close $filename";
            my $restored    = YAML::XS::Load($data);
            return $restored;
        |,
        -deep       => $href,
    },
    
    { -done => 1 }, # # # # # # # # # # # # DONE # # # # # # # # # # # # # # #
    
    
    <commit_msg>Temp cases work too.<commit_after>use strict;
use warnings;
#~ use diagnostics;

use Test::More;
use Cwd;                # Get current working directory = cwd();
use File::Spec;         # Portable OO methods on filenames
use YAML::XS;           # Perl YAML Serialization using XS and libyaml

use App::Rhea;
my $QRTRUE       = $App::Rhea::QRTRUE    ;
my $QRFALSE      = $App::Rhea::QRFALSE   ;

#----------------------------------------------------------------------------#
# load-yaml.t
#
# Load arbitrary data structure from a file in YAML format.
#
my $unit        = q{App::Rhea::_load_yaml};
my $base        = $unit . q{: };

#~ diag(q{&### This test normally generates warnings. ###&});

#----------------------------------------------------------------------------#
# CONSTANTS
my $fixed_test_dir      = 'rheatmp';
my $working_dir         = cwd();
my $rhea_dir            = '.rhea';
my $yaml_fn             = 'test.yaml';
my $href                = {
    hoge    => 42,
    piyo    => 'foo',
    aref    => [ 'bar', 17 ],
};
my $serialized          = << 'HERE';
hoge: 42
piyo: foo
aref: 
    - bar
    - 17
HERE

#----------------------------------------------------------------------------#
# GLOBALS

#----------------------------------------------------------------------------#
# SETUP
my $prove_dir       = cwd();    # save CWD to restore on teardown

#----------------------------------------------------------------------------#
# CASES

my @td  = (
    
    # Fixed cases leave a mess; so disable in production.
    {
        -case       => 'fixed-setup',
        -skip       => 1,
        -code       => qq{
            `rm -rf '$fixed_test_dir' 2>&1`;            # backticks
            App::Rhea::_setup('$fixed_test_dir');
            chdir "$fixed_test_dir";
                    },
        -need       => 1,       # perl okay
    },
    {
        -case       => 'fixed-dump-load',
        -skip       => 1,
        -code       => q|
            App::Rhea::init();
            my $filename    = File::Spec->catfile( $rhea_dir, $yaml_fn );
            App::Rhea::_dump_yaml({
                filename    => $filename,
                data        => $href,
            });
            -f $filename or die "Did not write $filename";
            my $restored    = App::Rhea::_load_yaml($filename);
            return $restored;
        |,
        -deep       => $href,
    },
    
    # Temp cases clean up after themselves automatically.
    {
        -case       => 'temp-setup',
#~         -skip       => 1,
        -code       => q|
            my $dir = App::Rhea::_setup();
            chdir "$dir";
        |,
        -need       => 1,       # perl okay
    },
    {
        -case       => 'temp-dump-load',
#~         -skip       => 1,
        -code       => q|
            App::Rhea::init();
            my $filename    = File::Spec->catfile( $rhea_dir, $yaml_fn );
            App::Rhea::_dump_yaml({
                filename    => $filename,
                data        => $href,
            });
            -f $filename or die "Did not write $filename";
            my $restored    = App::Rhea::_load_yaml($filename);
            return $restored;
        |,
        -deep       => $href,
    },
    
    { -done => 1 }, # # # # # # # # # # # # DONE # # # # # # # # # # # # # # #
    
    
    
{'fraction_non_alphanumeric': 0.24707602339181287, 'fraction_numerical': 0.004970760233918129, 'mean_word_length': 1.0311757719714965, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2097484', 'n_tokens_mistral': 2072, 'n_tokens_neox': 1977, 'n_words': 477}