Skip to content

Commit

Permalink
some doc updates and some more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
burner committed Oct 20, 2014
1 parent 6284361 commit 35193c6
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions std/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,13 @@ if (isDynamicArray!(E[]) && isForwardRange!R1 && isForwardRange!R2
return app.data;
}

/// Ditto
unittest
{
assert("Hello Wörld".replace("o Wö", "o Wo") == "Hello World");
assert("Hello Wörld".replace("l", "h") == "Hehho Wörhd");
}

/++
Same as above, but outputs the result via OutputRange $(D sink).
If no match is found the original array is transferred to $(D sink) as is.
Expand Down Expand Up @@ -1957,21 +1964,24 @@ unittest

foreach (S; TypeTuple!(string, wstring, dstring, char[], wchar[], dchar[]))
{
auto s = to!S("This is a foo foo list");
auto from = to!S("foo");
auto into = to!S("silly");
S r;
int i;
foreach (T; TypeTuple!(string, wstring, dstring, char[], wchar[], dchar[]))
{
auto s = to!S("This is a foo foo list");
auto from = to!T("foo");
auto into = to!S("silly");
S r;
int i;

r = replace(s, from, into);
i = cmp(r, "This is a silly silly list");
assert(i == 0);
r = replace(s, from, into);
i = cmp(r, "This is a silly silly list");
assert(i == 0);

r = replace(s, to!S(""), into);
i = cmp(r, "This is a foo foo list");
assert(i == 0);
r = replace(s, to!S(""), into);
i = cmp(r, "This is a foo foo list");
assert(i == 0);

assert(replace(r, to!S("won't find this"), to!S("whatever")) is r);
assert(replace(r, to!S("won't find this"), to!S("whatever")) is r);
}
}

immutable s = "This is a foo foo list";
Expand Down Expand Up @@ -2001,14 +2011,6 @@ unittest
Replaces elements from $(D array) with indices ranging from $(D from)
(inclusive) to $(D to) (exclusive) with the range $(D stuff). Returns a new
array without changing the contents of $(D subject).
Examples:
--------------------
auto a = [ 1, 2, 3, 4 ];
auto b = a.replace(1, 3, [ 9, 9, 9 ]);
assert(a == [ 1, 2, 3, 4 ]);
assert(b == [ 1, 9, 9, 9, 4 ]);
--------------------
+/
T[] replace(T, Range)(T[] subject, size_t from, size_t to, Range stuff)
if(isInputRange!Range &&
Expand Down Expand Up @@ -2038,7 +2040,7 @@ T[] replace(T, Range)(T[] subject, size_t from, size_t to, Range stuff)
}
}

//Verify Examples.
/// Ditto
unittest
{
auto a = [ 1, 2, 3, 4 ];
Expand Down

0 comments on commit 35193c6

Please sign in to comment.