mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
Add test_format_bool
This commit is contained in:
parent
cf2f6e9f72
commit
76f2ed0cee
1 changed files with 36 additions and 0 deletions
|
@ -1041,6 +1041,42 @@ mod tests {
|
|||
assert_eq!(FormatSpec::parse("<>-#23,.11b"), expected);
|
||||
}
|
||||
|
||||
fn format_bool(text: &str, value: bool) -> Result<String, FormatSpecError> {
|
||||
FormatSpec::parse(text).and_then(|spec| spec.format_bool(value))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_bool() {
|
||||
assert_eq!(format_bool("b", true), Ok("1".to_owned()));
|
||||
assert_eq!(format_bool("b", false), Ok("0".to_owned()));
|
||||
assert_eq!(format_bool("d", true), Ok("1".to_owned()));
|
||||
assert_eq!(format_bool("d", false), Ok("0".to_owned()));
|
||||
assert_eq!(format_bool("o", true), Ok("1".to_owned()));
|
||||
assert_eq!(format_bool("o", false), Ok("0".to_owned()));
|
||||
assert_eq!(format_bool("n", true), Ok("1".to_owned()));
|
||||
assert_eq!(format_bool("n", false), Ok("0".to_owned()));
|
||||
assert_eq!(format_bool("x", true), Ok("1".to_owned()));
|
||||
assert_eq!(format_bool("x", false), Ok("0".to_owned()));
|
||||
assert_eq!(format_bool("X", true), Ok("1".to_owned()));
|
||||
assert_eq!(format_bool("X", false), Ok("0".to_owned()));
|
||||
assert_eq!(format_bool("g", true), Ok("1".to_owned()));
|
||||
assert_eq!(format_bool("g", false), Ok("0".to_owned()));
|
||||
assert_eq!(format_bool("G", true), Ok("1".to_owned()));
|
||||
assert_eq!(format_bool("G", false), Ok("0".to_owned()));
|
||||
assert_eq!(format_bool("c", true), Ok("\x01".to_owned()));
|
||||
assert_eq!(format_bool("c", false), Ok("\x00".to_owned()));
|
||||
assert_eq!(format_bool("e", true), Ok("1.000000e+00".to_owned()));
|
||||
assert_eq!(format_bool("e", false), Ok("0.000000e+00".to_owned()));
|
||||
assert_eq!(format_bool("E", true), Ok("1.000000E+00".to_owned()));
|
||||
assert_eq!(format_bool("E", false), Ok("0.000000E+00".to_owned()));
|
||||
assert_eq!(format_bool("f", true), Ok("1.000000".to_owned()));
|
||||
assert_eq!(format_bool("f", false), Ok("0.000000".to_owned()));
|
||||
assert_eq!(format_bool("F", true), Ok("1.000000".to_owned()));
|
||||
assert_eq!(format_bool("F", false), Ok("0.000000".to_owned()));
|
||||
assert_eq!(format_bool("%", true), Ok("100.000000%".to_owned()));
|
||||
assert_eq!(format_bool("%", false), Ok("0.000000%".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_int() {
|
||||
assert_eq!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue