@@ -6,6 +6,7 @@ module Data.KDL.Decoder.ArrowSpec (spec) where
66
77import Control.Arrow (returnA )
88import Control.Monad (forM_ , unless , when )
9+ import Data.Int (Int64 )
910import Data.KDL.Arrow qualified as KDL
1011import Data.KDL.Types (
1112 Entry (.. ),
@@ -1046,12 +1047,21 @@ schemaSpec = do
10461047 let decoder = KDL. document $ proc () -> do
10471048 x <- KDL. nodeWith " foo" $ show <$> KDL. argWith decodeFoo -< ()
10481049 ys <- KDL. many $ KDL. nodeWith " bar" $ KDL. arg @ String -< ()
1049- returnA -< (x, ys)
1050+
1051+ zType <- KDL. argAt @ Text " baz_type" -< ()
1052+ z <- KDL. argAtWith " baz" decodeBaz -< zType
1053+
1054+ returnA -< (x, ys, z)
10501055 decodeFoo =
10511056 KDL. oneOf
10521057 [ Left <$> KDL. valueDecoder @ Bool
10531058 , Right <$> KDL. valueDecoder @ Text
10541059 ]
1060+ decodeBaz = proc zType -> do
1061+ case zType of
1062+ " int" -> KDL. valueDecoder @ Int64 -< ()
1063+ " bool" -> (\ b -> if b then 1 else 0 ) <$> KDL. valueDecoder @ Bool -< ()
1064+ _ -> KDL. fail -< " Invalid type: " <> zType
10551065 expected =
10561066 KDL. SchemaAnd
10571067 [ KDL. SchemaOne . KDL. NodeNamed " foo" $
@@ -1085,6 +1095,34 @@ schemaSpec = do
10851095 }
10861096 , KDL. SchemaAnd []
10871097 ]
1098+ , KDL. SchemaOne . KDL. NodeNamed " baz_type" $
1099+ KDL. TypedNodeSchema
1100+ { typeHint = typeRep $ Proxy @ Text
1101+ , validTypeAnns = []
1102+ , nodeSchema =
1103+ KDL. SchemaOne . KDL. NodeArg $
1104+ KDL. TypedValueSchema
1105+ { typeHint = typeRep $ Proxy @ Text
1106+ , validTypeAnns = [" text" ]
1107+ , dataSchema = KDL. SchemaOne KDL. TextSchema
1108+ }
1109+ }
1110+ , KDL. SchemaOne . KDL. NodeNamed " baz" $
1111+ KDL. TypedNodeSchema
1112+ { typeHint = typeRep $ Proxy @ Int64
1113+ , validTypeAnns = []
1114+ , nodeSchema =
1115+ KDL. SchemaOne . KDL. NodeArg $
1116+ KDL. TypedValueSchema
1117+ { typeHint = typeRep $ Proxy @ Int64
1118+ , validTypeAnns = []
1119+ , dataSchema =
1120+ KDL. SchemaOr
1121+ [ KDL. SchemaOne KDL. NumberSchema
1122+ , KDL. SchemaOne KDL. BoolSchema
1123+ ]
1124+ }
1125+ }
10881126 ]
10891127 KDL. documentSchema decoder `shouldBe` expected
10901128
0 commit comments