use v6;
use Test;
plan 36;
my %ords = (
1 => 'first',
2 => 'second',
3 => 'third',
4 => 'fourth',
5 => 'fifth',
6 => 'sixth',
7 => 'seventh',
8 => 'eighth',
9 => 'ninth',
);
is split(:input("fiSMBoC => fREW is Station's Most Bodacious Creation"), " ").join(','),
qw/fiSMBoC => fREW is Station's Most Bodacious Creation/.join(','),
q{split(:input(Str), " "};
is split(:input("UNIFICATIONS => Unions Normally Identified From Initial Characters; Aesthetically Tailored to Infer Other Notions Subconsciously"), /\s+/).join(','),
qw/UNIFICATIONS => Unions Normally Identified From Initial Characters; Aesthetically Tailored to Infer Other Notions Subconsciously/.join(','),
q{split(:input(Str), /\s+/};
is split("", "forty-two").join(','),
<f o r t y - t w o>.join(','),
q{split "", Str};
is split(' ', 'split this string').join(','),
<split this string>.join(','),
q{split ' ', Str};
is split('$', 'try$this$string').join(','),
<try this string>.join(','),
q{split '$', Str};
is split(', ', "comma, separated, values").join(','),
<comma separated values>.join(','),
q{split ', ', Str};
my $delimiter = '::';
is split($delimiter, "Perl6::Pugs::Test").join(','),
<Perl6 Pugs Test>.join(','),
q{split $delimiter, Str};
is split(rx:Perl5 {,}, "split,me").join(','),
qw/split me/.join(','),
q/split rx:Perl5 {,}, Str/;
is split(rx:Perl5 {\s+}, "Hello World Goodbye Mars").join(','),
qw/Hello World Goodbye Mars/.join(','),
q/split rx:Perl5 {\s+}, Str/;
is split(rx:Perl5 {(\s+)}, "Hello test", :all).join(','),
('Hello', ("Hello test" ~~ rx:Perl5 {(\s+)}), 'test').join(','),
q/split rx:Perl5 {(\s+)}, Str/;
is "to be || ! to be".split(' ').join(','),
<to be || ! to be>.join(','),
q/Str.split(' ')/;
is "this will be split".split(rx:Perl5 { }).join(','),
<this will be split>.join(','),
q/Str.split(rx:Perl5 { })/;
is split(rx:Perl5 {\s+}, "Hello World Goodbye Mars", 3).join(','),
( <Hello World>, "Goodbye Mars" ).join(','),
q/split rx:Perl5 {\s+}, Str, limit/;
is split(" ", "Hello World Goodbye Mars", 3).join(','),
( <Hello World>, " Goodbye Mars" ).join(','),
q/split " ", Str, limit/;
is "Hello World Goodbye Mars".split(rx:Perl5 {\s+}, 3).join(','),
( <Hello World>, "Goodbye Mars" ).join(','),
q/Str.split(rx:Perl5 {\s+}, limit)/;
is "Hello World Goodbye Mars".split(" ", 3).join(','),
( <Hello World>, " Goodbye Mars" ).join(','),
q/Str.split(" ", limit)/;
is "Word".split("", 3).join(','), <W o rd>.join(','),
q/Str.split("", limit)/;
dies_ok {" abc def ".split()}, q/Str.split() disallowed/;
is "".split('').elems, 0, q/"".split()/;
is "".split(':').elems, 1, q/"".split(':')/;
is "a.b".split(/\./).join(','), <a b>.join(','),
q{"a.b".split(/\./)};
{
is "abcd".split(/<null>/).join(','), <a b c d>.join(','),
q{"abcd".split(/<null>/)};()
}
{
' ' ~~ /(\s)/;
if $0 eq ' ' {
is "foo bar baz".split(/<prior>/).join(','), <foo bar baz>.join(','),
q{"foo bar baz".split(/<prior>/)};
} else {
skip q{' ' ~~ /\s/ did not result in ' '};
}
}
{
is 'hello-world'.split(/<ws>/).join(','), <hello - world>.join(','),
q{'hello-world'.split(/<ws>/)};
is 'hello-world'.split(/<wb>/).join(','), <hello - world>.join(','),
q{'hello-world'.split(/<wb>/)};
}
{
my @a = "hello world".split(/<[aeiou]>/, :all);
is +@a, 7, "split:all resulted in seven pieces";
isa_ok @a[1], Match, "second is a Match object";
isa_ok @a[3], Match, "fourth is a Match object";
isa_ok @a[5], Match, "sixth is a Match object";
is ~@a, ~("h", "e", "ll", "o", " w", "o", "rld"), "The pieces are correct";
}
{
my @a = "hello world".split(/(<[aeiou]>)(.)/, :all);
is +@a, 7, "split:all resulted in seven pieces";
is ~@a, ~("h", "el", "l", "o ", "w", "or", "ld"), "The pieces are correct";
is @a[1][0], "e", "First capture worked";
is @a[1][1], "l", "Second capture worked";
is @a[3][0], "o", "Third capture worked";
is @a[3][1], " ", "Fourth capture worked";
}
done_testing;