<commit_before>
package XMLMappingTests;

BEGIN { *$_ = \&{"main::$_"} for qw(ok diag) }

use Scriptalicious;
use File::Find;
use FindBin qw($Bin $Script);
use strict;
use YAML qw(LoadFile Load Dump);
use XML::LibXML;
use Test::XML::Assert;

our $grep;
getopt_lenient( "test-grep|t=s" => \$grep );

# get an XML parser
my $parser = XML::LibXML->new();
my $xmlns = {
    epp => 'urn:ietf:params:xml:ns:epp-1.0',
    domain => 'urn:ietf:params:xml:ns:domain-1.0',
    host => 'urn:ietf:params:xml:ns:host-1.0',
    contact => 'urn:ietf:params:xml:ns:contact-1.0',
};

sub find_tests {
	my $group = shift || ($Script=~/(.*)\.t$/)[0];

	my @tests;
	find(sub {
		     if ( m{\.(?:x|ya)ml$} && (!$grep||m{$grep}) ) {
			     my $name = $File::Find::name;
			     $name =~ s{^\Q$Bin\E/}{} or die;
			     push @tests, $name;
		     }
	     }, "$Bin/$group");
	@tests;
}

sub read_xml {
	my $test = shift;
	open XML, "<$Bin/$test";
	binmode XML, ":utf8";
	my $xml = do {
		local($/);
		<XML>;
	};
	close XML;
	$xml;
}

sub read_yaml {
	my $test = shift;
	LoadFile "$Bin/$test";
}

sub run_testset {
    my ($xml, $testset) = @_;

    # firstly, make an XML document with the input $xml
    my $doc = $parser->parse_string( $xml )->documentElement();

    # if we have some count tests, run those first
    if ( defined $testset->{count} ) {
        for my $t ( @{$testset->{count}} ) {
            # print Dumper($t);
            # print "Doing test $t->[2]\n";
            is_xpath_count( $doc, $xmlns, $t->[0], $t->[1], $t->[2] );
            # print "Done\n";
        }
    }

    # if we some matches
    if ( defined $testset->{match} ) {
        for my $t ( @{$testset->{match}} ) {
            does_xpath_value_match( $doc, $xmlns, $t->[0], $t->[1], $t->[2] );
        }
    }

    # if we some matche_all
    if ( defined $testset->{match_all} ) {
        for my $t ( @{$testset->{match_all}} ) {
            do_xpath_values_match( $doc, $xmlns, $t->[0], $t->[1], $t->[2] );
        }
    }
}

1;<commit_msg>Fix some comments<commit_after>
package XMLMappingTests;

BEGIN { *$_ = \&{"main::$_"} for qw(ok diag) }

use Scriptalicious;
use File::Find;
use FindBin qw($Bin $Script);
use strict;
use YAML qw(LoadFile Load Dump);
use XML::LibXML;
use Test::XML::Assert;

our $grep;
getopt_lenient( "test-grep|t=s" => \$grep );

# get an XML parser
my $parser = XML::LibXML->new();
my $xmlns = {
    epp => 'urn:ietf:params:xml:ns:epp-1.0',
    domain => 'urn:ietf:params:xml:ns:domain-1.0',
    host => 'urn:ietf:params:xml:ns:host-1.0',
    contact => 'urn:ietf:params:xml:ns:contact-1.0',
};

sub find_tests {
	my $group = shift || ($Script=~/(.*)\.t$/)[0];

	my @tests;
	find(sub {
		     if ( m{\.(?:x|ya)ml$} && (!$grep||m{$grep}) ) {
			     my $name = $File::Find::name;
			     $name =~ s{^\Q$Bin\E/}{} or die;
			     push @tests, $name;
		     }
	     }, "$Bin/$group");
	@tests;
}

sub read_xml {
	my $test = shift;
	open XML, "<$Bin/$test";
	binmode XML, ":utf8";
	my $xml = do {
		local($/);
		<XML>;
	};
	close XML;
	$xml;
}

sub read_yaml {
	my $test = shift;
	LoadFile "$Bin/$test";
}

sub run_testset {
    my ($xml, $testset) = @_;

    # firstly, make an XML document with the input $xml
    my $doc = $parser->parse_string( $xml )->documentElement();

    # if we have some count tests, run those first
    if ( defined $testset->{count} ) {
        for my $t ( @{$testset->{count}} ) {
            # print Dumper($t);
            # print "Doing test $t->[2]\n";
            is_xpath_count( $doc, $xmlns, $t->[0], $t->[1], $t->[2] );
            # print "Done\n";
        }
    }

    # if we have some matches
    if ( defined $testset->{match} ) {
        for my $t ( @{$testset->{match}} ) {
            does_xpath_value_match( $doc, $xmlns, $t->[0], $t->[1], $t->[2] );
        }
    }

    # if we have some match_all
    if ( defined $testset->{match_all} ) {
        for my $t ( @{$testset->{match_all}} ) {
            do_xpath_values_match( $doc, $xmlns, $t->[0], $t->[1], $t->[2] );
        }
    }
}

1;
{'fraction_non_alphanumeric': 0.21841648051625714, 'fraction_numerical': 0.010424422933730455, 'mean_word_length': 2.5632183908045976, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 28}, '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': '2057383', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1624, 'n_words': 369}