Skip to content

Commit

Permalink
BranchInfo is a data type
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierverdier committed Jan 31, 2015
1 parent e054212 commit 86dafd4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/BranchParse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ instance Arbitrary Branch where
arbitrary = MkBranch <$> arbitrary `suchThat` isValidBranch


type BranchInfo = ((Maybe Branch, Maybe Branch), Maybe Distance)
data BranchInfo = MkBranchInfo (Maybe Branch) (Maybe Branch) (Maybe Distance) deriving (Eq, Show)

noBranchInfo :: BranchInfo
noBranchInfo = ((Nothing, Nothing), Nothing)
noBranchInfo = MkBranchInfo Nothing Nothing Nothing

newRepo :: Parser BranchInfo
newRepo =
fmap (\ branch -> ((Just $ MkBranch branch, Nothing), Nothing))
fmap (\ branch -> MkBranchInfo (Just $ MkBranch branch) Nothing Nothing)
$ string "Initial commit on " *> many anyChar <* eof

noBranch :: Parser BranchInfo
Expand All @@ -69,20 +69,20 @@ trackedBranch = MkBranch <$> manyTill anyChar (try $ string "...")

branchRemoteTracking :: Parser BranchInfo
branchRemoteTracking =
(\ branch tracking behead -> ((Just branch, Just $ MkBranch tracking), Just behead))
(\ branch tracking behead -> MkBranchInfo (Just branch) (Just $ MkBranch tracking) (Just behead))
<$> trackedBranch
<*> many (noneOf " ") <* char ' '
<*> inBrackets

branchRemote :: Parser BranchInfo
branchRemote =
(\ branch tracking -> ((Just branch, Just $ MkBranch tracking), Nothing))
(\ branch tracking -> MkBranchInfo (Just branch) (Just $ MkBranch tracking) Nothing)
<$> trackedBranch
<*> many (noneOf " ") <* eof

branchOnly :: Parser BranchInfo
branchOnly =
(\ branch -> ((Just $ MkBranch branch, Nothing), Nothing))
(\ branch -> MkBranchInfo (Just $ MkBranch branch) Nothing Nothing)
<$> many (noneOf " ") <* eof

branchParser :: Parser BranchInfo
Expand Down
4 changes: 2 additions & 2 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import System.Process (readProcessWithExitCode)
import System.Exit (ExitCode(ExitSuccess))
import Data.Maybe (fromMaybe)
import Control.Applicative ((<$>), (<*>))
import BranchParse (Branch(MkBranch), BranchInfo, branchInfo, Distance, pairFromDistance)
import BranchParse (Branch(MkBranch), BranchInfo(MkBranchInfo), branchInfo, Distance, pairFromDistance)
import StatusParse (Status(MakeStatus), processStatus)
import Data.List (intercalate)

Expand Down Expand Up @@ -63,7 +63,7 @@ branchOrHash branch =
Just (MkBranch bn) -> return bn

allInfo :: (BranchInfo, Status Int) -> (IO String, Numbers)
allInfo (((branch, _), behead), stat) = (branchOrHash branch, showBranchNumbers behead ++ showStatusNumbers stat)
allInfo ((MkBranchInfo branch _ behead), stat) = (branchOrHash branch, showBranchNumbers behead ++ showStatusNumbers stat)

ioStrings :: (IO String, Numbers) -> IO [String]
ioStrings (ios,ss) = (: ss) <$> ios
Expand Down
12 changes: 6 additions & 6 deletions src/TestBranchParse.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BranchParse (BranchInfo, branchInfo, Distance, Branch(MkBranch))
import BranchParse (BranchInfo(MkBranchInfo), branchInfo, Distance, Branch(MkBranch), noBranchInfo)
import Test.QuickCheck (property, stdArgs, maxSuccess, quickCheckWith)


Expand All @@ -16,31 +16,31 @@ checkRight b s = expectRight b $ branchInfo s
propNoBranch :: Branch -> Bool
propNoBranch (MkBranch s) =
checkRight
((Nothing, Nothing), Nothing)
noBranchInfo
$ s ++ " (no branch)"

propNewRepo :: Branch -> Bool
propNewRepo b@(MkBranch s) =
checkRight
((Just b, Nothing), Nothing)
(MkBranchInfo (Just b) Nothing Nothing)
$ "Initial commit on " ++ s

propBranchOnly :: Branch -> Bool
propBranchOnly b@(MkBranch s) =
checkRight
((Just b, Nothing), Nothing)
(MkBranchInfo (Just b) Nothing Nothing)
s

propBranchRemote :: Branch -> Branch -> Bool
propBranchRemote b'@(MkBranch b) t'@(MkBranch t) =
checkRight
((Just b', Just t'), Nothing)
(MkBranchInfo (Just b') (Just t') Nothing)
$ b ++"..." ++ t

propBranchRemoteTracking :: Branch -> Branch -> Distance -> Bool
propBranchRemoteTracking b'@(MkBranch b) t'@(MkBranch t) distance =
checkRight
((Just b', Just t'), Just distance)
(MkBranchInfo (Just b') (Just t') (Just distance))
$ b ++ "..." ++ t ++ " " ++ show distance

main :: IO()
Expand Down

0 comments on commit 86dafd4

Please sign in to comment.