Skip to content

Commit

Permalink
allow for && to indicate conjunction
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Nelson committed Sep 7, 2016
1 parent 65ffa7e commit 4d99eee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Data/SemVer/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ pJoinedSemVerRange :: Parser SemVerRange
pJoinedSemVerRange = do
first <- pSemVerRangeSingle
option first $ do
lookAhead (sstring "||" <|> map singleton anyChar) >>= \case
let next = choice [sstring "||", sstring "&&", map singleton anyChar]
lookAhead next >>= \case
"||" -> Or first <$> (sstring "||" *> pJoinedSemVerRange)
"&&" -> And first <$> (sstring "&&" *> pJoinedSemVerRange)
_ -> And first <$> pJoinedSemVerRange

-- | Parses a hyphenated range.
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ main = hspec $ do
`shouldBeR` Geq (semver'' 1 2 3 ["pre"] ["asdf"])
`And` Lt (semver'' 2 4 3 ["pre"] ["asdf"])

it "should parse semvers with && instead of spaces" $ do
let expected = Geq (semver 2 0 0) `And` Leq (semver 2 15 0)
parseSemVerRange ">= 2 && <= 2.14" `shouldBeR` expected

it "should fail when it's wrong" $ do
shouldBeL (parseSemVerRange "xyz")

Expand Down

0 comments on commit 4d99eee

Please sign in to comment.