From 082a5c5f0212f62add88282319773bae5d002a16 Mon Sep 17 00:00:00 2001 From: Huw Campbell Date: Fri, 27 Sep 2024 09:32:47 +1000 Subject: [PATCH] Fixup optional 'doc' field for enum. Add canonicaliser tests --- avro-simple.cabal | 5 ++++- src/Avro/Schema.hs | 3 ++- test/Main.hs | 2 ++ test/Test/Avro/Binary.hs | 2 +- test/Test/Avro/Schema/Roundtrip.hs | 7 ++++--- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/avro-simple.cabal b/avro-simple.cabal index e1a7b05..1fc69a2 100644 --- a/avro-simple.cabal +++ b/avro-simple.cabal @@ -57,6 +57,7 @@ test-suite avro-simple-test Test.Avro.Codec.Basics Test.Avro.Codec.Compound Test.Avro.Codec.Recursive + Test.Avro.Schema.Canonical Test.Avro.Schema.Roundtrip Test.Avro.Schema.Validation Test.Avro.Resolutions.Base @@ -69,12 +70,14 @@ test-suite avro-simple-test avro-simple, aeson, binary, + bytestring, containers, invariant, neat-interpolation, profunctors, text, - hedgehog + hedgehog, + hedgehog-corpus ghc-options: -Wall diff --git a/src/Avro/Schema.hs b/src/Avro/Schema.hs index 1d0e9d0..d1b5992 100644 --- a/src/Avro/Schema.hs +++ b/src/Avro/Schema.hs @@ -1168,6 +1168,7 @@ decodeFields context (Aeson.Object obj) = do decodeFields _ _ = fail "Can't parse Field object" + decodeSchema :: Aeson.Value -> Aeson.Parser Schema decodeSchema = decodeSchemaInContext Nothing @@ -1294,7 +1295,7 @@ decodeSchemaInContext context vs = case vs of decodeAliases name obj Enum name aliases - <$> obj Aeson..: "doc" + <$> obj Aeson..:? "doc" <*> obj Aeson..: "symbols" <*> obj Aeson..:? "default" diff --git a/test/Main.hs b/test/Main.hs index 230e5c5..24eb066 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -8,6 +8,7 @@ import qualified Test.Avro.Binary import qualified Test.Avro.Codec.Basics import qualified Test.Avro.Codec.Compound import qualified Test.Avro.Codec.Recursive +import qualified Test.Avro.Schema.Canonical import qualified Test.Avro.Schema.Roundtrip import qualified Test.Avro.Schema.Validation import qualified Test.Avro.Resolutions.Basics @@ -21,6 +22,7 @@ main = Test.Avro.Codec.Basics.tests, Test.Avro.Codec.Compound.tests, Test.Avro.Codec.Recursive.tests, + Test.Avro.Schema.Canonical.tests, Test.Avro.Schema.Roundtrip.tests, Test.Avro.Schema.Validation.tests, Test.Avro.Resolutions.Basics.tests, diff --git a/test/Test/Avro/Binary.hs b/test/Test/Avro/Binary.hs index 9706188..9270df9 100644 --- a/test/Test/Avro/Binary.hs +++ b/test/Test/Avro/Binary.hs @@ -23,7 +23,7 @@ fuzzSchemaAndValue = do prop_trip_binary_values :: Property prop_trip_binary_values = - withTests 1000 . withDiscards 1 . property $ do + withTests 1000 . property $ do (sc, example) <- forAll fuzzSchemaAndValue let dynamic = diff --git a/test/Test/Avro/Schema/Roundtrip.hs b/test/Test/Avro/Schema/Roundtrip.hs index 7e0769e..0a5adde 100644 --- a/test/Test/Avro/Schema/Roundtrip.hs +++ b/test/Test/Avro/Schema/Roundtrip.hs @@ -2,6 +2,7 @@ module Test.Avro.Schema.Roundtrip where import Hedgehog +import qualified Hedgehog.Corpus as Corpus import qualified Hedgehog.Gen as Gen import qualified Hedgehog.Range as Range @@ -78,7 +79,7 @@ nubFields = fuzzBaseName :: Gen Text fuzzBaseName = - Gen.element [ "foo", "bar", "baz" ] + Gen.element Corpus.boats fuzzSuits :: Gen [Text] @@ -92,7 +93,7 @@ fuzzName :: Gen TypeName fuzzName = TypeName <$> fuzzBaseName - <*> Gen.list (Range.linear 0 10) fuzzBaseName + <*> Gen.list (Range.linear 0 10) (Gen.element Corpus.waters) flattenUnions :: [Schema] -> [Schema] @@ -186,7 +187,7 @@ fuzzField = do schema <- fuzzSchema Field <$> fuzzBaseName - <*> Gen.list (Range.linear 0 10) fuzzBaseName + <*> Gen.list (Range.linear 0 2) fuzzBaseName <*> pure Nothing <*> Gen.maybe (Gen.element [ Ascending, Descending, Ignore ]) <*> pure schema