File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -2548,7 +2548,7 @@ impl<'comments> Formatter<'comments> {
25482548 fn negate_int < ' a > ( & mut self , expr : & ' a UntypedExpr ) -> Document < ' a > {
25492549 match expr {
25502550 UntypedExpr :: NegateInt { value, .. } => self . expr ( value) ,
2551- UntypedExpr :: Int { value, .. } if value. starts_with ( '-' ) => self . int ( value) ,
2551+ UntypedExpr :: Int { value, .. } if value. starts_with ( '-' ) => self . int ( & value[ 1 .. ] ) ,
25522552 UntypedExpr :: BinOp { .. } => "- " . to_doc ( ) . append ( self . expr ( expr) ) ,
25532553
25542554 _ => docvec ! [ "-" , self . expr( expr) ] ,
Original file line number Diff line number Diff line change @@ -6733,3 +6733,46 @@ fn format_panic_as_with_block_message() {
67336733"#
67346734 ) ;
67356735}
6736+
6737+ // https://github.com/gleam-lang/gleam/issues/5056
6738+ #[ test]
6739+ fn remove_redundant_negation_from_literal_int_1 ( ) {
6740+ assert_format_rewrite ! (
6741+ "pub fn main() {
6742+ --1
6743+ }
6744+ " ,
6745+ "pub fn main() {
6746+ 1
6747+ }
6748+ "
6749+ ) ;
6750+ }
6751+
6752+ #[ test]
6753+ fn remove_redundant_negation_from_literal_int_2 ( ) {
6754+ assert_format_rewrite ! (
6755+ "pub fn main() {
6756+ ---1
6757+ }
6758+ " ,
6759+ "pub fn main() {
6760+ -1
6761+ }
6762+ "
6763+ ) ;
6764+ }
6765+
6766+ #[ test]
6767+ fn remove_redundant_negation_from_literal_int_3 ( ) {
6768+ assert_format_rewrite ! (
6769+ "pub fn main() {
6770+ ----1
6771+ }
6772+ " ,
6773+ "pub fn main() {
6774+ 1
6775+ }
6776+ "
6777+ ) ;
6778+ }
You can’t perform that action at this time.
0 commit comments