use Test;

=begin pod

Parts of this file were originally derived from the Perl CPAN module
Perl6::Rules, version 0.3 (12 Apr 2004), file t/word.t.

=end pod

plan 19;

ok(!( "abc  def" ~~ m/abc  def/ ), 'Literal space nonmatch' );
ok(   "abcdef"   ~~ m/abc  def/, 'Nonspace match' );
ok(   "abc  def" ~~ m:s/abc  def/, 'Word space match' );
ok(   'abc  def' ~~ ms/abc def/, 'word space match with ms//');
ok(   "abc\ndef" ~~ m:sigspace/abc  def/, 'Word newline match' );
ok(!( "abcdef"   ~~ m:sigspace/abc  def/ ), 'Word nonspace nonmatch' );
ok(   "abc  def" ~~ m:sigspace/abc <.ws> def/, 'Word explicit space match');

ok 'abc def'     ~~ m/:s abc def/,  'inline :s (+)';
ok 'zabc def'   ~~  m/:s'abc' def/, "inline :s (+)";
ok 'zabc def'   ~~ m/:s abc def/,   "inline :s doesn't imply <.ws> immediately (-)";

ok 'zabc def  '   ~~ m/:s abc def  /,   "inline :s (sigspace)'s trailing whitespace is significant";
nok 'zabc defmef'   ~~ m/:s abc def  /,   "inline :s (sigspace)'s trailing whitespace is significant (2)";
is '  a'          ~~ m:s/       a/, 'a', "m:s/  / starting whitespace between delimiters is not significant.";

# L<S05/Modifiers/The :s modifier is considered sufficiently important>

ok 'abc def' ~~ ms/c d/, 'ms// works, implies :s (+)';
ok 'abcdef' !~~ ms/c d/, 'ms// works, implies :s (-)';

# https://github.com/Raku/old-issue-tracker/issues/3195
# https://github.com/Raku/old-issue-tracker/issues/2640
{
    role Foo { rule foo { foo } }
    grammar Spacey does Foo {
        rule TOP { ^ <foo> }
    }
    grammar NonSpacey does Foo {
        rule TOP { ^<foo> }
    }
    ok ?Spacey.parse\  (" foo"), "Semantics of sigspace after ^";
    ok !NonSpacey.parse(" foo"), "Semantics of sigspace after ^";
    ok ?Spacey.parse\  ("foo"),  "Semantics of sigspace after ^";
    ok ?NonSpacey.parse("foo"),  "Semantics of sigspace after ^";
}

# vim: expandtab shiftwidth=4
