3 fn same(fmt
: &'
static str, p
: &[Piece
<'
static>]) {
4 let parser
= Parser
::new(fmt
, None
, None
, false, ParseMode
::Format
);
5 assert_eq
!(parser
.collect
::<Vec
<Piece
<'
static>>>(), p
);
8 fn fmtdflt() -> FormatSpec
<'
static> {
13 precision
: CountImplied
,
23 let mut p
= Parser
::new(s
, None
, None
, false, ParseMode
::Format
);
25 assert
!(!p
.errors
.is_empty());
30 same("asdf", &[String("asdf")]);
31 same("a{{b", &[String("a"), String("{b")]);
32 same("a}}b", &[String("a"), String("}b")]);
33 same("a}}", &[String("a"), String("}")]);
34 same("}}", &[String("}")]);
35 same("\\}}", &[String("\\"), String("}")]);
61 same("{}", &[NextArgument(Argument { position: ArgumentImplicitlyIs(0), format: fmtdflt() }
)]);
64 fn format_position() {
65 same("{3}", &[NextArgument(Argument { position: ArgumentIs(3), format: fmtdflt() }
)]);
68 fn format_position_nothing_else() {
69 same("{3:}", &[NextArgument(Argument { position: ArgumentIs(3), format: fmtdflt() }
)]);
75 &[NextArgument(Argument
{
76 position
: ArgumentIs(3),
81 precision
: CountImplied
,
92 fn format_align_fill() {
95 &[NextArgument(Argument
{
96 position
: ArgumentIs(3),
101 precision
: CountImplied
,
103 precision_span
: None
,
112 &[NextArgument(Argument
{
113 position
: ArgumentIs(3),
118 precision
: CountImplied
,
120 precision_span
: None
,
129 &[NextArgument(Argument
{
130 position
: ArgumentIs(3),
135 precision
: CountImplied
,
137 precision_span
: None
,
140 ty_span
: Some(InnerSpan
::new(6, 10)),
147 use rustc_span
::{edition, SessionGlobals, SESSION_GLOBALS}
;
148 SESSION_GLOBALS
.set(&SessionGlobals
::new(edition
::DEFAULT_EDITION
), || {
151 &[NextArgument(Argument
{
152 position
: ArgumentImplicitlyIs(0),
157 precision
: CountImplied
,
159 precision_span
: None
,
168 &[NextArgument(Argument
{
169 position
: ArgumentImplicitlyIs(0),
174 precision
: CountIs(10),
175 width
: CountIsParam(10),
176 precision_span
: None
,
177 width_span
: Some(InnerSpan
::new(3, 6)),
185 &[NextArgument(Argument
{
186 position
: ArgumentImplicitlyIs(1),
191 precision
: CountIsParam(0),
193 precision_span
: Some(InnerSpan
::new(3, 5)),
202 &[NextArgument(Argument
{
203 position
: ArgumentImplicitlyIs(0),
208 precision
: CountIsParam(10),
210 precision_span
: Some(InnerSpan
::new(3, 7)),
219 &[NextArgument(Argument
{
220 position
: ArgumentImplicitlyIs(0),
225 precision
: CountIsName(Symbol
::intern("b")),
226 width
: CountIsName(Symbol
::intern("a")),
227 precision_span
: None
,
240 &[NextArgument(Argument
{
241 position
: ArgumentImplicitlyIs(0),
245 flags
: (1 << FlagSignMinus
as u32),
246 precision
: CountImplied
,
248 precision_span
: None
,
257 &[NextArgument(Argument
{
258 position
: ArgumentImplicitlyIs(0),
262 flags
: (1 << FlagSignPlus
as u32) | (1 << FlagAlternate
as u32),
263 precision
: CountImplied
,
265 precision_span
: None
,
274 fn format_mixture() {
279 NextArgument(Argument
{
280 position
: ArgumentIs(3),
285 precision
: CountImplied
,
287 precision_span
: None
,