Implement new formatter for 'int'.
This is used for constants and patterns, which can carry negative values.
This commit is contained in:
parent
78d34f7f76
commit
126f2ab004
|
@ -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> {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue