<commit_before>#!/usr/bin/env perl

use strict;
use warnings;

use Test::Most;

# Just so we don't have to type cmp_deeply over and over...
sub t { cmp_deeply(@_) }

subtest initialization => sub {
    { package ListTester; use Moo; with 'DDG::GoodieRole::Parse::List'; 1; }

    new_ok('ListTester', [], 'Applied to a class');
};

subtest parse_list => sub {
    subtest 'varying brackets' => sub {
        my %brackets = (
            '[' => ']',
            '{' => '}',
            '(' => ')',
        );
        while (my ($open, $close) = each %brackets) {
            my $test_list = "${open}1, 2, 3$close";
            my $expected  = [1, 2, 3];
            subtest "brackets: $open$close" => sub {
                t(ListTester::parse_list($test_list), $expected, "parse $test_list");
            };
        }
    };

    subtest 'number of items' => sub {
        my %tcs = (
            0 => '[]',
            1 => '[1]',
            2 => '[1, 2]',
            4 => '[1, 2, 3, 4]',
        );
        while (my ($amount, $tstring) = each %tcs) {
            subtest "$amount items" => sub {
                t(ListTester::parse_list($tstring), arraylength($amount), "parse $tstring");
            };
        }
    };
};

done_testing;

1;<commit_msg>Pull common list-parsing test into sub<commit_after>#!/usr/bin/env perl

use strict;
use warnings;

use Test::Most;

# Just so we don't have to type cmp_deeply over and over...
sub t { cmp_deeply(@_) }

sub parse_test {
    my ($to_parse, $expected) = @_;
    t(ListTester::parse_list($to_parse), $expected, "parse $to_parse");
}

subtest initialization => sub {
    { package ListTester; use Moo; with 'DDG::GoodieRole::Parse::List'; 1; }

    new_ok('ListTester', [], 'Applied to a class');
};

subtest parse_list => sub {
    subtest 'varying brackets' => sub {
        my %brackets = (
            '[' => ']',
            '{' => '}',
            '(' => ')',
        );
        while (my ($open, $close) = each %brackets) {
            my $test_list = "${open}1, 2, 3$close";
            my $expected  = [1, 2, 3];
            subtest "brackets: $open$close" => sub {
                parse_test($test_list, $expected);
            };
        }
    };

    subtest 'number of items' => sub {
        my %tcs = (
            0 => '[]',
            1 => '[1]',
            2 => '[1, 2]',
            4 => '[1, 2, 3, 4]',
        );
        while (my ($amount, $tstring) = each %tcs) {
            subtest "$amount items" => sub {
                parse_test($tstring, arraylength($amount));
            };
        }
    };
};

done_testing;

1;
{'fraction_non_alphanumeric': 0.18108419838523646, 'fraction_numerical': 0.014609765474817378, 'mean_word_length': 1.8313384113166484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '7522730', 'n_tokens_mistral': 910, 'n_tokens_neox': 865, 'n_words': 217}