Rune - Fix array passing, optimize constant array indices
[rune.git] / tests / format.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 w3 = 3;
16         int w9 = 9;
17
18         stdout->format("Format %d\n", 23.4, 44);
19
20         stdout->format("Format %+d %04d %4d\n", 23, -23, -23);
21
22         stdout->format("Format %d %o 0x%x %#x %#X\n", 63, 63, 63, 63, 63);
23
24         # badflt
25         stdout->format("Format %6.2f\n", 33);
26
27         # 33.00 33 33.
28         stdout->format("Format  33.00 33 33.\n");
29         stdout->format("Format %6.2f %.0f %#.0f\n", 33.0, 33.0, 33.0);
30
31         # Rounding
32         stdout->format("Format %6.2f\n", 333333333.334);
33         stdout->format("Format %6.2f\n", 333333333.335);
34         stdout->format("Format %6.2f\n", 333333333.336);
35
36         stdout->format("Format 0: %6.0f\n", 0.0);
37         stdout->format("Format 0.00: %6.2f\n", 0.0);
38
39         stdout->show  ("Format      33   33.11    33.1  33.100");
40         stdout->format("Format %7.3g %7.3g %7.3g %#7.3g\n",
41                         33.00, 33.11, 33.1, 33.1);
42
43         stdout->format("Format %6.2f %6.9f\n", 1.234567891234, 1.234567891234);
44
45         stdout->format("Format %6.*f %*.*f %6.*f\n",
46                         w9, 3.3,
47                         w9, w3, 3.3,
48                         w9, 3.3);
49
50         stdout->format("Format string %s ok\n", "charlie");
51
52         stdout->format("Format %+8.3f\n", 1.234567890123456789F);
53         stdout->format("Format %+8.6f\n", 1.234567890123456789F);
54         stdout->format("Format %+8.9f\n", 1.234567890123456789F);
55
56         stdout->format("Format %+8.3f\n", 1.234567890123456789);
57         stdout->format("Format %+8.6f\n", 1.234567890123456789);
58         stdout->format("Format %+8.9f\n", 1.234567890123456789);
59
60         w3 = 95755;
61         stdout->format("Format %+8.3f\n", 1.234567890123456789X);
62         stdout->format("Format %+8.6f\n", 1.234567890123456789X);
63         stdout->format("Format %+8.9f\n", 1.234567890123456789X);
64
65         stdout->format("Format %+10.3r\n", 1.234567890123456789e-3F);
66         stdout->format("Format %+10.3r\n", 1.234567890123456789e+1);
67         stdout->format("Format %+10.3r\n", 1.234567890123456789e+3X);
68
69         stdout->format("Format %.30r\n", 1.234567890123456789012345F);
70         stdout->format("Format %.30r\n", 1.234567890123456789012345);
71         stdout->format("Format %.30r\n", 1.234567890123456789012345X);
72
73         stdout->format("Format %.30r\n", 1.0F);
74         stdout->format("Format %.30r\n", 1.0);
75         stdout->format("Format %.30r\n", 1.0X);
76
77         # Test large negative and positive exponents
78         #
79         stdout->format("float.epsilon   %12.6e test\n", float.epsilon);
80         stdout->format("double.epsilon  %12.6e test\n", double.epsilon);
81         stdout->format("ldouble.epsilon %12.6e test\n", ldouble.epsilon);
82
83         stdout->format("float.epsilon   %12.6E invt\n",
84                        1.0F / float.epsilon);
85         stdout->format("double.epsilon  %12.6E invt\n",
86                        1.0 / double.epsilon);
87         stdout->format("ldouble.epsilon %12.6E invt\n",
88                        1.0X / ldouble.epsilon);
89
90         stdout->format("string %15s string\n", "abcd");
91         stdout->format("string %-15s string\n", "abcd");
92         stdout->format("string %015s string\n", "abcd");
93         stdout->format("string %.15s string\n", "");
94
95         stdout->format("pointer %p\n", (const void *)"");
96
97         # generates "(noarg)"
98         #
99         stdout->format("missing-argument %p\n");
100
101         return(0);
102 }