Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
substr fossil, this is done via substr-rw now
  • Loading branch information
coke committed Aug 4, 2014
1 parent 516a6dc commit 012b339
Showing 1 changed file with 1 addition and 77 deletions.
78 changes: 1 addition & 77 deletions S32-str/substr.t
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 88;
plan 69;

# L<S32::Str/Str/=item substr>

Expand Down Expand Up @@ -68,21 +68,6 @@ sub l (Int $a) { my $l = $a; return $l }
is($str, "foobar", "original string still not changed (substr(Int, StrLen)).");
};

#?rakudo skip 'too many args'
{ # replacement
my $str = "foobar";

substr($str, 2, l(1), "i");
is($str, "foibar", "fourth arg to substr replaced part (substr(Int, StrLen)).");

substr($str, *-1, l(1), "blah");
is($str, "foibablah", "longer replacement expands string (substr(Int, StrLen)).");

substr($str, 1, l(3), "");
is($str, "fablah", "shorter replacement shrunk it (substr(Int, StrLen)).");
};


{ # misc
my $str = "hello foo and bar";

Expand Down Expand Up @@ -133,67 +118,6 @@ sub p (Int $a) { my $p = $a; return $p }
is($str, "fablah", "shorter replacement shrunk it (substr(Int, StrPos)).");
};

# as lvalue, XXX: not sure this should work, as that'd be action at distance:
# my $substr = \substr($str, ...);
# ...;
# some_func $substr; # manipulates $substr
# # $str altered!
# But one could think that's the wanted behaviour, so I leave the test in.
#?rakudo skip 'StrPos NYI'
#?niecza skip 'StrPos tests broken'
{
my $str = "gorch ding";

substr($str, 0, p(5)) = "gloop";
is($str, "gloop ding", "lvalue assignment modified original string (substr(Int, StrPos)).");

my $r = \substr($str, 0, p(5));
ok(WHAT($r).gist, '$r is a reference (substr(Int, StrPos)).');
is($$r, "gloop", '$r referent is eq to the substring (substr(Int, StrPos)).');

$$r = "boing";
is($str, "boing ding", "assignment to reference modifies original (substr(Int, StrPos)).");
is($$r, "boing", '$r is consistent (substr(Int, StrPos)).');

my $o = \substr($str, 3, p(2));
is($$o, "ng", "other ref to other lvalue (substr(Int, StrPos)).");
$$r = "foo";
is($str, "foo ding", "lvalue ref size varies but still works (substr(Int, StrPos)).");
is($$o, " d", "other lvalue wiggled around (substr(Int, StrPos)).");

};

#?rakudo skip 'lvalue substr'
#?niecza skip 'StrPos tests broken'
{ # as lvalue, should work
my $str = "gorch ding";

substr($str, 0, p(5)) = "gloop";
is($str, "gloop ding", "lvalue assignment modified original string (substr(Int, StrPos)).");
};

#?rakudo skip 'StrPos NYI'
#?niecza skip 'StrPos tests broken'
{ # as lvalue, using :=, should work
my $str = "gorch ding";

substr($str, 0, p(5)) = "gloop";
is($str, "gloop ding", "lvalue assignment modified original string (substr(Int, StrPos)).");

my $r := substr($str, 0, p(5));
is($r, "gloop", 'bound $r is eq to the substring (substr(Int, StrPos)).');

$r = "boing";
is($str, "boing ding", "assignment to bound var modifies original (substr(Int, StrPos)).");
is($r, "boing", 'bound $r is consistent (substr(Int, StrPos)).');

my $o := substr($str, 3, p(2));
is($o, "ng", "other bound var to other lvalue (substr(Int, StrPos)).");
$r = "foo";
is($str, "foo ding", "lvalue ref size varies but still works (substr(Int, StrPos)).");
is($o, " d", "other lvalue wiggled around (substr(Int, StrPos)).");
};

{ # misc
my $str = "hello foo and bar";
is(substr($str, 6, p(3)), "foo", "substr (substr(Int, StrPos)).");
Expand Down

0 comments on commit 012b339

Please sign in to comment.