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:
parent
ac4d95e936
commit
132d92ce64
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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")
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user