-
Notifications
You must be signed in to change notification settings - Fork 9
/
formatstrings.nt
54 lines (47 loc) · 1.41 KB
/
formatstrings.nt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module formatstrings;
macro import std.macro.assert;
void main() {
int i = 5;
assert("i = $i" == "i = 5");
float f = 1.5f, g = 3.0f;
assert("$f and $g" == "1.500000 and 3.000000");
assert("the sum is $(f + g)." == "the sum is 4.500000.");
assert("$(f + g =)." == "f + g = 4.500000.");
long l;
assert("$(l)" == "0"); // long
int[] a;
assert("$(a.length)" == "0"); // size_t
testTypes;
}
void testTypes() {
assert("$(2)" == "2");
assert("$(2.0f)" == "2.000000");
assert("$(2.0)" == "2.000000");
assert("$(cast(short) 2)" == "2");
assert("$(cast(ubyte) 2)" == "2");
assert("$(true)" == "true");
assert("$([2, 3, 4])" == "[2, 3, 4]");
assert("$(A(2))" == "A(i=2)");
assert("$(null)" == "null");
assert("$(cast(void*) null)" == "null");
assert("$(cast(void*) 1)" == ("0x0000000000000001" if sizeof(size_t) == 8 else "0x00000001"));
assert("$(:foo)" == ":foo");
assert("$((2, false))" == "(2, false)");
assert("$((a=2, b=false))" == "(a=2, b=false)");
assert("$(sum(false))" == "foo");
assert("$(sum(true))" == "2");
assert("$(vec2i(2, 3))" == "<2, 3>");
assert("$(Enum.A)" == "A");
assert("$(Enum.B)" == "B");
}
alias vec2i = Vector(int, 2);
struct A {
int i;
// FIXME autogen
string toString() return "A(i=$i)";
}
enum Enum { A, B }
(int | string) sum(bool b) {
if (b) return 2;
else return "foo";
}