Parse enumerations (#4)

This commit is contained in:
Yuras 2020-02-07 11:50:41 +03:00 committed by GitHub
parent 9fadbc0aae
commit 1f31ce4489
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 2 deletions

View File

@ -168,11 +168,19 @@ parseRestriction c = do
_ -> parseError c "Multiple types"
Just t -> Xsd.Ref <$> makeQName c t
constraints <- parseConstrains c
return Xsd.Restriction
{ Xsd.restrictionBase = tp
, Xsd.restrictionConstraints = [] -- TODO: implement me
, Xsd.restrictionConstraints = constraints
}
parseConstrains :: Cursor -> P [Xsd.Constraint]
parseConstrains c = do
enumerationAxis <- makeElemAxis "enumeration"
forM (c $/ enumerationAxis) $ \e -> do
Xsd.Enumeration <$> theAttribute "value" e
parseList :: Cursor -> P (Xsd.RefOr Xsd.SimpleType)
parseList c =
-- XXX: generalaze RefOr parsing

View File

@ -7,6 +7,7 @@ module Xsd.Types
, Type(..)
, SimpleType(..)
, Restriction(..)
, Constraint(..)
, ComplexType(..)
, RefOr(..)
, Element(..)

View File

@ -93,6 +93,32 @@ spec = do
Xsd.restrictionBase restriction `shouldBe`
Xsd.Ref (Xsd.QName (Just (Xsd.Namespace "something")) "string")
context "when restriction contains enumerations" $ do
it "parses them" $ do
let
doc = mkDoc $
mkElem "schema"
(Map.fromList [("xmlns:xs","something")])
[NodeElement $ mkElem "simpleType"
(Map.fromList [("name", "str")])
[NodeElement $ mkElem "restriction"
(Map.fromList [("base", "xs:string")])
[ NodeElement $ mkElem "enumeration"
(Map.fromList [("value", "value1")]) []
, NodeElement $ mkElem "enumeration"
(Map.fromList [("value", "value2")]) []
]]]
res = Xsd.parse Xsd.defaultConfig doc
Right [Xsd.ChildType tpName (Xsd.TypeSimple t)] =
fmap Xsd.children res
Xsd.AtomicType restriction _ = t
res `shouldSatisfy` isRight
tpName `shouldBe` (Xsd.QName Nothing "str")
Xsd.restrictionConstraints restriction `shouldBe`
[ Xsd.Enumeration "value1"
, Xsd.Enumeration "value2"
]
context "when restrication base is inlined" $ do
it "parses it" $ do
let
@ -117,7 +143,7 @@ spec = do
Xsd.restrictionBase restriction `shouldBe`
Xsd.Ref (Xsd.QName (Just (Xsd.Namespace "something")) "string")
context "when base is refers to an unbound prefix" $ do
context "when base refers to an unbound prefix" $ do
it "fails" $ do
let
doc = mkDoc $