<commit_before>#! nqp

# sprintf. This file will be moved to t/hll once it handles everything that parrot's sprintf can.

my $die_message := 'unset';

sub dies_ok(&callable, $description) {
    &callable();
    ok(0, $description);
    return '';

    CATCH {
        ok(1, $description);
        $die_message := $_;
    }
}

sub is($actual, $expected, $description) {
    my $they_are_equal := $actual eq $expected;
    ok($they_are_equal, $description);
    unless $they_are_equal {
        say("#   Actual value: $actual");
        say("# Expected value: $expected");
    }
}

plan(265);

is(nqp::sprintf('<NAME>ishop', []), '<NAME>', 'no directives' );

is(nqp::sprintf('Peter %s', ['Bishop']), '<NAME>', 'one %s directive' );
is(nqp::sprintf('%s %s', ['William', 'Bell']), '<NAME>', 'two %s directives' );

dies_ok({ nqp::sprintf('%s %s', ['Dr.', 'William', 'Bell']) }, 'arguments > directives' );
is($die_message, 'Too few directives: found 2, fewer than the 3 arguments after the format string',
    'arguments > directives error message' );

dies_ok({ nqp::sprintf('%s %s %s', ['Olivia', 'Dunham']) }, 'directives > arguments' );
is($die_message, 'Too many directives: found 3, but only 2 arguments after the format string',
    'directives > arguments error message' );

dies_ok({ nqp::sprintf('%s %s', []) }, 'directives > 0 arguments' );
is($die_message, 'Too many directives: found 2, but no arguments after the format string',
    'directives > 0 arguments error message' );

is(nqp::sprintf('%% %% %%', []), '% % %', '%% escape' );
<commit_msg>Adjust error message for directives/arguements mismatch in nqp tests<commit_after>#! nqp

# sprintf. This file will be moved to t/hll once it handles everything that parrot's sprintf can.

my $die_message := 'unset';

sub dies_ok(&callable, $description) {
    &callable();
    ok(0, $description);
    return '';

    CATCH {
        ok(1, $description);
        $die_message := $_;
    }
}

sub is($actual, $expected, $description) {
    my $they_are_equal := $actual eq $expected;
    ok($they_are_equal, $description);
    unless $they_are_equal {
        say("#   Actual value: $actual");
        say("# Expected value: $expected");
    }
}

plan(265);

is(nqp::sprintf('<NAME>', []), '<NAME>', 'no directives' );

is(nqp::sprintf('Peter %s', ['Bishop']), '<NAME>', 'one %s directive' );
is(nqp::sprintf('%s %s', ['William', 'Bell']), '<NAME>', 'two %s directives' );

dies_ok({ nqp::sprintf('%s %s', ['Dr.', 'William', 'Bell']) }, 'arguments > directives' );
is($die_message, 'Directives specify 2 arguments, but 3 arguments were supplied',
    'arguments > directives error message' );

dies_ok({ nqp::sprintf('%s %s %s', ['Olivia', 'Dunham']) }, 'directives > arguments' );
is($die_message, 'Directives specify 3 arguments, but 2 arguments were supplied',
    'directives > arguments error message' );

dies_ok({ nqp::sprintf('%s %s', []) }, 'directives > 0 arguments' );
is($die_message, 'Directives specify 2 arguments, but no argument was supplied',
    'directives > 0 arguments error message' );

is(nqp::sprintf('%% %% %%', []), '% % %', '%% escape' );

{'fraction_non_alphanumeric': 0.19584, 'fraction_numerical': 0.00768, 'mean_word_length': 4.371134020618556, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '5173120', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1030, 'n_words': 300}