Wolfgang Thallergcc 15.1.0ada185d1 year agoHistory
892 lines · 21.0 KB · D
RawDownload
@safe pure unittest{    import std.string;     import std.exception : assertThrown;    auto bad = "      a\n\tb\n   c";    assertThrown!StringException(bad.outdent);} @system pure unittest{    import std.string;     assert(fromStringz("foo\0"c.ptr) == "foo"c);    assert(fromStringz("foo\0"w.ptr) == "foo"w);    assert(fromStringz("foo\0"d.ptr) == "foo"d);     assert(fromStringz("福\0"c.ptr) == "福"c);    assert(fromStringz("福\0"w.ptr) == "福"w);    assert(fromStringz("福\0"d.ptr) == "福"d);} @nogc @safe pure nothrow unittest{    import std.string;     struct C    {        char[32] name;    }    assert(C("foo\0"c).name.fromStringz() == "foo"c);     struct W    {        wchar[32] name;    }    assert(W("foo\0"w).name.fromStringz() == "foo"w);     struct D    {        dchar[32] name;    }    assert(D("foo\0"d).name.fromStringz() == "foo"d);} pure nothrow @system unittest{    import std.string;     import core.stdc.string : strlen;    import std.conv : to;     auto p = toStringz("foo");    assert(strlen(p) == 3);    const(char)[] foo = "abbzxyzzy";    p = toStringz(foo[3 .. 5]);    assert(strlen(p) == 2);     string test = "";    p = toStringz(test);    assert(*p == 0);     test = "\0";    p = toStringz(test);    assert(*p == 0);     test = "foo\0";    p = toStringz(test);    assert(p[0] == 'f' && p[1] == 'o' && p[2] == 'o' && p[3] == 0);     const string test2 = "";    p = toStringz(test2);    assert(*p == 0);     assert(toStringz([]) is toStringz(""));} @safe pure unittest{    import std.string;     import std.typecons : No;     string s = "Hello World";    assert(indexOf(s, 'W') == 6);    assert(indexOf(s, 'Z') == -1);    assert(indexOf(s, 'w', No.caseSensitive) == 6);} @safe pure unittest{    import std.string;     import std.typecons : No;     string s = "Hello World";    assert(indexOf(s, 'W', 4) == 6);    assert(indexOf(s, 'Z', 100) == -1);    assert(indexOf(s, 'w', 3, No.caseSensitive) == 6);} @safe pure unittest{    import std.string;     import std.typecons : No;     string s = "Hello World";    assert(indexOf(s, "Wo", 4) == 6);    assert(indexOf(s, "Zo", 100) == -1);    assert(indexOf(s, "wo", 3, No.caseSensitive) == 6);} @safe pure unittest{    import std.string;     import std.typecons : No;     string s = "Hello World";    assert(indexOf(s, "Wo") == 6);    assert(indexOf(s, "Zo") == -1);    assert(indexOf(s, "wO", No.caseSensitive) == 6);} @safe pure unittest{    import std.string;     import std.typecons : No;     string s = "Hello World";    assert(lastIndexOf(s, 'l') == 9);    assert(lastIndexOf(s, 'Z') == -1);    assert(lastIndexOf(s, 'L', No.caseSensitive) == 9);} @safe pure unittest{    import std.string;     import std.typecons : No;     string s = "Hello World";    assert(lastIndexOf(s, 'l', 4) == 3);    assert(lastIndexOf(s, 'Z', 1337) == -1);    assert(lastIndexOf(s, 'L', 7, No.caseSensitive) == 3);} @safe pure unittest{    import std.string;     import std.typecons : No;     string s = "Hello World";    assert(lastIndexOf(s, "ll") == 2);    assert(lastIndexOf(s, "Zo") == -1);    assert(lastIndexOf(s, "lL", No.caseSensitive) == 2);} @safe pure unittest{    import std.string;     import std.typecons : No;     string s = "Hello World";    assert(lastIndexOf(s, "ll", 4) == 2);    assert(lastIndexOf(s, "Zo", 128) == -1);    assert(lastIndexOf(s, "lL", 3, No.caseSensitive) == -1);} @safe pure unittest{    import std.string;     import std.conv : to;     ptrdiff_t i = "helloWorld".indexOfAny("Wr");    assert(i == 5);    i = "öällo world".indexOfAny("lo ");    assert(i == 4, to!string(i));} @safe pure unittest{    import std.string;     import std.conv : to;     ptrdiff_t i = "helloWorld".indexOfAny("Wr", 4);    assert(i == 5);     i = "Foo öällo world".indexOfAny("lh", 3);    assert(i == 8, to!string(i));} @safe pure unittest{    import std.string;     ptrdiff_t i = "helloWorld".lastIndexOfAny("Wlo");    assert(i == 8);     i = "Foo öäöllo world".lastIndexOfAny("öF");    assert(i == 8);} @safe pure unittest{    import std.string;     import std.conv : to;     ptrdiff_t i = "helloWorld".lastIndexOfAny("Wlo", 4);    assert(i == 3);     i = "Foo öäöllo world".lastIndexOfAny("öF", 3);    assert(i == 0);} @safe pure unittest{    import std.string;     assert(indexOfNeither("abba", "a", 2) == 2);    assert(indexOfNeither("def", "de", 1) == 2);    assert(indexOfNeither("dfefffg", "dfe", 4) == 6);} @safe pure unittest{    import std.string;     assert(indexOfNeither("def", "a") == 0);    assert(indexOfNeither("def", "de") == 2);    assert(indexOfNeither("dfefffg", "dfe") == 6);} @safe pure unittest{    import std.string;     assert(lastIndexOfNeither("abba", "a") == 2);    assert(lastIndexOfNeither("def", "f") == 1);} @safe pure unittest{    import std.string;     assert(lastIndexOfNeither("def", "rsa", 3) == -1);    assert(lastIndexOfNeither("abba", "a", 2) == 1);} @safe pure unittest{    import std.string;     string s = "hello";    static assert(is(typeof(representation(s)) == immutable(ubyte)[]));    assert(representation(s) is cast(immutable(ubyte)[]) s);    assert(representation(s) == [0x68, 0x65, 0x6c, 0x6c, 0x6f]);} pure @safe unittest{    import std.string;     assert(capitalize("hello") == "Hello");    assert(capitalize("World") == "World");} @safe pure nothrow unittest{    import std.string;     string s = "Hello\nmy\rname\nis";    assert(splitLines(s) == ["Hello", "my", "name", "is"]);} @safe pure unittest{    import std.string;     import std.array : array;     string s = "Hello\nmy\rname\nis";     /* notice the call to 'array' to turn the lazy range created by    lineSplitter comparable to the string[] created by splitLines.    */    assert(lineSplitter(s).array == splitLines(s));} @nogc @safe pure unittest{    import std.string;     auto s = "\rpeter\n\rpaul\r\njerry\u2028ice\u2029cream\n\nsunday\nmon\u2030day\n";    auto lines = s.lineSplitter();    static immutable witness = ["", "peter", "", "paul", "jerry", "ice", "cream", "", "sunday", "mon\u2030day"];    uint i;    foreach (line; lines)    {        assert(line == witness[i++]);    }    assert(i == witness.length);} nothrow @safe pure unittest{    import std.string;     import std.uni : lineSep, paraSep;    assert(stripLeft("     hello world     ") ==           "hello world     ");    assert(stripLeft("\n\t\v\rhello world\n\t\v\r") ==           "hello world\n\t\v\r");    assert(stripLeft(" \u2028hello world") ==           "hello world");    assert(stripLeft("hello world") ==           "hello world");    assert(stripLeft([lineSep] ~ "hello world" ~ lineSep) ==           "hello world" ~ [lineSep]);    assert(stripLeft([paraSep] ~ "hello world" ~ paraSep) ==           "hello world" ~ [paraSep]);     import std.array : array;    import std.utf : byChar;    assert(stripLeft("     hello world     "w.byChar).array ==           "hello world     ");    assert(stripLeft("     \u2022hello world     ".byChar).array ==           "\u2022hello world     ");} @safe pure unittest{    import std.string;     assert(stripLeft("     hello world     ", " ") ==           "hello world     ");    assert(stripLeft("xxxxxhello world     ", "x") ==           "hello world     ");    assert(stripLeft("xxxyy    hello world     ", "xy ") ==           "hello world     ");} @safe pure unittest{    import std.string;     import std.array : array;    import std.utf : byChar, byWchar, byDchar;     assert(stripLeft("  xxxyy hello world     "w.byChar, "xy ").array ==           "hello world     ");     assert(stripLeft("\u2028\u2020hello world\u2028"w.byWchar,                     "\u2028").array == "\u2020hello world\u2028");    assert(stripLeft("\U00010001hello world"w.byWchar, " ").array ==           "\U00010001hello world"w);    assert(stripLeft("\U00010001 xyhello world"d.byDchar,                     "\U00010001 xy").array == "hello world"d);     assert(stripLeft("\u2020hello"w, "\u2020"w) == "hello"w);    assert(stripLeft("\U00010001hello"d, "\U00010001"d) == "hello"d);    assert(stripLeft(" hello ", "") == " hello ");} nothrow @safe pure unittest{    import std.string;     import std.uni : lineSep, paraSep;    assert(stripRight("     hello world     ") ==           "     hello world");    assert(stripRight("\n\t\v\rhello world\n\t\v\r") ==           "\n\t\v\rhello world");    assert(stripRight("hello world") ==           "hello world");    assert(stripRight([lineSep] ~ "hello world" ~ lineSep) ==           [lineSep] ~ "hello world");    assert(stripRight([paraSep] ~ "hello world" ~ paraSep) ==           [paraSep] ~ "hello world");} @safe pure unittest{    import std.string;     assert(stripRight("     hello world     ", "x") ==           "     hello world     ");    assert(stripRight("     hello world     ", " ") ==           "     hello world");    assert(stripRight("     hello worldxy     ", "xy ") ==           "     hello world");} @safe pure unittest{    import std.string;     import std.uni : lineSep, paraSep;    assert(strip("     hello world     ") ==           "hello world");    assert(strip("\n\t\v\rhello world\n\t\v\r") ==           "hello world");    assert(strip("hello world") ==           "hello world");    assert(strip([lineSep] ~ "hello world" ~ [lineSep]) ==           "hello world");    assert(strip([paraSep] ~ "hello world" ~ [paraSep]) ==           "hello world");} @safe pure unittest{    import std.string;     assert(strip("     hello world     ", "x") ==           "     hello world     ");    assert(strip("     hello world     ", " ") ==           "hello world");    assert(strip("   xyxyhello worldxyxy     ", "xy ") ==           "hello world");    assert(strip("\u2020hello\u2020"w, "\u2020"w) == "hello"w);    assert(strip("\U00010001hello\U00010001"d, "\U00010001"d) == "hello"d);    assert(strip(" hello ", "") == " hello ");} @safe pure unittest{    import std.string;     assert(strip("xxhelloyy", "x", "y") == "hello");    assert(strip("   xyxyhello worldxyxyzz    ", "xy ", "xyz ") ==           "hello world");    assert(strip("\u2020hello\u2028"w, "\u2020"w, "\u2028"w) == "hello"w);    assert(strip("\U00010001hello\U00010002"d, "\U00010001"d, "\U00010002"d) ==           "hello"d);    assert(strip(" hello ", "", "") == " hello ");} @safe pure unittest{    import std.string;     import std.uni : lineSep, paraSep, nelSep;    import std.utf : decode;    assert(chomp(" hello world  \n\r") == " hello world  \n");    assert(chomp(" hello world  \r\n") == " hello world  ");    assert(chomp(" hello world  \f") == " hello world  ");    assert(chomp(" hello world  \v") == " hello world  ");    assert(chomp(" hello world  \n\n") == " hello world  \n");    assert(chomp(" hello world  \n\n ") == " hello world  \n\n ");    assert(chomp(" hello world  \n\n" ~ [lineSep]) == " hello world  \n\n");    assert(chomp(" hello world  \n\n" ~ [paraSep]) == " hello world  \n\n");    assert(chomp(" hello world  \n\n" ~ [ nelSep]) == " hello world  \n\n");    assert(chomp(" hello world ") == " hello world ");    assert(chomp(" hello world") == " hello world");    assert(chomp("") == "");     assert(chomp(" hello world", "orld") == " hello w");    assert(chomp(" hello world", " he") == " hello world");    assert(chomp("", "hello") == "");     // Don't decode pointlessly    assert(chomp("hello\xFE", "\r") == "hello\xFE");} @safe pure unittest{    import std.string;     assert(chompPrefix("hello world", "he") == "llo world");    assert(chompPrefix("hello world", "hello w") == "orld");    assert(chompPrefix("hello world", " world") == "hello world");    assert(chompPrefix("", "hello") == "");} @safe pure unittest{    import std.string;     assert(chop("hello world") == "hello worl");    assert(chop("hello world\n") == "hello world");    assert(chop("hello world\r") == "hello world");    assert(chop("hello world\n\r") == "hello world\n");    assert(chop("hello world\r\n") == "hello world");    assert(chop("Walter Bright") == "Walter Brigh");    assert(chop("") == "");} @safe pure unittest{    import std.string;     assert(leftJustify("hello", 7, 'X') == "helloXX");

Lines 1–500 of 892.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t