<commit_before>use v6;
use Test;

plan 11;

# L<S05/Regexes are now first-class language, not strings>

eval_dies_ok('qr/foo/', 'qr// is gone');

#?rakudo 2 skip 'rx// syntax not implemented'
isa_ok(rx/oo/, Regex);
isa_ok(rx (o), Regex);
eval_dies_ok('rx(o)', 'rx () whitespace if the delims are parens');
#?rakudo todo 'regex {} does not make a Regex object'
isa_ok(regex {oo}, Regex);

eval_dies_ok('rx :foo:', 'colons are not allowed as rx delimiters');

#?rakudo todo 'my $var = /foo/ does not make a Regex object'
{
    my $var = /foo/;
    isa_ok($var, Regex, '$var = /foo/ returns a Regex object');
}

#?rakudo skip 'my $match = m{oo} does not match on $_'
{
    $_ = 'foo';
    my $match = m{oo};
    is($match, 'oo', 'm{} always matches instead of making a Regex object');
}

#?rakudo skip 'my $match = m/oo/ parsefail'
{

    $_ = 'foo';
    my $match = m/oo/;
    is($match, 'oo', 'm{} always matches instead of making a Regex object');
}

# we'll just check that this syntax is valid for now
{
    lives_ok({token foo {bar}}, 'token foo {...} is valid');
    lives_ok({regex baz {qux}}, 'regex foo {...} is valid');
}<commit_msg>[t/spec/S05-metasyntax/regex.t] added tests for regex, token, and rule outside of grammars<commit_after>use v6;
use Test;

plan 14;

# L<S05/Regexes are now first-class language, not strings>

eval_dies_ok('qr/foo/', 'qr// is gone');

#?rakudo 2 skip 'rx// syntax not implemented'
isa_ok(rx/oo/, Regex);
isa_ok(rx (o), Regex);
eval_dies_ok('rx(o)', 'rx () whitespace if the delims are parens');
#?rakudo todo 'regex {} does not make a Regex object'
isa_ok(regex {oo}, Regex);

eval_dies_ok('rx :foo:', 'colons are not allowed as rx delimiters');

#?rakudo todo 'my $var = /foo/ does not make a Regex object'
{
    my $var = /foo/;
    isa_ok($var, Regex, '$var = /foo/ returns a Regex object');
}

#?rakudo skip 'my $match = m{oo} does not match on $_'
{
    $_ = 'foo';
    my $match = m{oo};
    is($match, 'oo', 'm{} always matches instead of making a Regex object');
}

#?rakudo skip 'my $match = m/oo/ parsefail'
{

    $_ = 'foo';
    my $match = m/oo/;
    is($match, 'oo', 'm{} always matches instead of making a Regex object');
}

# we'll just check that this syntax is valid for now
{
    lives_ok({token foo {bar}}, 'token foo {...} is valid');
    lives_ok({regex baz {qux}}, 'regex foo {...} is valid');
}

#?rakudo skip 'rakudo cannot handle named regexes outside of grammars'
{
    regex alien { ET };
    token archaeologist { Indiana };
    rule food { pasta };

    ok( 'ET phone home' ~~ alien, 'named regex outside of a grammar works' );
    ok( 'Indiana has left the fridge' ~~ archaeologist,
                                  'named token outside of a grammar works' );
    ok( 'mmm, pasta' ~~ food,
                                  'named tule outside of a grammar works' );
}
{'fraction_non_alphanumeric': 0.16156282998944033, 'fraction_numerical': 0.004927842309046111, 'mean_word_length': 3.179411764705882, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4973263', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1010, 'n_words': 365}