Skip to content

Commit

Permalink
trailing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierverdier committed Jan 16, 2016
1 parent 045d5a5 commit 51cdc48
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ successOrNothing (exitCode, output, _) =
if exitCode == ExitSuccess then Just output else Nothing

safeRun :: String -> [String] -> IO (Maybe String)
safeRun command arguments =
safeRun command arguments =
do -- IO
output <- readProcessWithExitCode command arguments ""
return (successOrNothing output)
Expand Down
20 changes: 10 additions & 10 deletions src/src/BranchParse.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module BranchParse where

import Control.Applicative (liftA, liftA2)
import Text.Parsec (digit, string, char, eof, anyChar,
import Text.Parsec (digit, string, char, eof, anyChar,
many, many1, manyTill, noneOf, between,
parse, ParseError, (<|>), try)
import Text.Parsec.String (Parser)
Expand Down Expand Up @@ -48,7 +48,7 @@ isValidBranch b = not (or (isForbidden b)) where


instance Arbitrary Branch where
arbitrary =
arbitrary =
do -- Gen
branch <- arbitrary `suchThat` isValidBranch
return (MkBranch branch)
Expand All @@ -63,7 +63,7 @@ data BranchInfo = MkBranchInfo Branch (Maybe Remote) deriving (Eq, Show)
type MBranchInfo = Maybe BranchInfo

newRepo :: Parser MBranchInfo
newRepo =
newRepo =
do -- Parsec
string "Initial commit on "
branch <- many anyChar
Expand All @@ -72,20 +72,20 @@ newRepo =
return (Just bi)

noBranch :: Parser MBranchInfo
noBranch =
noBranch =
do -- Parsec
manyTill anyChar (try (string " (no branch)"))
eof
return Nothing

trackedBranch :: Parser Branch
trackedBranch =
trackedBranch =
do -- Parsec
b <- manyTill anyChar (try (string "..."))
return (MkBranch b)

branchRemoteTracking :: Parser MBranchInfo
branchRemoteTracking =
branchRemoteTracking =
do -- Parsec
branch <- trackedBranch
tracking <- many (noneOf " ")
Expand All @@ -97,7 +97,7 @@ branchRemoteTracking =


branchRemote :: Parser MBranchInfo
branchRemote =
branchRemote =
do -- Parsec
branch <- trackedBranch
tracking <- many (noneOf " ")
Expand All @@ -107,15 +107,15 @@ branchRemote =
return (Just bi)

branchOnly :: Parser MBranchInfo
branchOnly =
branchOnly =
do -- Parsec
branch <- many (noneOf " ")
eof
let bi = MkBranchInfo (MkBranch branch) Nothing
return (Just bi)

branchParser :: Parser MBranchInfo
branchParser =
branchParser =
try noBranch
<|> try newRepo
<|> try branchRemoteTracking
Expand All @@ -132,7 +132,7 @@ inBrackets :: Parser Distance
inBrackets = between (char '[') (char ']') (behind <|> try aheadBehind <|> ahead)

makeAheadBehind :: String -> (Int -> Distance) -> Parser Distance
makeAheadBehind name constructor =
makeAheadBehind name constructor =
do -- Parsec
string (name ++ " ")
dist <- many1 digit
Expand Down
10 changes: 4 additions & 6 deletions src/src/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ processBranch = rightOrNothing . branchInfo

processGitStatus :: [String] -> Maybe GitInfo
processGitStatus [] = Nothing
processGitStatus (branchLine:statusLines) =
processGitStatus (branchLine:statusLines) =
do -- Maybe
mbranch <- processBranch branchLine
status <- processStatus statusLines
return (MkGitInfo mbranch status)

showStatusNumbers :: Status Int -> [String]
showStatusNumbers (MakeStatus s x c t) =
showStatusNumbers (MakeStatus s x c t) =
do -- List
nb <- [s, x, c, t]
return (show nb)

showRemoteNumbers :: Maybe Remote -> [String]
showRemoteNumbers mremote =
showRemoteNumbers mremote =
do -- List
ab <- [ahead, behind]
return (show ab)
Expand All @@ -55,7 +55,7 @@ branchOrHashWith c (Just hash) Nothing = MkBranchInfo (MkBranch (c : getHash has
branchOrHashWith _ Nothing _ = MkBranchInfo (MkBranch "") Nothing

showGitInfo :: Maybe Hash
-> GitInfo
-> GitInfo
-> [String]
showGitInfo mhash (MkGitInfo bi stat) = branchInfoString ++ showStatusNumbers stat
where
Expand All @@ -67,5 +67,3 @@ stringsFromStatus :: Maybe Hash
stringsFromStatus h status = do -- List
processed <- processGitStatus (lines status)
return (showGitInfo h processed)


13 changes: 6 additions & 7 deletions src/test/TestBranchParse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ checkRight b s = expectRight b (branchInfo ("## " ++ s))
-- gitRep (MkBranchInfo (MkBranch branch) Nothing) = branch
-- gitRep (MkBranchInfo (MkBranch branch) (MkRemote (Just (MkBranch rem)) Nothing)) = branch ++ "..." ++ rem
-- gitRep (MkBranchInfo (MkBranch branch) (MkRemote (Just (MkBranch rem)) (Just dis))) = gitRep (MkBranchInfo branch $ MkRemote (Just rem) Nothing) ++ show dis
--
--
{- Test -}

propNoBranch :: Branch -> Bool
Expand All @@ -29,13 +29,13 @@ propNoBranch b =

propNewRepo :: Branch -> Bool
propNewRepo b =
checkRight
checkRight
(Just (MkBranchInfo b Nothing))
("Initial commit on " ++ show b)

propBranchOnly :: Branch -> Bool
propBranchOnly b =
checkRight
propBranchOnly b =
checkRight
(Just (MkBranchInfo b Nothing))
(show b)

Expand All @@ -48,8 +48,8 @@ propBranchRemote b t =
remote = Just (MkRemote t Nothing)

propBranchRemoteTracking :: Branch -> Branch -> Distance -> Bool
propBranchRemoteTracking b t distance =
checkRight
propBranchRemoteTracking b t distance =
checkRight
(Just (MkBranchInfo b remote))
(show b ++ "..." ++ show t ++ " " ++ show distance)
where
Expand All @@ -74,4 +74,3 @@ main :: IO()
main = do -- IO
results <- runTests
unless (all isSuccess results) exitFailure

0 comments on commit 51cdc48

Please sign in to comment.