diff --git a/std/conv.d b/std/conv.d index 7a6700376..bbd065e1e 100644 --- a/std/conv.d +++ b/std/conv.d @@ -974,6 +974,11 @@ unittest assert(wtext(int.max) == "2147483647"w); assert(wtext(int.min) == "-2147483648"w); assert(to!string(0L) == "0"); + + //Test CTFE-ability. + static assert(to!string(1uL << 62) == "4611686018427387904"); + static assert(to!string(0x100000000) == "4294967296"); + static assert(to!string(-138L) == "-138"); } unittest @@ -2010,6 +2015,14 @@ unittest } } +unittest +{ + //Some CTFE-ability checks. + static assert((){string s = "1234abc"; return parse!int(s) == 1234 && s == "abc";}()); + static assert((){string s = "-1234abc"; return parse!int(s) == -1234 && s == "abc";}()); + static assert((){string s = "1234abc"; return parse!uint(s) == 1234 && s == "abc";}()); +} + /// ditto Target parse(Target, Source)(ref Source s, uint radix) if (isSomeChar!(ElementType!Source) && diff --git a/std/string.d b/std/string.d index 06117c1a8..db22b96f1 100644 --- a/std/string.d +++ b/std/string.d @@ -2554,6 +2554,10 @@ unittest assertThrown!FormatException(format("foo %s")); assertThrown!FormatException(format("foo %s", 123, 456)); + + //Test CTFE-ability of format. + static assert(format("hel%slo%s%s%s", "world", -138, 'c', true) == + "helworldlo-138ctrue", "[" ~ s ~ "]"); }