Skip to content

Commit

Permalink
Fixup optional 'doc' field for enum. Add canonicaliser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HuwCampbell committed Sep 26, 2024
1 parent 120c1eb commit 082a5c5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion avro-simple.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/Avro/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/Test/Avro/Binary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
7 changes: 4 additions & 3 deletions test/Test/Avro/Schema/Roundtrip.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -78,7 +79,7 @@ nubFields =

fuzzBaseName :: Gen Text
fuzzBaseName =
Gen.element [ "foo", "bar", "baz" ]
Gen.element Corpus.boats


fuzzSuits :: Gen [Text]
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 082a5c5

Please sign in to comment.