Skip to content

Commit 9e59d74

Browse files
committed
fix tests
1 parent 762f645 commit 9e59d74

File tree

1 file changed

+187
-146
lines changed

1 file changed

+187
-146
lines changed

src/libfmt_macros/tests.rs

+187-146
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ fn fmtdflt() -> FormatSpec<'static> {
1212
flags: 0,
1313
precision: CountImplied,
1414
width: CountImplied,
15+
precision_span: None,
16+
width_span: None,
1517
ty: "",
1618
};
1719
}
@@ -79,165 +81,204 @@ fn format_position_nothing_else() {
7981
}
8082
#[test]
8183
fn format_type() {
82-
same("{3:a}",
83-
&[NextArgument(Argument {
84-
position: ArgumentIs(3),
85-
format: FormatSpec {
86-
fill: None,
87-
align: AlignUnknown,
88-
flags: 0,
89-
precision: CountImplied,
90-
width: CountImplied,
91-
ty: "a",
92-
},
93-
})]);
84+
same(
85+
"{3:a}",
86+
&[NextArgument(Argument {
87+
position: ArgumentIs(3),
88+
format: FormatSpec {
89+
fill: None,
90+
align: AlignUnknown,
91+
flags: 0,
92+
precision: CountImplied,
93+
width: CountImplied,
94+
precision_span: None,
95+
width_span: None,
96+
ty: "a",
97+
},
98+
})]);
9499
}
95100
#[test]
96101
fn format_align_fill() {
97-
same("{3:>}",
98-
&[NextArgument(Argument {
99-
position: ArgumentIs(3),
100-
format: FormatSpec {
101-
fill: None,
102-
align: AlignRight,
103-
flags: 0,
104-
precision: CountImplied,
105-
width: CountImplied,
106-
ty: "",
107-
},
108-
})]);
109-
same("{3:0<}",
110-
&[NextArgument(Argument {
111-
position: ArgumentIs(3),
112-
format: FormatSpec {
113-
fill: Some('0'),
114-
align: AlignLeft,
115-
flags: 0,
116-
precision: CountImplied,
117-
width: CountImplied,
118-
ty: "",
119-
},
120-
})]);
121-
same("{3:*<abcd}",
122-
&[NextArgument(Argument {
123-
position: ArgumentIs(3),
124-
format: FormatSpec {
125-
fill: Some('*'),
126-
align: AlignLeft,
127-
flags: 0,
128-
precision: CountImplied,
129-
width: CountImplied,
130-
ty: "abcd",
131-
},
132-
})]);
102+
same(
103+
"{3:>}",
104+
&[NextArgument(Argument {
105+
position: ArgumentIs(3),
106+
format: FormatSpec {
107+
fill: None,
108+
align: AlignRight,
109+
flags: 0,
110+
precision: CountImplied,
111+
width: CountImplied,
112+
precision_span: None,
113+
width_span: None,
114+
ty: "",
115+
},
116+
})]);
117+
same(
118+
"{3:0<}",
119+
&[NextArgument(Argument {
120+
position: ArgumentIs(3),
121+
format: FormatSpec {
122+
fill: Some('0'),
123+
align: AlignLeft,
124+
flags: 0,
125+
precision: CountImplied,
126+
width: CountImplied,
127+
precision_span: None,
128+
width_span: None,
129+
ty: "",
130+
},
131+
})]);
132+
same(
133+
"{3:*<abcd}",
134+
&[NextArgument(Argument {
135+
position: ArgumentIs(3),
136+
format: FormatSpec {
137+
fill: Some('*'),
138+
align: AlignLeft,
139+
flags: 0,
140+
precision: CountImplied,
141+
width: CountImplied,
142+
precision_span: None,
143+
width_span: None,
144+
ty: "abcd",
145+
},
146+
})]);
133147
}
134148
#[test]
135149
fn format_counts() {
136150
use syntax_pos::{GLOBALS, Globals, edition};
137151
GLOBALS.set(&Globals::new(edition::DEFAULT_EDITION), || {
138-
same("{:10s}",
139-
&[NextArgument(Argument {
140-
position: ArgumentImplicitlyIs(0),
141-
format: FormatSpec {
142-
fill: None,
143-
align: AlignUnknown,
144-
flags: 0,
145-
precision: CountImplied,
146-
width: CountIs(10),
147-
ty: "s",
148-
},
149-
})]);
150-
same("{:10$.10s}",
151-
&[NextArgument(Argument {
152-
position: ArgumentImplicitlyIs(0),
153-
format: FormatSpec {
154-
fill: None,
155-
align: AlignUnknown,
156-
flags: 0,
157-
precision: CountIs(10),
158-
width: CountIsParam(10),
159-
ty: "s",
160-
},
161-
})]);
162-
same("{:.*s}",
163-
&[NextArgument(Argument {
164-
position: ArgumentImplicitlyIs(1),
165-
format: FormatSpec {
166-
fill: None,
167-
align: AlignUnknown,
168-
flags: 0,
169-
precision: CountIsParam(0),
170-
width: CountImplied,
171-
ty: "s",
172-
},
173-
})]);
174-
same("{:.10$s}",
175-
&[NextArgument(Argument {
176-
position: ArgumentImplicitlyIs(0),
177-
format: FormatSpec {
178-
fill: None,
179-
align: AlignUnknown,
180-
flags: 0,
181-
precision: CountIsParam(10),
182-
width: CountImplied,
183-
ty: "s",
184-
},
185-
})]);
186-
same("{:a$.b$s}",
187-
&[NextArgument(Argument {
188-
position: ArgumentImplicitlyIs(0),
189-
format: FormatSpec {
190-
fill: None,
191-
align: AlignUnknown,
192-
flags: 0,
193-
precision: CountIsName(Symbol::intern("b")),
194-
width: CountIsName(Symbol::intern("a")),
195-
ty: "s",
196-
},
197-
})]);
152+
same(
153+
"{:10s}",
154+
&[NextArgument(Argument {
155+
position: ArgumentImplicitlyIs(0),
156+
format: FormatSpec {
157+
fill: None,
158+
align: AlignUnknown,
159+
flags: 0,
160+
precision: CountImplied,
161+
width: CountIs(10),
162+
precision_span: None,
163+
width_span: None,
164+
ty: "s",
165+
},
166+
})]);
167+
same(
168+
"{:10$.10s}",
169+
&[NextArgument(Argument {
170+
position: ArgumentImplicitlyIs(0),
171+
format: FormatSpec {
172+
fill: None,
173+
align: AlignUnknown,
174+
flags: 0,
175+
precision: CountIs(10),
176+
width: CountIsParam(10),
177+
precision_span: None,
178+
width_span: Some(InnerSpan::new(3, 6)),
179+
ty: "s",
180+
},
181+
})]);
182+
same(
183+
"{:.*s}",
184+
&[NextArgument(Argument {
185+
position: ArgumentImplicitlyIs(1),
186+
format: FormatSpec {
187+
fill: None,
188+
align: AlignUnknown,
189+
flags: 0,
190+
precision: CountIsParam(0),
191+
width: CountImplied,
192+
precision_span: Some(InnerSpan::new(3, 5)),
193+
width_span: None,
194+
ty: "s",
195+
},
196+
})]);
197+
same(
198+
"{:.10$s}",
199+
&[NextArgument(Argument {
200+
position: ArgumentImplicitlyIs(0),
201+
format: FormatSpec {
202+
fill: None,
203+
align: AlignUnknown,
204+
flags: 0,
205+
precision: CountIsParam(10),
206+
width: CountImplied,
207+
precision_span: Some(InnerSpan::new(3, 7)),
208+
width_span: None,
209+
ty: "s",
210+
},
211+
})]);
212+
same(
213+
"{:a$.b$s}",
214+
&[NextArgument(Argument {
215+
position: ArgumentImplicitlyIs(0),
216+
format: FormatSpec {
217+
fill: None,
218+
align: AlignUnknown,
219+
flags: 0,
220+
precision: CountIsName(Symbol::intern("b")),
221+
width: CountIsName(Symbol::intern("a")),
222+
precision_span: None,
223+
width_span: None,
224+
ty: "s",
225+
},
226+
})]);
198227
});
199228
}
200229
#[test]
201230
fn format_flags() {
202-
same("{:-}",
203-
&[NextArgument(Argument {
204-
position: ArgumentImplicitlyIs(0),
205-
format: FormatSpec {
206-
fill: None,
207-
align: AlignUnknown,
208-
flags: (1 << FlagSignMinus as u32),
209-
precision: CountImplied,
210-
width: CountImplied,
211-
ty: "",
212-
},
213-
})]);
214-
same("{:+#}",
215-
&[NextArgument(Argument {
216-
position: ArgumentImplicitlyIs(0),
217-
format: FormatSpec {
218-
fill: None,
219-
align: AlignUnknown,
220-
flags: (1 << FlagSignPlus as u32) | (1 << FlagAlternate as u32),
221-
precision: CountImplied,
222-
width: CountImplied,
223-
ty: "",
224-
},
225-
})]);
231+
same(
232+
"{:-}",
233+
&[NextArgument(Argument {
234+
position: ArgumentImplicitlyIs(0),
235+
format: FormatSpec {
236+
fill: None,
237+
align: AlignUnknown,
238+
flags: (1 << FlagSignMinus as u32),
239+
precision: CountImplied,
240+
width: CountImplied,
241+
precision_span: None,
242+
width_span: None,
243+
ty: "",
244+
},
245+
})]);
246+
same(
247+
"{:+#}",
248+
&[NextArgument(Argument {
249+
position: ArgumentImplicitlyIs(0),
250+
format: FormatSpec {
251+
fill: None,
252+
align: AlignUnknown,
253+
flags: (1 << FlagSignPlus as u32) | (1 << FlagAlternate as u32),
254+
precision: CountImplied,
255+
width: CountImplied,
256+
precision_span: None,
257+
width_span: None,
258+
ty: "",
259+
},
260+
})]);
226261
}
227262
#[test]
228263
fn format_mixture() {
229-
same("abcd {3:a} efg",
230-
&[String("abcd "),
231-
NextArgument(Argument {
232-
position: ArgumentIs(3),
233-
format: FormatSpec {
234-
fill: None,
235-
align: AlignUnknown,
236-
flags: 0,
237-
precision: CountImplied,
238-
width: CountImplied,
239-
ty: "a",
240-
},
241-
}),
242-
String(" efg")]);
264+
same(
265+
"abcd {3:a} efg",
266+
&[
267+
String("abcd "),
268+
NextArgument(Argument {
269+
position: ArgumentIs(3),
270+
format: FormatSpec {
271+
fill: None,
272+
align: AlignUnknown,
273+
flags: 0,
274+
precision: CountImplied,
275+
width: CountImplied,
276+
precision_span: None,
277+
width_span: None,
278+
ty: "a",
279+
},
280+
}),
281+
String(" efg"),
282+
],
283+
);
243284
}

0 commit comments

Comments
 (0)