fixed fmt

This commit is contained in:
TheAnyKey committed 2020-04-29 17:52:47 -04:00
1 parent 8e8e839b94
commit 3ccb117b9a
1 file changed
+23 -25
+23 -25
View File
@@ -27,7 +27,7 @@ impl<'a> FStringParser<'a> {
let mut delims = Vec::new();
let mut conversion = None;
let mut pred_expression_text = String::new();
let mut trailing_seq=String::new();
let mut trailing_seq = String::new();
while let Some(ch) = self.chars.next() {
match ch {
@@ -77,7 +77,8 @@ impl<'a> FStringParser<'a> {
// match a python 3.8 self documenting expression
// format '{' PYTHON_EXPRESSION '=' FORMAT_SPECIFIER? '}'
'=' if self.chars.peek() != Some(&'=') => { // check for delims empty?
'=' if self.chars.peek() != Some(&'=') => {
// check for delims empty?
pred_expression_text = expression.to_string(); // safe expression before = to print it
}
@@ -161,28 +162,25 @@ impl<'a> FStringParser<'a> {
conversion,
spec,
});
}
else {
return Ok(Joined{
values:vec![
Constant{
value:pred_expression_text.to_owned()+"="
},
Constant {
value:trailing_seq.to_owned()
},
FormattedValue {
} else {
return Ok(Joined {
values: vec![
Constant {
value: pred_expression_text.to_owned() + "=",
},
Constant {
value: trailing_seq.to_owned(),
},
FormattedValue {
value: Box::new(
parse_expression(expression.trim())
.map_err(|e| InvalidExpression(Box::new(e.error)))?,
),
conversion,
spec,},
]
}
);
spec,
},
],
});
}
}
'"' | '\'' => {
@@ -360,24 +358,24 @@ mod tests {
#[test]
fn test_fstring_parse_selfdocumenting_base() {
let src=String::from("{user=}");
let parse_ast=parse_fstring(&src);
let src = String::from("{user=}");
let parse_ast = parse_fstring(&src);
assert!(parse_ast.is_ok());
}
#[test]
fn test_fstring_parse_selfdocumenting_base_more() {
let src=String::from("mix {user=} with text and {second=}");
let parse_ast=parse_fstring(&src);
let src = String::from("mix {user=} with text and {second=}");
let parse_ast = parse_fstring(&src);
assert!(parse_ast.is_ok());
}
#[test]
fn test_fstring_parse_selfdocumenting_format() {
let src=String::from("{user=:>10}");
let parse_ast=parse_fstring(&src);
let src = String::from("{user=:>10}");
let parse_ast = parse_fstring(&src);
assert!(parse_ast.is_ok());
}