1 // RUNNABLE_PHOBOS_TEST
2 // PERMUTE_ARGS:
3
4 import std.stdio;
5 import std.string;
6
7 /*************************************************************/
8
test1()9 void test1()
10 {
11 double x = 1e6;
12 float f;
13 double d;
14 real r;
15
16 while (x > 1e-5)
17 { double y = x / 101.0;
18
19 std.stdio.writef("x = %g\t%f\t%e\n",x/101.0,x/101.0,x/101.0);
20 x /= 10.0;
21 }
22
23 double a = 123456789.0;
24 for (int i = 20; i--; a /= 10)
25 std.stdio.writef("%20.6g|%20.6e|%20.6f\n",a,a,a);
26
27 std.stdio.writef("%e %e %e %e\n",float.nan,double.nan,real.nan,double.infinity);
28 std.stdio.writef("%e %e %e\n",-float.nan,-double.nan,-double.infinity);
29 std.stdio.writef("%-5E %5E %E\n",float.nan,double.nan,double.infinity);
30
31 std.stdio.writef("%f %f %f\n",float.nan,double.nan,double.infinity);
32 std.stdio.writef("%f %f %f\n",-float.nan,-double.nan,-double.infinity);
33 std.stdio.writef("%+F %+ F %F\n",float.nan,double.nan,double.infinity);
34
35 std.stdio.writef("%g %g %g\n",float.nan,double.nan,double.infinity);
36 std.stdio.writef("%g %g %g\n",-float.nan,-double.nan,-double.infinity);
37 std.stdio.writef("% G %G %G\n",float.nan,double.nan,double.infinity);
38
39 r = 0x1.AAp+3L;
40 std.stdio.writef(" r = %g\n", r);
41 std.stdio.writef(" r = %a\n", r);
42 std.stdio.writef(" r = %A\n", r);
43
44 d = 0x1.AAp+3;
45 std.stdio.writef(" d = %.5a\n", d);
46 std.stdio.writef(" d = %A\n", d);
47
48 f = 0x1.AAp+3f;
49 std.stdio.writef(" f = %a\n", f);
50 std.stdio.writef(" f = %A\n", f);
51
52 f = 0x1.FFp+3f;
53 std.stdio.writef(" f = %.1a\n", f);
54 std.stdio.writef(" f = %A\n", f);
55
56 r = 0;
57 std.stdio.writef(" r = %a\n", r);
58 std.stdio.writef(" r = %A\n", r);
59
60 std.stdio.writef("%e\n", 1e+300);
61 std.stdio.writef("%.0f\n%.307f\n", 1e+300, 1e-300);
62 std.stdio.writef("%.0A\n%.307A\n", 1e+300, 1e-300);
63 }
64
65 /*************************************************************/
66
test2()67 void test2()
68 {
69 writefln("%o", 9);
70 assert(std.string.format("%o", 9) == "11");
71 assert(std.string.format("%o", 10) == "12");
72 assert(std.string.format("%b", 9) == "1001");
73 assert(std.string.format("%b", 10) == "1010");
74 }
75
76
77 /*************************************************************/
78
test3()79 void test3()
80 {
81 Object e = new Exception("hello");
82 writeln(e.toString());
83 //assert(e.toString() == "object.Exception: hello");
84 //assert(format(e) == "object.Exception: hello");
85
86 alias char[] xstring;
87 assert(format(cast(xstring)"world") == "world");
88 }
89
90 /*************************************************************/
91
test4()92 void test4()
93 {
94 const char[][] x = ["%s","123"];
95 writeln(x);
96 assert(std.string.format("%s", x) == `["%s", "123"]`);
97 }
98
99 /*************************************************************/
100
test5()101 void test5()
102 {
103 int[int] foo;
104
105 foo[1] = 2;
106 foo[7] = 28;
107
108 writefln("%s", foo);
109
110 void[0] v;
111 assert(format("%s", v) == "[]");
112 }
113
114 /*************************************************************/
115
main()116 int main()
117 {
118 test1();
119 test2();
120 test3();
121 test4();
122 test5();
123
124 std.stdio.writefln("Success");
125 return 0;
126 }
127