feat: add back single ampersand

This commit is contained in:
electria 2026-07-24 21:57:30 -07:00
commit 262c55b91a
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -34,17 +34,31 @@ pub fn parse_and_calc_humanreadable(mut input: String) -> String {
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);
format!(
"{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),
)
}
#[test]
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");
}
pub fn parse_and_calc(s: &str) -> Float {