From 9bd4044536cee08a7cc631dc16d7a63f40d1bb8c Mon Sep 17 00:00:00 2001 From: jmdavis Date: Sun, 24 Feb 2013 16:02:32 -0800 Subject: [PATCH] Added CTFE-ability tests to some stuff in std.conv and std.string. These tests are for the functionality that std.metastrings provides, and we need to ensure that the normal functions which are replacing those in std.metastrings continue to work in CTFE. --- std/conv.d | 13 +++++++++++++ std/string.d | 4 ++++ 2 files changed, 17 insertions(+) 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 ~ "]"); }