feat: add back single ampersand
This commit is contained in:
parent
704ef81816
commit
262c55b91a
1 changed files with 15 additions and 1 deletions
16
src/main.rs
16
src/main.rs
|
|
@ -34,17 +34,31 @@ pub fn parse_and_calc_humanreadable(mut input: String) -> String {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// no need to remove the character here,
|
||||||
|
// as we ignore the ampersand in all other logic already
|
||||||
|
let should_add_back_alignment = input.contains('&');
|
||||||
|
|
||||||
let result = parse_and_calc(&input);
|
let result = parse_and_calc(&input);
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"{0}{result:.1$}",
|
"{0}{result:.1$}",
|
||||||
if should_add_back_equals { "= " } else { "" },
|
if should_add_back_equals && should_add_back_alignment {
|
||||||
|
"& = "
|
||||||
|
} else if should_add_back_equals {
|
||||||
|
"= "
|
||||||
|
} else if should_add_back_alignment {
|
||||||
|
"& "
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
get_significant_digits(&result),
|
get_significant_digits(&result),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_equals_readdition() {
|
fn test_equals_readdition() {
|
||||||
assert_eq!(parse_and_calc_humanreadable(" = 11".into()), "= 11");
|
assert_eq!(parse_and_calc_humanreadable(" = 11".into()), "= 11");
|
||||||
|
assert_eq!(parse_and_calc_humanreadable(" &= 11".into()), "& = 11");
|
||||||
|
assert_eq!(parse_and_calc_humanreadable(" & 11".into()), "& 11");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_and_calc(s: &str) -> Float {
|
pub fn parse_and_calc(s: &str) -> Float {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue