mirror of
https://github.com/typeable/xsd-parser.git
synced 2024-11-26 16:05:33 +03:00
Parse enumerations (#4)
This commit is contained in:
parent
9fadbc0aae
commit
1f31ce4489
@ -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
|
||||
|
@ -7,6 +7,7 @@ module Xsd.Types
|
||||
, Type(..)
|
||||
, SimpleType(..)
|
||||
, Restriction(..)
|
||||
, Constraint(..)
|
||||
, ComplexType(..)
|
||||
, RefOr(..)
|
||||
, Element(..)
|
||||
|
28
test/Spec.hs
28
test/Spec.hs
@ -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 $
|
||||
|
Loading…
Reference in New Issue
Block a user