fix tests
This commit is contained in:
parent
762f6452b9
commit
9e59d744ac
1 changed files with 187 additions and 146 deletions
|
@ -12,6 +12,8 @@ fn fmtdflt() -> FormatSpec<'static> {
|
||||||
flags: 0,
|
flags: 0,
|
||||||
precision: CountImplied,
|
precision: CountImplied,
|
||||||
width: CountImplied,
|
width: CountImplied,
|
||||||
|
precision_span: None,
|
||||||
|
width_span: None,
|
||||||
ty: "",
|
ty: "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -79,165 +81,204 @@ fn format_position_nothing_else() {
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn format_type() {
|
fn format_type() {
|
||||||
same("{3:a}",
|
same(
|
||||||
&[NextArgument(Argument {
|
"{3:a}",
|
||||||
position: ArgumentIs(3),
|
&[NextArgument(Argument {
|
||||||
format: FormatSpec {
|
position: ArgumentIs(3),
|
||||||
fill: None,
|
format: FormatSpec {
|
||||||
align: AlignUnknown,
|
fill: None,
|
||||||
flags: 0,
|
align: AlignUnknown,
|
||||||
precision: CountImplied,
|
flags: 0,
|
||||||
width: CountImplied,
|
precision: CountImplied,
|
||||||
ty: "a",
|
width: CountImplied,
|
||||||
},
|
precision_span: None,
|
||||||
})]);
|
width_span: None,
|
||||||
|
ty: "a",
|
||||||
|
},
|
||||||
|
})]);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn format_align_fill() {
|
fn format_align_fill() {
|
||||||
same("{3:>}",
|
same(
|
||||||
&[NextArgument(Argument {
|
"{3:>}",
|
||||||
position: ArgumentIs(3),
|
&[NextArgument(Argument {
|
||||||
format: FormatSpec {
|
position: ArgumentIs(3),
|
||||||
fill: None,
|
format: FormatSpec {
|
||||||
align: AlignRight,
|
fill: None,
|
||||||
flags: 0,
|
align: AlignRight,
|
||||||
precision: CountImplied,
|
flags: 0,
|
||||||
width: CountImplied,
|
precision: CountImplied,
|
||||||
ty: "",
|
width: CountImplied,
|
||||||
},
|
precision_span: None,
|
||||||
})]);
|
width_span: None,
|
||||||
same("{3:0<}",
|
ty: "",
|
||||||
&[NextArgument(Argument {
|
},
|
||||||
position: ArgumentIs(3),
|
})]);
|
||||||
format: FormatSpec {
|
same(
|
||||||
fill: Some('0'),
|
"{3:0<}",
|
||||||
align: AlignLeft,
|
&[NextArgument(Argument {
|
||||||
flags: 0,
|
position: ArgumentIs(3),
|
||||||
precision: CountImplied,
|
format: FormatSpec {
|
||||||
width: CountImplied,
|
fill: Some('0'),
|
||||||
ty: "",
|
align: AlignLeft,
|
||||||
},
|
flags: 0,
|
||||||
})]);
|
precision: CountImplied,
|
||||||
same("{3:*<abcd}",
|
width: CountImplied,
|
||||||
&[NextArgument(Argument {
|
precision_span: None,
|
||||||
position: ArgumentIs(3),
|
width_span: None,
|
||||||
format: FormatSpec {
|
ty: "",
|
||||||
fill: Some('*'),
|
},
|
||||||
align: AlignLeft,
|
})]);
|
||||||
flags: 0,
|
same(
|
||||||
precision: CountImplied,
|
"{3:*<abcd}",
|
||||||
width: CountImplied,
|
&[NextArgument(Argument {
|
||||||
ty: "abcd",
|
position: ArgumentIs(3),
|
||||||
},
|
format: FormatSpec {
|
||||||
})]);
|
fill: Some('*'),
|
||||||
|
align: AlignLeft,
|
||||||
|
flags: 0,
|
||||||
|
precision: CountImplied,
|
||||||
|
width: CountImplied,
|
||||||
|
precision_span: None,
|
||||||
|
width_span: None,
|
||||||
|
ty: "abcd",
|
||||||
|
},
|
||||||
|
})]);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn format_counts() {
|
fn format_counts() {
|
||||||
use syntax_pos::{GLOBALS, Globals, edition};
|
use syntax_pos::{GLOBALS, Globals, edition};
|
||||||
GLOBALS.set(&Globals::new(edition::DEFAULT_EDITION), || {
|
GLOBALS.set(&Globals::new(edition::DEFAULT_EDITION), || {
|
||||||
same("{:10s}",
|
same(
|
||||||
&[NextArgument(Argument {
|
"{:10s}",
|
||||||
position: ArgumentImplicitlyIs(0),
|
&[NextArgument(Argument {
|
||||||
format: FormatSpec {
|
position: ArgumentImplicitlyIs(0),
|
||||||
fill: None,
|
format: FormatSpec {
|
||||||
align: AlignUnknown,
|
fill: None,
|
||||||
flags: 0,
|
align: AlignUnknown,
|
||||||
precision: CountImplied,
|
flags: 0,
|
||||||
width: CountIs(10),
|
precision: CountImplied,
|
||||||
ty: "s",
|
width: CountIs(10),
|
||||||
},
|
precision_span: None,
|
||||||
})]);
|
width_span: None,
|
||||||
same("{:10$.10s}",
|
ty: "s",
|
||||||
&[NextArgument(Argument {
|
},
|
||||||
position: ArgumentImplicitlyIs(0),
|
})]);
|
||||||
format: FormatSpec {
|
same(
|
||||||
fill: None,
|
"{:10$.10s}",
|
||||||
align: AlignUnknown,
|
&[NextArgument(Argument {
|
||||||
flags: 0,
|
position: ArgumentImplicitlyIs(0),
|
||||||
precision: CountIs(10),
|
format: FormatSpec {
|
||||||
width: CountIsParam(10),
|
fill: None,
|
||||||
ty: "s",
|
align: AlignUnknown,
|
||||||
},
|
flags: 0,
|
||||||
})]);
|
precision: CountIs(10),
|
||||||
same("{:.*s}",
|
width: CountIsParam(10),
|
||||||
&[NextArgument(Argument {
|
precision_span: None,
|
||||||
position: ArgumentImplicitlyIs(1),
|
width_span: Some(InnerSpan::new(3, 6)),
|
||||||
format: FormatSpec {
|
ty: "s",
|
||||||
fill: None,
|
},
|
||||||
align: AlignUnknown,
|
})]);
|
||||||
flags: 0,
|
same(
|
||||||
precision: CountIsParam(0),
|
"{:.*s}",
|
||||||
width: CountImplied,
|
&[NextArgument(Argument {
|
||||||
ty: "s",
|
position: ArgumentImplicitlyIs(1),
|
||||||
},
|
format: FormatSpec {
|
||||||
})]);
|
fill: None,
|
||||||
same("{:.10$s}",
|
align: AlignUnknown,
|
||||||
&[NextArgument(Argument {
|
flags: 0,
|
||||||
position: ArgumentImplicitlyIs(0),
|
precision: CountIsParam(0),
|
||||||
format: FormatSpec {
|
width: CountImplied,
|
||||||
fill: None,
|
precision_span: Some(InnerSpan::new(3, 5)),
|
||||||
align: AlignUnknown,
|
width_span: None,
|
||||||
flags: 0,
|
ty: "s",
|
||||||
precision: CountIsParam(10),
|
},
|
||||||
width: CountImplied,
|
})]);
|
||||||
ty: "s",
|
same(
|
||||||
},
|
"{:.10$s}",
|
||||||
})]);
|
&[NextArgument(Argument {
|
||||||
same("{:a$.b$s}",
|
position: ArgumentImplicitlyIs(0),
|
||||||
&[NextArgument(Argument {
|
format: FormatSpec {
|
||||||
position: ArgumentImplicitlyIs(0),
|
fill: None,
|
||||||
format: FormatSpec {
|
align: AlignUnknown,
|
||||||
fill: None,
|
flags: 0,
|
||||||
align: AlignUnknown,
|
precision: CountIsParam(10),
|
||||||
flags: 0,
|
width: CountImplied,
|
||||||
precision: CountIsName(Symbol::intern("b")),
|
precision_span: Some(InnerSpan::new(3, 7)),
|
||||||
width: CountIsName(Symbol::intern("a")),
|
width_span: None,
|
||||||
ty: "s",
|
ty: "s",
|
||||||
},
|
},
|
||||||
})]);
|
})]);
|
||||||
|
same(
|
||||||
|
"{:a$.b$s}",
|
||||||
|
&[NextArgument(Argument {
|
||||||
|
position: ArgumentImplicitlyIs(0),
|
||||||
|
format: FormatSpec {
|
||||||
|
fill: None,
|
||||||
|
align: AlignUnknown,
|
||||||
|
flags: 0,
|
||||||
|
precision: CountIsName(Symbol::intern("b")),
|
||||||
|
width: CountIsName(Symbol::intern("a")),
|
||||||
|
precision_span: None,
|
||||||
|
width_span: None,
|
||||||
|
ty: "s",
|
||||||
|
},
|
||||||
|
})]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn format_flags() {
|
fn format_flags() {
|
||||||
same("{:-}",
|
same(
|
||||||
&[NextArgument(Argument {
|
"{:-}",
|
||||||
position: ArgumentImplicitlyIs(0),
|
&[NextArgument(Argument {
|
||||||
format: FormatSpec {
|
position: ArgumentImplicitlyIs(0),
|
||||||
fill: None,
|
format: FormatSpec {
|
||||||
align: AlignUnknown,
|
fill: None,
|
||||||
flags: (1 << FlagSignMinus as u32),
|
align: AlignUnknown,
|
||||||
precision: CountImplied,
|
flags: (1 << FlagSignMinus as u32),
|
||||||
width: CountImplied,
|
precision: CountImplied,
|
||||||
ty: "",
|
width: CountImplied,
|
||||||
},
|
precision_span: None,
|
||||||
})]);
|
width_span: None,
|
||||||
same("{:+#}",
|
ty: "",
|
||||||
&[NextArgument(Argument {
|
},
|
||||||
position: ArgumentImplicitlyIs(0),
|
})]);
|
||||||
format: FormatSpec {
|
same(
|
||||||
fill: None,
|
"{:+#}",
|
||||||
align: AlignUnknown,
|
&[NextArgument(Argument {
|
||||||
flags: (1 << FlagSignPlus as u32) | (1 << FlagAlternate as u32),
|
position: ArgumentImplicitlyIs(0),
|
||||||
precision: CountImplied,
|
format: FormatSpec {
|
||||||
width: CountImplied,
|
fill: None,
|
||||||
ty: "",
|
align: AlignUnknown,
|
||||||
},
|
flags: (1 << FlagSignPlus as u32) | (1 << FlagAlternate as u32),
|
||||||
})]);
|
precision: CountImplied,
|
||||||
|
width: CountImplied,
|
||||||
|
precision_span: None,
|
||||||
|
width_span: None,
|
||||||
|
ty: "",
|
||||||
|
},
|
||||||
|
})]);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn format_mixture() {
|
fn format_mixture() {
|
||||||
same("abcd {3:a} efg",
|
same(
|
||||||
&[String("abcd "),
|
"abcd {3:a} efg",
|
||||||
NextArgument(Argument {
|
&[
|
||||||
position: ArgumentIs(3),
|
String("abcd "),
|
||||||
format: FormatSpec {
|
NextArgument(Argument {
|
||||||
fill: None,
|
position: ArgumentIs(3),
|
||||||
align: AlignUnknown,
|
format: FormatSpec {
|
||||||
flags: 0,
|
fill: None,
|
||||||
precision: CountImplied,
|
align: AlignUnknown,
|
||||||
width: CountImplied,
|
flags: 0,
|
||||||
ty: "a",
|
precision: CountImplied,
|
||||||
},
|
width: CountImplied,
|
||||||
}),
|
precision_span: None,
|
||||||
String(" efg")]);
|
width_span: None,
|
||||||
|
ty: "a",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
String(" efg"),
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue