@@ -14,6 +14,17 @@ fn main() {
14
14
15
15
test ( #fmt ( "test" ) , "test" ) ;
16
16
17
+ // a quadratic optimization in LLVM (jump-threading) makes this test a
18
+ // bit slow to compile unless we break it up
19
+ part1 ( ) ;
20
+ part2 ( ) ;
21
+ part3 ( ) ;
22
+ part4 ( ) ;
23
+ part5 ( ) ;
24
+ part6 ( ) ;
25
+ }
26
+
27
+ fn part1 ( ) {
17
28
// Simple tests for types
18
29
19
30
test ( #fmt ( "%d" , 1 ) , "1" ) ;
@@ -36,6 +47,8 @@ fn main() {
36
47
test ( #fmt ( "%x" , 0xffffffff_ u) , "ffffffff" ) ;
37
48
test ( #fmt ( "%o" , 0xffffffff_ u) , "37777777777" ) ;
38
49
test ( #fmt ( "%t" , 0xffffffff_ u) , "11111111111111111111111111111111" ) ;
50
+ }
51
+ fn part2 ( ) {
39
52
// Widths
40
53
41
54
test ( #fmt ( "%1d" , 500 ) , "500" ) ;
@@ -61,6 +74,9 @@ fn main() {
61
74
test ( #fmt ( "%-10o" , 10 u) , "12 " ) ;
62
75
test ( #fmt ( "%-10t" , 0xff_ u) , "11111111 " ) ;
63
76
test ( #fmt ( "%-10c" , 'A' ) , "A " ) ;
77
+ }
78
+
79
+ fn part3 ( ) {
64
80
// Precision
65
81
66
82
test ( #fmt ( "%.d" , 0 ) , "" ) ;
@@ -99,6 +115,8 @@ fn main() {
99
115
test ( #fmt ( "%.1o" , 10 u) , "12" ) ;
100
116
test ( #fmt ( "%.1t" , 3 u) , "11" ) ;
101
117
test ( #fmt ( "%.1c" , 'A' ) , "A" ) ;
118
+ }
119
+ fn part4 ( ) {
102
120
test ( #fmt ( "%.5d" , 0 ) , "00000" ) ;
103
121
test ( #fmt ( "%.5u" , 0 u) , "00000" ) ;
104
122
test ( #fmt ( "%.5x" , 0 u) , "00000" ) ;
@@ -115,10 +133,13 @@ fn main() {
115
133
// conversions support precision - it's not standard printf so we
116
134
// can do whatever. For now I'm making it behave the same as string
117
135
// conversions.
118
-
136
+
119
137
test ( #fmt ( "%.b" , true ) , "" ) ;
120
138
test ( #fmt ( "%.0b" , true ) , "" ) ;
121
- test ( #fmt ( "%.1b" , true ) , "t" ) ;
139
+ test ( #fmt ( "%.1b" , true ) , "t" ) ;
140
+ }
141
+
142
+ fn part5 ( ) {
122
143
// Explicit + sign. Only for signed conversions
123
144
124
145
test ( #fmt ( "%+d" , 0 ) , "+0" ) ;
@@ -161,6 +182,8 @@ fn main() {
161
182
test ( #fmt ( "%-05s" , "test" ) , "test " ) ;
162
183
test ( #fmt ( "%-05c" , 'A' ) , "A " ) ;
163
184
test ( #fmt ( "%-05b" , true ) , "true " ) ;
185
+ }
186
+ fn part6 ( ) {
164
187
// Precision overrides 0-padding
165
188
166
189
test ( #fmt ( "%06.5d" , 0 ) , " 00000" ) ;
@@ -192,4 +215,4 @@ fn main() {
192
215
test ( #fmt ( "%- 05d" , -1 ) , "-1 " ) ;
193
216
test ( #fmt ( "%-+05d" , 1 ) , "+1 " ) ;
194
217
test ( #fmt ( "%-+05d" , -1 ) , "-1 " ) ;
195
- }
218
+ }
0 commit comments