Implement new formatter for 'int'.

This is used for constants and patterns, which can carry negative
   values.
This commit is contained in:
KtorZ 2023-07-06 19:14:45 +02:00 committed by Lucas
parent 78d34f7f76
commit 126f2ab004
2 changed files with 22 additions and 1 deletions

View File

@ -702,7 +702,10 @@ impl<'comments> Formatter<'comments> {
}
pub fn int<'a>(&mut self, s: &'a str, base: &Base) -> Document<'a> {
unimplemented!()
match s.chars().next() {
Some('-') => Document::Str("-").append(self.uint(&s[1..], base)),
_ => self.uint(s, base),
}
}
pub fn uint<'a>(&mut self, s: &'a str, base: &Base) -> Document<'a> {

View File

@ -887,3 +887,21 @@ fn first_class_binop() {
assert_fmt(src, src);
}
#[test]
fn int_uint() {
let src = indoc! { r#"
const i = 42
const j = -14
fn foo() {
when y is {
14 -> -14
-42 -> 42
}
}
"#};
assert_fmt(src, src);
}