<commit_before>#!/usr/bin/env perl
#
# Cheat sheet tester created by <NAME> (https://github.com/dnmfarrell)
# from http://perltricks.com/article/190/2015/8/28/Check-your-DuckDuckGo-cheatsheets-with-Perl
#
use strict;
use warnings;
use open ':std', ':encoding(utf8)';
use Test::More;
use Term::ANSIColor;
use JSON;
use IO::All;
use List::Util qw(first);

my $json_dir = "share/goodie/cheat_sheets/json";
my $json;

sub file_name_to_id {
    my $file_name = shift;
    $file_name =~ s/\.json//;
    $file_name =~ s/-/_/g;
    return $file_name . "_cheat_sheet";
}

sub id_to_file_name {
    my $id = shift;
    $id =~ s/_cheat_sheet//;
    $id =~ s/_/-/g;
    return "$id.json";
}

# Iterate over all Cheat Sheet JSON files...
foreach my $path (glob("$json_dir/*.json")){
    next if $ARGV[0] && $path ne  "$json_dir/$ARGV[0].json";

    my ($file_name) = $path =~ /$json_dir\/(.+)/;
    my ($name) = $path =~ /.+\/(.+)\.json$/;
    my $defaultName = $name =~ s/-/ /gr;
    my @tests;

    ### File tests ###
    my $temp_pass = (my $content < io($path))? 1 : 0;
    push(@tests, {msg => 'file content can be read', critical => 1, pass => $temp_pass});

    $temp_pass = ($json = decode_json($content))? 1 : 0;
    push(@tests, {msg => 'content is valid JSON', critical => 1, pass => $temp_pass});

    ### Code style tests ###
    $temp_pass = not ($content =~ /^ *\t/m);
    push(@tests, {msg => 'tabs detected - use spaces for indenting!', critical => 0, pass => $temp_pass});

    $temp_pass = not ($content =~ /^(?!( {4})*(\S|$))/m);
    push(@tests, {msg => 'indentation not a multiple of 4', critical => 0, pass => $temp_pass});

    $temp_pass = not ($content =~ /[\t ]+$/m);
    push(@tests, {msg => 'trailing whitespace detected', critical => 0, pass => $temp_pass});


    ### Headers tests ###
    $temp_pass = (exists $json->{id} && $json->{id})? 1 : 0;
    push(@tests, {msg => 'has id', critical => 1, pass => $temp_pass});;<commit_msg>Remove code-style tests<commit_after>#!/usr/bin/env perl
#
# Cheat sheet tester created by <NAME> (https://github.com/dnmfarrell)
# from http://perltricks.com/article/190/2015/8/28/Check-your-DuckDuckGo-cheatsheets-with-Perl
#
use strict;
use warnings;
use open ':std', ':encoding(utf8)';
use Test::More;
use Term::ANSIColor;
use JSON;
use IO::All;
use List::Util qw(first);

my $json_dir = "share/goodie/cheat_sheets/json";
my $json;

sub file_name_to_id {
    my $file_name = shift;
    $file_name =~ s/\.json//;
    $file_name =~ s/-/_/g;
    return $file_name . "_cheat_sheet";
}

sub id_to_file_name {
    my $id = shift;
    $id =~ s/_cheat_sheet//;
    $id =~ s/_/-/g;
    return "$id.json";
}

# Iterate over all Cheat Sheet JSON files...
foreach my $path (glob("$json_dir/*.json")){
    next if $ARGV[0] && $path ne  "$json_dir/$ARGV[0].json";

    my ($file_name) = $path =~ /$json_dir\/(.+)/;
    my ($name) = $path =~ /.+\/(.+)\.json$/;
    my $defaultName = $name =~ s/-/ /gr;
    my @tests;

    ### File tests ###
    my $temp_pass = (my $content < io($path))? 1 : 0;
    push(@tests, {msg => 'file content can be read', critical => 1, pass => $temp_pass});

    $temp_pass = ($json = decode_json($content))? 1 : 0;
    push(@tests, {msg => 'content is valid JSON', critical => 1, pass => $temp_pass});

    ### Headers tests ###
    $temp_pass = (exists $json->{id} && $json->{id})? 1 : 0;
    push(@tests, {msg => 'has id', critical => 1, pass => $temp_pass});;
{'fraction_non_alphanumeric': 0.21826670557338781, 'fraction_numerical': 0.014298220017508025, 'mean_word_length': 3.237330037082818, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 36, 'https://': 2, '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': '1056252', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1296, 'n_words': 332}