Fix minimize-parens feature, Add a few basic tests
parent
54043ca9ba
commit
b3f8317e99
|
@ -0,0 +1,27 @@
|
||||||
|
#group feature/minimize-parens
|
||||||
|
|
||||||
|
#golden minimize parens basic test
|
||||||
|
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||||
|
func = func (abc) (def)
|
||||||
|
#expected
|
||||||
|
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||||
|
func = func abc def
|
||||||
|
|
||||||
|
#test minimize parens test that it keep necessary parens
|
||||||
|
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||||
|
func = func (abc False) ("asd" ++ "def")
|
||||||
|
|
||||||
|
|
||||||
|
#golden minimize nested parens 1
|
||||||
|
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||||
|
func = func ((((((((nested))))))))
|
||||||
|
#expected
|
||||||
|
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||||
|
func = func nested
|
||||||
|
|
||||||
|
#golden minimize nested parens 2
|
||||||
|
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||||
|
func = func ((((((((nested + expression))))))))
|
||||||
|
#expected
|
||||||
|
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
||||||
|
func = func (nested + expression)
|
|
@ -1060,13 +1060,6 @@ func = do
|
||||||
)
|
)
|
||||||
`shouldReturn` thing
|
`shouldReturn` thing
|
||||||
|
|
||||||
#golden minimize parens basic test
|
|
||||||
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
|
||||||
func = func (abc) (def)
|
|
||||||
#expected
|
|
||||||
-- brittany { lconfig_operatorParenthesisRefactorMode: PRMMinimize }
|
|
||||||
func = func abc def
|
|
||||||
|
|
||||||
#test wandering comment at end of datadecl
|
#test wandering comment at end of datadecl
|
||||||
data ReformatParenMode
|
data ReformatParenMode
|
||||||
= ReformatParenModeKeep -- don't modify parens at all
|
= ReformatParenModeKeep -- don't modify parens at all
|
||||||
|
|
|
@ -185,7 +185,12 @@ addAllParens topLevelParen = \case
|
||||||
remSuperfluousParens :: Int -> OpTree -> OpTree
|
remSuperfluousParens :: Int -> OpTree -> OpTree
|
||||||
remSuperfluousParens outerFixity = \case
|
remSuperfluousParens outerFixity = \case
|
||||||
x@OpLeaf{} -> x
|
x@OpLeaf{} -> x
|
||||||
OpUnknown _ locO locC c [] -> OpUnknown NoParen locO locC c []
|
OpUnknown _ locO locC c@(OpLeaf doc) [] | isLit doc ->
|
||||||
|
OpUnknown NoParen locO locC c []
|
||||||
|
OpUnknown _ locO locC c@(OpUnknown ParenWithSpace _ _ _ _) [] ->
|
||||||
|
OpUnknown NoParen locO locC (remSuperfluousParens 11 c) []
|
||||||
|
OpUnknown _ locO locC c@(OpUnknown ParenNoSpace _ _ _ _) [] ->
|
||||||
|
OpUnknown NoParen locO locC (remSuperfluousParens 11 c) []
|
||||||
x@OpUnknown{} -> x
|
x@OpUnknown{} -> x
|
||||||
OpKnown paren locO locC fixity c cs ->
|
OpKnown paren locO locC fixity c cs ->
|
||||||
OpKnown
|
OpKnown
|
||||||
|
@ -200,7 +205,22 @@ remSuperfluousParens outerFixity = \case
|
||||||
fixity
|
fixity
|
||||||
(remSuperfluousParens (fixLevel fixity) c)
|
(remSuperfluousParens (fixLevel fixity) c)
|
||||||
[ (op, remSuperfluousParens (fixLevel fixity) tree) | (op, tree) <- cs ]
|
[ (op, remSuperfluousParens (fixLevel fixity) tree) | (op, tree) <- cs ]
|
||||||
where fixLevel (Fixity _ i _) = i
|
where
|
||||||
|
fixLevel (Fixity _ i _) = i
|
||||||
|
isLit = \case
|
||||||
|
(_, BDFlushCommentsPrior _ x ) -> isLit x
|
||||||
|
(_, BDFlushCommentsPost _ _ x) -> isLit x
|
||||||
|
(_, BDQueueComments _ x ) -> isLit x
|
||||||
|
(_, BDEntryDelta _ x ) -> isLit x
|
||||||
|
(_, BDForceAlt _ x ) -> isLit x
|
||||||
|
(_, BDDebug _ x ) -> isLit x
|
||||||
|
(_, BDAddBaseY _ x ) -> isLit x
|
||||||
|
(_, BDBaseYPushCur x ) -> isLit x
|
||||||
|
(_, BDIndentLevelPushCur x ) -> isLit x
|
||||||
|
(_, BDIndentLevelPop x ) -> isLit x
|
||||||
|
(_, BDLit{} ) -> True
|
||||||
|
_ -> False
|
||||||
|
|
||||||
|
|
||||||
hardcodedFixity :: Bool -> String -> Maybe Fixity
|
hardcodedFixity :: Bool -> String -> Maybe Fixity
|
||||||
hardcodedFixity allowUnqualify = \case
|
hardcodedFixity allowUnqualify = \case
|
||||||
|
|
Loading…
Reference in New Issue