@@ -1004,6 +1004,76 @@ removeImportTests = testGroup "remove import actions"
1004
1004
, " x = a -- Must use something from module A, but not (@.)"
1005
1005
]
1006
1006
liftIO $ expectedContentAfterAction @=? contentAfterAction
1007
+ , testSession " remove redundant record field import" $ do
1008
+ let contentA = T. unlines
1009
+ [ " module ModuleA where"
1010
+ , " data A = A {"
1011
+ , " a1 :: String,"
1012
+ , " a2 :: Int"
1013
+ , " }"
1014
+ , " newA = A \" foo\" 42"
1015
+ ]
1016
+ _docA <- createDoc " ModuleA.hs" " haskell" contentA
1017
+ let contentB = T. unlines
1018
+ [ " {-# OPTIONS_GHC -Wunused-imports #-}"
1019
+ , " module ModuleB where"
1020
+ , " import ModuleA"
1021
+ , " ( A (a1, a2),"
1022
+ , " newA"
1023
+ , " )"
1024
+ , " x = a1 newA"
1025
+ ]
1026
+ docB <- createDoc " ModuleB.hs" " haskell" contentB
1027
+ _ <- waitForDiagnostics
1028
+ action <- pickActionWithTitle " Remove A(a2) from import" =<< getCodeActions docB (R 2 0 5 3 )
1029
+ executeCodeAction action
1030
+ contentAfterAction <- documentContents docB
1031
+ let expectedContentAfterAction = T. unlines
1032
+ [ " {-# OPTIONS_GHC -Wunused-imports #-}"
1033
+ , " module ModuleB where"
1034
+ , " import ModuleA"
1035
+ , " ( A (a1),"
1036
+ , " newA"
1037
+ , " )"
1038
+ , " x = a1 newA"
1039
+ ]
1040
+ liftIO $ expectedContentAfterAction @=? contentAfterAction
1041
+ , testSession " remove multiple redundant record field imports" $ do
1042
+ let contentA = T. unlines
1043
+ [ " module ModuleA where"
1044
+ , " data A = A {"
1045
+ , " a1 :: String,"
1046
+ , " a2 :: Int,"
1047
+ , " a3 :: Int,"
1048
+ , " a4 :: Int"
1049
+ , " }"
1050
+ , " newA = A \" foo\" 2 3 4"
1051
+ ]
1052
+ _docA <- createDoc " ModuleA.hs" " haskell" contentA
1053
+ let contentB = T. unlines
1054
+ [ " {-# OPTIONS_GHC -Wunused-imports #-}"
1055
+ , " module ModuleB where"
1056
+ , " import ModuleA"
1057
+ , " ( A (a1, a2, a3, a4),"
1058
+ , " newA"
1059
+ , " )"
1060
+ , " x = a2 newA"
1061
+ ]
1062
+ docB <- createDoc " ModuleB.hs" " haskell" contentB
1063
+ _ <- waitForDiagnostics
1064
+ action <- pickActionWithTitle " Remove A(a1), A(a3), A(a4) from import" =<< getCodeActions docB (R 2 0 5 3 )
1065
+ executeCodeAction action
1066
+ contentAfterAction <- documentContents docB
1067
+ let expectedContentAfterAction = T. unlines
1068
+ [ " {-# OPTIONS_GHC -Wunused-imports #-}"
1069
+ , " module ModuleB where"
1070
+ , " import ModuleA"
1071
+ , " ( A (a2),"
1072
+ , " newA"
1073
+ , " )"
1074
+ , " x = a2 newA"
1075
+ ]
1076
+ liftIO $ expectedContentAfterAction @=? contentAfterAction
1007
1077
]
1008
1078
1009
1079
extendImportTests :: TestTree
0 commit comments