1
1
mirror of https://github.com/sol/hpack.git synced 2024-10-04 11:47:15 +03:00

Accept name/version for system-build-tools

This commit is contained in:
Simon Hengel 2018-09-08 07:38:11 +08:00
parent ac4d95e936
commit 132d92ce64
3 changed files with 23 additions and 7 deletions

View File

@ -70,14 +70,15 @@ newtype SystemBuildTools = SystemBuildTools {
} deriving (Show, Eq, Semigroup, Monoid)
instance FromValue SystemBuildTools where
fromValue v = case v of
String s -> fromList . return <$> parseSystemBuildTool s
Array xs -> fromList <$> parseArray (withText parseSystemBuildTool) xs
Object _ -> SystemBuildTools <$> fromValue v
_ -> typeMismatch "Array, Object, or String" v
fromValue = fmap (SystemBuildTools . Map.fromList) . parseDependencies parse
where
fromList :: [(String, DependencyVersion)] -> SystemBuildTools
fromList = SystemBuildTools . Map.fromList
parse :: Parse String DependencyVersion
parse = Parse {
parseString = parseSystemBuildTool
, parseListItem = fmap VersionConstraint . (.: "version")
, parseDictItem = dependencyVersion
, parseKey = T.unpack
}
parseSystemBuildTool :: Monad m => Text -> m (String, DependencyVersion)
parseSystemBuildTool = fmap fromCabal . parseCabalBuildTool . T.unpack

View File

@ -43,6 +43,13 @@ type GitRef = String
data VersionConstraint = AnyVersion | VersionRange String
deriving (Eq, Show)
instance FromValue VersionConstraint where
fromValue v = case v of
Null -> return AnyVersion
Number n -> return (numericVersionConstraint n)
String s -> stringVersionConstraint s
_ -> typeMismatch "Null, Number, or String" v
anyVersion :: DependencyVersion
anyVersion = VersionConstraint AnyVersion

View File

@ -100,3 +100,11 @@ spec = do
("foo", anyVersion)
, ("bar", versionRange ">=0.1.0")
]
it "accepts objects with name and version" $ do
[yaml|
- name: foo
version: 0.1.0
|] `shouldDecodeTo_` SystemBuildTools [
("foo", versionRange "==0.1.0")
]