<commit_before>use v6;
use Test;

# L<S32::Str/Str/"=item split">
plan *;

=begin description

The tests in split.t are rather inaccessible for new implementations, so
here is a start from scratch that should be easier to run.

=end description

#?DOES 2
sub split_test(@splitted, @expected, $desc) {
    say "jj";
    ok @splitted.elems ==  @expected.elems,
       "split created the correct number of elements for: $desc";
    say "jk";
    is @splitted.join('|-|'), @expected.join('|-|'),
       "values matched for: $desc";
    say "hj";
}

is 'a1b24f'.split(/\d+/).elems, 3, 'Str.split(/regex/)';
is 'a1b24f'.split(/\d+/).Str, "a b f", 'Str.split(/regex/)';

# split_test split(/\d+/, 'a1b24f'), <a b f>, 'split(/regex/, Str)';
# split_test 'a1b'.split(1),         <a b>,   'Str.split(Any) (with Str semantics';
is 'theXXbigXXbang'.split('XX').elems, 3, 'Str.split(Str)';
is 'theXXbigXXbang'.split('XX').Str, 'the big bang', 'Str.split(Str)';

is 'a1b24f'.split(/\d+/, *).elems, 3, 'Str.split(/regex/) (with * limit)';
is 'a1b24f'.split(/\d+/, *).Str, "a b f", 'Str.split(/regex/) (with * limit)';
# split_test split(/\d+/, 'a1b24f', *), <a b f>, 'split(/regex/, Str) (with * limit)';
# split_test 'a1b'.split(1, *),         <a b>,   'Str.split(Any) (with Str semantics (with * limit)';
is 'theXXbigXXbang'.split('XX', *).elems, 3, 'Str.split(Str) (with * limit)';
is 'theXXbigXXbang'.split('XX', *).Str, 'the big bang', 'Str.split(Str) (with * limit)';

# {
#     split_test 123.split(2),           <1 3>,   'Int.split(Int)';
#     split_test split(2, 123),          <1 3>,   'split(Int, Int)';
# }

is '1234'.split(/X/).elems, 1,  'Non-matching regex returns whole string';
is '1234'.split(/X/).Str, "1234",  'Non-matching regex returns whole string';
is '1234'.split('X').elems, 1,  'Non-matching string returns whole string';
is '1234'.split('X').Str, "1234",  'Non-matching string returns whole string';
is 'abcb'.split(/b/).elems, 3, 'trailing matches leave an empty string';
is 'abcb'.split(/b/).Str, "a c ", 'trailing matches leave an empty string';

# # Limit tests
# #?DOES 4
# {
# split_test 'theXbigXbang'.split(/X/, -1), (), 'Negative limit returns empty List';
# split_test @('theXbigXbang'.split(/X/, 0)),  (), 'Zero limit returns empty List';
# }
# split_test 'ab1cd12ef'.split(/\d+/, 1), @(<ab1cd12ef>), 'Limit of 1 returns a 1 element List (with identical string)';
# split_test '102030405'.split(0, 3),  <1 2 30405>, 'Split on an Integer with limit parameter works';
# split_test(
#     '<tag>soup</tag>'.split(/\<\/?.*?\>/, 3),
#     ('','soup',''),<commit_msg>[t/spec] Skip two tests which quite inexplicably fail.  Start adding limit tests back in.<commit_after>use v6;
use Test;

# L<S32::Str/Str/"=item split">
plan *;

=begin description

The tests in split.t are rather inaccessible for new implementations, so
here is a start from scratch that should be easier to run.

=end description

#?DOES 2
sub split_test(@splitted, @expected, $desc) {
    say "jj";
    ok @splitted.elems ==  @expected.elems,
       "split created the correct number of elements for: $desc";
    say "jk";
    is @splitted.join('|-|'), @expected.join('|-|'),
       "values matched for: $desc";
    say "hj";
}

is 'a1b24f'.split(/\d+/).elems, 3, 'Str.split(/regex/)';
is 'a1b24f'.split(/\d+/).Str, "a b f", 'Str.split(/regex/)';

# split_test split(/\d+/, 'a1b24f'), <a b f>, 'split(/regex/, Str)';
# split_test 'a1b'.split(1),         <a b>,   'Str.split(Any) (with Str semantics';
is 'theXXbigXXbang'.split('XX').elems, 3, 'Str.split(Str)';
is 'theXXbigXXbang'.split('XX').Str, 'the big bang', 'Str.split(Str)';

is 'a1b24f'.split(/\d+/, *).elems, 3, 'Str.split(/regex/) (with * limit)';
is 'a1b24f'.split(/\d+/, *).Str, "a b f", 'Str.split(/regex/) (with * limit)';
# split_test split(/\d+/, 'a1b24f', *), <a b f>, 'split(/regex/, Str) (with * limit)';
# split_test 'a1b'.split(1, *),         <a b>,   'Str.split(Any) (with Str semantics (with * limit)';
is 'theXXbigXXbang'.split('XX', *).elems, 3, 'Str.split(Str) (with * limit)';
#?rakudo skip "Blows up for inexplicable reasons"
is 'theXXbigXXbang'.split('XX', *).Str, 'the big bang', 'Str.split(Str) (with * limit)';

# {
#     split_test 123.split(2),           <1 3>,   'Int.split(Int)';
#     split_test split(2, 123),          <1 3>,   'split(Int, Int)';
# }

is '1234'.split(/X/).elems, 1,  'Non-matching regex returns whole string';
is '1234'.split(/X/).Str, "1234",  'Non-matching regex returns whole string';
is '1234'.split('X').elems, 1,  'Non-matching string returns whole string';
is '1234'.split('X').Str, "1234",  'Non-matching string returns whole string';
#?rakudo skip "Blows up for inexplicable reasons"
is 'abcb'.split(/b/).elems, 3, 'trailing matches leave an empty string';
is 'abcb'.split(/b/).Str, "a c ", 'trailing matches leave an empty string';

# Limit tests
is 'theXbigXbang'.split(/X/, -1).elems, 0, 'Negative limit returns empty List';
is 'theXbigXbang'.split(/X/, 0).elems, 0, 'Zero limit returns empty List';

is 'ab1cd12ef'.split(/\d+/, 1).elems, 1, 'Limit of 1 returns a 1 element List (with identical string)';
is 'ab1cd12ef'.split(/\d+/, 1)[0], 'ab1cd12ef', 'Limit of 1 returns a 1 element List (with identical string)';
# split_test '102030405'.split(0, 3),  <1 2 30405>, 'Split on an Integer with limit parameter works';
# split_test(
#     '<tag>soup</tag>'.split(/\<\/?.*?\>/, 3),
#     ('','soup',''),
{'fraction_non_alphanumeric': 0.21708579881656806, 'fraction_numerical': 0.038646449704142015, 'mean_word_length': 3.8685868586858687, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, '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': '775771', 'n_tokens_mistral': 2215, 'n_tokens_neox': 2043, 'n_words': 579}