Skip to content

Commit 472d2f1

Browse files
committed
Move formatRejections top level and doctest
1 parent 538d0ab commit 472d2f1

File tree

1 file changed

+26
-15
lines changed
  • cabal-install-solver/src/Distribution/Solver/Modular

1 file changed

+26
-15
lines changed

cabal-install-solver/src/Distribution/Solver/Modular/Message.hs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,6 @@ showMessages = go 0
102102
(atLevel l $ formatRejections (map (showQPNPOpt qpn) (reverse is)) ++ showFR c fr)
103103
(go l ms)
104104

105-
formatRejections :: [String] -> String
106-
formatRejections [x] = "rejecting: " ++ x
107-
formatRejections xs = "rejecting: " ++ case L.nub prefixes of
108-
[prefix] -> prefix ++ "; " ++ L.intercalate ", " versions
109-
_ -> L.intercalate ", " xs
110-
where
111-
(prefixes, versions) = unzip
112-
[ maybe (x, "") (\hyphen -> (take hyphen x, drop (hyphen + 1) x)) ix
113-
| x <- xs
114-
-- Package names may contain hypens but a hypen is also the separator
115-
-- between the package name and its version so find the last hyphen in
116-
-- the string.
117-
, let ix = listToMaybe (reverse $ L.elemIndices '-' x)
118-
]
119-
120105
-- Handle many subsequent skipped package instances.
121106
goPSkip :: Int
122107
-> QPN
@@ -138,6 +123,32 @@ showMessages = go 0
138123
let s = show l
139124
in Step ("[" ++ replicate (3 - length s) '_' ++ s ++ "] " ++ x) xs
140125

126+
-- | Format a list of package names and versions as a rejection message,
127+
-- avoiding repetition of the package name.
128+
-- >>> formatRejections ["foo-1.0.0", "foo-1.0.1", "foo-1.0.2"]
129+
-- "rejecting: foo; 1.0.0, 1.0.1, 1.0.2"
130+
-- >>> formatRejections ["foo-1.0.0"]
131+
-- "rejecting: foo-1.0.0"
132+
-- >>> formatRejections ["foo-1.0.0", "bar-1.0.0"]
133+
-- "rejecting: foo-1.0.0, bar-1.0.0"
134+
-- >>> formatRejections []
135+
-- "unexpected rejection set"
136+
formatRejections :: [String] -> String
137+
formatRejections [] = "unexpected rejection set"
138+
formatRejections [x] = "rejecting: " ++ x
139+
formatRejections xs = "rejecting: " ++ case L.nub prefixes of
140+
[prefix] -> prefix ++ "; " ++ L.intercalate ", " versions
141+
_ -> L.intercalate ", " xs
142+
where
143+
(prefixes, versions) = unzip
144+
[ maybe (x, "") (\hyphen -> (take hyphen x, drop (hyphen + 1) x)) ix
145+
| x <- xs
146+
-- Package names may contain hypens but a hypen is also the separator
147+
-- between the package name and its version so find the last hyphen in
148+
-- the string.
149+
, let ix = listToMaybe (reverse $ L.elemIndices '-' x)
150+
]
151+
141152
-- | Display the set of 'Conflicts' for a skipped package version.
142153
showConflicts :: Set CS.Conflict -> String
143154
showConflicts conflicts =

0 commit comments

Comments
 (0)