Rune - Fix array passing, optimize constant array indices
[rune.git] / tests / format3.d
1 #!/usr/local/bin/rune -x
2 #
3 # Test the File.format() method, generally used for output on stdout or
4 # stderr.
5
6 import "sys";
7 import <stdio>;
8
9 alias stdio.File *stdout = stdio.stdout;
10
11 public
12 int
13 main(int ac, char **av)
14 {
15         int i;
16
17         stdio.stdout->setmode(M_FULL);
18         for (i = 0; i < 10000; ++i)
19                 dotest();
20 }
21
22 public 
23 void
24 dotest()
25 {
26         int w3 = 3;
27         int w9 = 9;
28
29         stdout->format("Format %d\n", 23.4, 44);
30
31         stdout->format("Format %+d %04d %4d\n", 23, -23, -23);
32
33         stdout->format("Format %d %o 0x%x %#x %#X\n", 63, 63, 63, 63, 63);
34
35         # badflt
36         stdout->format("Format %6.2f\n", 33);
37
38         # 33.00 33 33.
39         stdout->format("Format  33.00 33 33.\n");
40         stdout->format("Format %6.2f %.0f %#.0f\n", 33.0, 33.0, 33.0);
41
42         # Rounding
43         stdout->format("Format %6.2f\n", 333333333.334);
44         stdout->format("Format %6.2f\n", 333333333.335);
45         stdout->format("Format %6.2f\n", 333333333.336);
46
47         stdout->format("Format 0: %6.0f\n", 0.0);
48         stdout->format("Format 0.00: %6.2f\n", 0.0);
49
50         stdout->show  ("Format      33   33.11    33.1  33.100");
51         stdout->format("Format %7.3g %7.3g %7.3g %#7.3g\n",
52                         33.00, 33.11, 33.1, 33.1);
53
54         stdout->format("Format %6.2f %6.9f\n", 1.234567891234, 1.234567891234);
55
56         stdout->format("Format %6.*f %*.*f %6.*f\n",
57                         w9, 3.3,
58                         w9, w3, 3.3,
59                         w9, 3.3);
60
61         stdout->format("Format string %s ok\n", "charlie");
62
63         stdout->format("Format %+8.3f\n", 1.234567890123456789F);
64         stdout->format("Format %+8.6f\n", 1.234567890123456789F);
65         stdout->format("Format %+8.9f\n", 1.234567890123456789F);
66
67         stdout->format("Format %+8.3f\n", 1.234567890123456789);
68         stdout->format("Format %+8.6f\n", 1.234567890123456789);
69         stdout->format("Format %+8.9f\n", 1.234567890123456789);
70
71         w3 = 95755;
72         stdout->format("Format %+8.3f\n", 1.234567890123456789X);
73         stdout->format("Format %+8.6f\n", 1.234567890123456789X);
74         stdout->format("Format %+8.9f\n", 1.234567890123456789X);
75
76         stdout->format("Format %+10.3r\n", 1.234567890123456789e-3F);
77         stdout->format("Format %+10.3r\n", 1.234567890123456789e+1);
78         stdout->format("Format %+10.3r\n", 1.234567890123456789e+3X);
79
80         stdout->format("Format %.30r\n", 1.234567890123456789012345F);
81         stdout->format("Format %.30r\n", 1.234567890123456789012345);
82         stdout->format("Format %.30r\n", 1.234567890123456789012345X);
83
84         stdout->format("Format %.30r\n", 1.0F);
85         stdout->format("Format %.30r\n", 1.0);
86         stdout->format("Format %.30r\n", 1.0X);
87
88         # Test large negative and positive exponents
89         #
90         stdout->format("float.epsilon   %12.6e test\n", float.epsilon);
91         stdout->format("double.epsilon  %12.6e test\n", double.epsilon);
92         stdout->format("ldouble.epsilon %12.6e test\n", ldouble.epsilon);
93
94         stdout->format("float.epsilon   %12.6E invt\n",
95                        1.0F / float.epsilon);
96         stdout->format("double.epsilon  %12.6E invt\n",
97                        1.0 / double.epsilon);
98         stdout->format("ldouble.epsilon %12.6E invt\n",
99                        1.0X / ldouble.epsilon);
100
101         stdout->format("string %15s string\n", "abcd");
102         stdout->format("string %-15s string\n", "abcd");
103         stdout->format("string %015s string\n", "abcd");
104         stdout->format("string %.15s string\n", "");
105
106         stdout->format("pointer %p\n", (const void *)"");
107
108         # generates "(noarg)"
109         #
110         stdout->format("missing-argument %p\n");
111 }