diff --git a/default.nix b/default.nix index fc52666b..d4ead885 100644 --- a/default.nix +++ b/default.nix @@ -1,5 +1,5 @@ { mkDerivation, base, bytestring, cereal, containers, deepseq -, filepath, haskell-src, mtl, parsec, parsers, pipes, pretty +, filepath, haskell-src, mtl, parsec, parsers, pretty, pretty-show , proto3-wire, QuickCheck, safe, semigroups, stdenv, tasty , tasty-hunit, tasty-quickcheck, text, transformers, turtle, vector }: @@ -9,12 +9,13 @@ mkDerivation { src = ./.; libraryHaskellDepends = [ base bytestring cereal containers deepseq filepath haskell-src mtl - parsec parsers pipes pretty proto3-wire QuickCheck safe semigroups - text transformers vector + parsec parsers pretty pretty-show proto3-wire QuickCheck safe + semigroups text transformers vector ]; testHaskellDepends = [ - base bytestring cereal proto3-wire QuickCheck semigroups tasty - tasty-hunit tasty-quickcheck text transformers turtle + base bytestring cereal pretty-show proto3-wire QuickCheck + semigroups tasty tasty-hunit tasty-quickcheck text transformers + turtle vector ]; description = "A low level library for writing out data in the Protocol Buffers wire format"; license = stdenv.lib.licenses.asl20; diff --git a/proto3-suite.cabal b/proto3-suite.cabal index 1d79ff00..73315971 100644 --- a/proto3-suite.cabal +++ b/proto3-suite.cabal @@ -31,6 +31,7 @@ library parsec >= 3.1.9 && <3.2.0, parsers >= 0.12 && <0.13, pretty ==1.1.*, + pretty-show >= 1.6.12 && < 1.7, proto3-wire == 1.0.*, QuickCheck >=2.8 && <3.0, semigroups ==0.18.*, @@ -46,7 +47,7 @@ library test-suite tests type: exitcode-stdio-1.0 main-is: Main.hs - other-modules: TestTypes TestCodeGen + other-modules: OldTestTypes GeneratedTestTypes TestCodeGen hs-source-dirs: tests build-depends: base >=4.8 && <5.0, tasty >= 0.11 && <0.12, @@ -60,4 +61,6 @@ test-suite tests cereal >= 0.5.1 && <0.6, semigroups ==0.18.*, transformers >=0.4 && <0.6, - turtle >= 1.2.0 + turtle >= 1.2.0, + pretty-show >= 1.6.12 && < 1.7, + vector >=0.11 && < 0.13 diff --git a/src/Proto3/Suite/Class.hs b/src/Proto3/Suite/Class.hs index 40f4a2a0..cc550c23 100644 --- a/src/Proto3/Suite/Class.hs +++ b/src/Proto3/Suite/Class.hs @@ -458,7 +458,7 @@ instance forall a. (Named a, Message a) => MessageField (NestedVec a) where instance MessageField (PackedVec Word32) where encodeMessageField fn = omittingDefault (Encode.packedVarints fn) . fmap fromIntegral decodeMessageField = decodePacked Decode.packedVarints - protoType _ = messageField (Prim UInt32) (Just DotProto.PackedField) + protoType _ = messageField (Repeated UInt32) (Just DotProto.PackedField) instance MessageField (PackedVec Word64) where encodeMessageField fn = omittingDefault (Encode.packedVarints fn) . fmap fromIntegral diff --git a/src/Proto3/Suite/DotProto/Generate.hs b/src/Proto3/Suite/DotProto/Generate.hs index 51e96038..1397a054 100644 --- a/src/Proto3/Suite/DotProto/Generate.hs +++ b/src/Proto3/Suite/DotProto/Generate.hs @@ -559,7 +559,10 @@ dotProtoEnumD parentIdent enumIdent enumParts = -- TODO assert that there is more than one enumeration constructor minEnumVal = fst (head enumCons) maxEnumVal = fst (last enumCons) - boundsE = HsTuple [intE minEnumVal, intE maxEnumVal] + boundsE = HsTuple + [ HsExpTypeSig l (intE minEnumVal) (HsQualType [] (HsTyCon (haskellName "Int"))) + , intE maxEnumVal + ] toEnumD = toEnumDPatterns <> [ toEnumFailure ] fromEnumD = diff --git a/test-files/make_reference_encodings.py b/test-files/make_reference_encodings.py index b8ebe77d..7f1492b5 100644 --- a/test-files/make_reference_encodings.py +++ b/test-files/make_reference_encodings.py @@ -67,7 +67,7 @@ def main(): trivNeg.trivialField = -1 serialize_to_file(trivNeg, 'trivial_negative.bin') - withFixed = test_pb2.WithFixedTypes() + withFixed = test_pb2.WithFixed() withFixed.fixed1 = 16 withFixed.fixed2 = -123 withFixed.fixed3 = 4096 diff --git a/test-files/test.proto b/test-files/test.proto index d1e32785..1ce671fb 100644 --- a/test-files/test.proto +++ b/test-files/test.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package test; +package GeneratedTestTypes; import "test-files/test_import.proto"; message Trivial { @@ -33,6 +33,8 @@ message WithNesting { message Nested { string nestedField1 = 1; int32 nestedField2 = 2; + repeated int32 nestedPacked = 3 [packed=true]; + repeated int32 nestedUnpacked = 4 [packed=false]; } Nested nestedMessage = 1; } @@ -47,19 +49,24 @@ message WithNestingRepeated { repeated Nested nestedMessages = 1; } -message WithNestingRepeatedInts { - message NestedInts { +message NestedInts { int32 nestedInt1 = 1; int32 nestedInt2 = 2; } + +message WithNestingRepeatedInts { repeated NestedInts nestedInts = 1; } +message WithNestingInts { + NestedInts nestedInts = 1; +} + message WithRepetition { repeated int32 repeatedField1 = 1; } -message WithFixedTypes { +message WithFixed { fixed32 fixed1 = 1; sfixed32 fixed2 = 2; fixed64 fixed3 = 3; @@ -116,6 +123,10 @@ message WithQualifiedName { } message UsingImported { - test_import.WithNesting importedNesting = 100; + GeneratedImportedTestTypes.WithNesting importedNesting = 100; WithNesting localNesting = 200; } + +message Wrapped { + Wrapped wrapped = 1; +} diff --git a/test-files/test_import.proto b/test-files/test_import.proto index f30f9062..55b611fb 100644 --- a/test-files/test_import.proto +++ b/test-files/test_import.proto @@ -1,5 +1,5 @@ syntax="proto3"; -package test_import; +package GeneratedImportedTestTypes; message WithNesting { message Nested { diff --git a/tests/ArbitraryGeneratedTestTypes.hs b/tests/ArbitraryGeneratedTestTypes.hs new file mode 100644 index 00000000..4685f170 --- /dev/null +++ b/tests/ArbitraryGeneratedTestTypes.hs @@ -0,0 +1,75 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} + +module ArbitraryGeneratedTestTypes where + +import qualified Data.ByteString as BS +import qualified Data.Text as T +import qualified Data.Vector as V +import Test.QuickCheck (Arbitrary, arbitrary, listOf) + +import GeneratedTestTypes + +instance Arbitrary a => Arbitrary (V.Vector a) where + arbitrary = V.fromList <$> listOf arbitrary + +instance Arbitrary Trivial where + arbitrary = Trivial <$> arbitrary + +instance Arbitrary MultipleFields where + arbitrary = + MultipleFields + <$> arbitrary + <*> arbitrary + <*> arbitrary + <*> arbitrary + <*> fmap T.pack arbitrary + <*> arbitrary + +instance Arbitrary WithEnum where + arbitrary = WithEnum <$> arbitrary + +instance Arbitrary WithNesting_Nested where + arbitrary = + WithNesting_Nested + <$> fmap T.pack arbitrary + <*> arbitrary + <*> arbitrary + <*> arbitrary + +instance Arbitrary WithNesting where + arbitrary = WithNesting <$> arbitrary + +instance Arbitrary WithRepetition where + arbitrary = WithRepetition <$> arbitrary + +instance Arbitrary WithFixed where + arbitrary = WithFixed <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary WithBytes where + arbitrary = WithBytes <$> arbitrary <*> arbitrary + +instance Arbitrary BS.ByteString where + arbitrary = BS.pack <$> arbitrary + +instance Arbitrary AllPackedTypes where + arbitrary = + AllPackedTypes + <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary + <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary + +instance Arbitrary SignedInts where + arbitrary = SignedInts <$> arbitrary <*> arbitrary + +instance Arbitrary WithNestingRepeated where + arbitrary = WithNestingRepeated <$> arbitrary + +instance Arbitrary WithNestingRepeated_Nested where + arbitrary = + WithNestingRepeated_Nested + <$> fmap T.pack arbitrary + <*> arbitrary + <*> arbitrary + <*> arbitrary + +instance Arbitrary Wrapped where + arbitrary = Wrapped <$> arbitrary diff --git a/tests/GeneratedImportedTestTypes.hs b/tests/GeneratedImportedTestTypes.hs new file mode 100644 index 00000000..1f058b72 --- /dev/null +++ b/tests/GeneratedImportedTestTypes.hs @@ -0,0 +1,97 @@ +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-unused-imports #-} +{-# OPTIONS_GHC -fno-warn-name-shadowing #-} +-- | Generated by Haskell protocol buffer compiler. DO NOT EDIT! +module GeneratedImportedTestTypes where +import qualified Prelude as Hs +import qualified Proto3.Suite.DotProto as HsProtobuf +import qualified Proto3.Suite.Types as HsProtobuf +import qualified Proto3.Suite.Class as HsProtobuf +import qualified Proto3.Wire as HsProtobuf +import Control.Applicative ((<*>), (<|>)) +import qualified Data.Text as Hs (Text) +import qualified Data.ByteString as Hs +import qualified Data.String as Hs (fromString) +import qualified Data.Vector as Hs (Vector) +import qualified Data.Int as Hs (Int16, Int32, Int64) +import qualified Data.Word as Hs (Word16, Word32, Word64) +import GHC.Generics as Hs +import GHC.Enum as Hs + +data WithNesting = WithNesting{withNestingNestedMessage1 :: + Hs.Maybe WithNesting_Nested, + withNestingNestedMessage2 :: Hs.Maybe WithNesting_Nested} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithNesting where + nameOf _ = (Hs.fromString "WithNesting") + +instance HsProtobuf.Message WithNesting where + encodeMessage _ + WithNesting{withNestingNestedMessage1 = withNestingNestedMessage1, + withNestingNestedMessage2 = withNestingNestedMessage2} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Nested withNestingNestedMessage1)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 100) + (HsProtobuf.Nested withNestingNestedMessage2))]) + decodeMessage _ + = (Hs.pure WithNesting) <*> + ((Hs.pure HsProtobuf.nested) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1))) + <*> + ((Hs.pure HsProtobuf.nested) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 100))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim (HsProtobuf.Named (HsProtobuf.Single "Nested"))) + (HsProtobuf.Single "nestedMessage1") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 100) + (HsProtobuf.Prim (HsProtobuf.Named (HsProtobuf.Single "Nested"))) + (HsProtobuf.Single "nestedMessage2") + [] + Hs.Nothing)] + +data WithNesting_Nested = WithNesting_Nested{withNesting_NestedNestedField1 + :: Hs.Int32, + withNesting_NestedNestedField2 :: Hs.Int32} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithNesting_Nested where + nameOf _ = (Hs.fromString "WithNesting_Nested") + +instance HsProtobuf.Message WithNesting_Nested where + encodeMessage _ + WithNesting_Nested{withNesting_NestedNestedField1 = + withNesting_NestedNestedField1, + withNesting_NestedNestedField2 = withNesting_NestedNestedField2} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + withNesting_NestedNestedField1), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) + withNesting_NestedNestedField2)]) + decodeMessage _ + = (Hs.pure WithNesting_Nested) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1)) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2)) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim HsProtobuf.Int32) + (HsProtobuf.Single "nestedField1") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Prim HsProtobuf.Int32) + (HsProtobuf.Single "nestedField2") + [] + Hs.Nothing)] \ No newline at end of file diff --git a/tests/GeneratedTestTypes.hs b/tests/GeneratedTestTypes.hs new file mode 100644 index 00000000..02413a48 --- /dev/null +++ b/tests/GeneratedTestTypes.hs @@ -0,0 +1,1102 @@ +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-unused-imports #-} +{-# OPTIONS_GHC -fno-warn-name-shadowing #-} +-- | Generated by Haskell protocol buffer compiler. DO NOT EDIT! +module GeneratedTestTypes where +import qualified Prelude as Hs +import qualified Proto3.Suite.DotProto as HsProtobuf +import qualified Proto3.Suite.Types as HsProtobuf +import qualified Proto3.Suite.Class as HsProtobuf +import qualified Proto3.Wire as HsProtobuf +import Control.Applicative ((<*>), (<|>)) +import qualified Data.Text as Hs (Text) +import qualified Data.ByteString as Hs +import qualified Data.String as Hs (fromString) +import qualified Data.Vector as Hs (Vector) +import qualified Data.Int as Hs (Int16, Int32, Int64) +import qualified Data.Word as Hs (Word16, Word32, Word64) +import GHC.Generics as Hs +import GHC.Enum as Hs +import qualified GeneratedImportedTestTypes + +data Trivial = Trivial{trivialTrivialField :: Hs.Int32} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named Trivial where + nameOf _ = (Hs.fromString "Trivial") + +instance HsProtobuf.Message Trivial where + encodeMessage _ Trivial{trivialTrivialField = trivialTrivialField} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + trivialTrivialField)]) + decodeMessage _ + = (Hs.pure Trivial) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1)) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim HsProtobuf.Int32) + (HsProtobuf.Single "trivialField") + [] + Hs.Nothing)] + +data MultipleFields = MultipleFields{multipleFieldsMultiFieldDouble + :: Hs.Double, + multipleFieldsMultiFieldFloat :: Hs.Float, + multipleFieldsMultiFieldInt32 :: Hs.Int32, + multipleFieldsMultiFieldInt64 :: Hs.Int64, + multipleFieldsMultiFieldString :: Hs.Text, + multipleFieldsMultiFieldBool :: Hs.Bool} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named MultipleFields where + nameOf _ = (Hs.fromString "MultipleFields") + +instance HsProtobuf.Message MultipleFields where + encodeMessage _ + MultipleFields{multipleFieldsMultiFieldDouble = + multipleFieldsMultiFieldDouble, + multipleFieldsMultiFieldFloat = multipleFieldsMultiFieldFloat, + multipleFieldsMultiFieldInt32 = multipleFieldsMultiFieldInt32, + multipleFieldsMultiFieldInt64 = multipleFieldsMultiFieldInt64, + multipleFieldsMultiFieldString = multipleFieldsMultiFieldString, + multipleFieldsMultiFieldBool = multipleFieldsMultiFieldBool} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + multipleFieldsMultiFieldDouble), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) + multipleFieldsMultiFieldFloat), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 3) + multipleFieldsMultiFieldInt32), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 4) + multipleFieldsMultiFieldInt64), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 5) + multipleFieldsMultiFieldString), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 6) + multipleFieldsMultiFieldBool)]) + decodeMessage _ + = (Hs.pure MultipleFields) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1)) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2)) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 3)) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 4)) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 5)) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 6)) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim HsProtobuf.Double) + (HsProtobuf.Single "multiFieldDouble") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Prim HsProtobuf.Float) + (HsProtobuf.Single "multiFieldFloat") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 3) + (HsProtobuf.Prim HsProtobuf.Int32) + (HsProtobuf.Single "multiFieldInt32") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 4) + (HsProtobuf.Prim HsProtobuf.Int64) + (HsProtobuf.Single "multiFieldInt64") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 5) + (HsProtobuf.Prim HsProtobuf.String) + (HsProtobuf.Single "multiFieldString") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 6) + (HsProtobuf.Prim HsProtobuf.Bool) + (HsProtobuf.Single "multiFieldBool") + [] + Hs.Nothing)] + +data SignedInts = SignedInts{signedIntsSigned32 :: Hs.Int32, + signedIntsSigned64 :: Hs.Int64} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named SignedInts where + nameOf _ = (Hs.fromString "SignedInts") + +instance HsProtobuf.Message SignedInts where + encodeMessage _ + SignedInts{signedIntsSigned32 = signedIntsSigned32, + signedIntsSigned64 = signedIntsSigned64} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Signed signedIntsSigned32)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Signed signedIntsSigned64))]) + decodeMessage _ + = (Hs.pure SignedInts) <*> + ((Hs.pure HsProtobuf.signed) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1))) + <*> + ((Hs.pure HsProtobuf.signed) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim HsProtobuf.SInt32) + (HsProtobuf.Single "signed32") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Prim HsProtobuf.SInt64) + (HsProtobuf.Single "signed64") + [] + Hs.Nothing)] + +data WithEnum = WithEnum{withEnumEnumField :: + HsProtobuf.Enumerated WithEnum_TestEnum} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithEnum where + nameOf _ = (Hs.fromString "WithEnum") + +instance HsProtobuf.Message WithEnum where + encodeMessage _ WithEnum{withEnumEnumField = withEnumEnumField} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + withEnumEnumField)]) + decodeMessage _ + = (Hs.pure WithEnum) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1)) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim (HsProtobuf.Named (HsProtobuf.Single "TestEnum"))) + (HsProtobuf.Single "enumField") + [] + Hs.Nothing)] + +data WithEnum_TestEnum = WithEnum_TestEnumENUM1 + | WithEnum_TestEnumENUM2 + | WithEnum_TestEnumENUM3 + deriving (Hs.Show, Hs.Bounded, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithEnum_TestEnum where + nameOf _ = (Hs.fromString "WithEnum_TestEnum") + +instance Hs.Enum WithEnum_TestEnum where + toEnum 0 = WithEnum_TestEnumENUM1 + toEnum 1 = WithEnum_TestEnumENUM2 + toEnum 2 = WithEnum_TestEnumENUM3 + toEnum i = (Hs.toEnumError "WithEnum_TestEnum" i (0 :: Hs.Int, 2)) + fromEnum (WithEnum_TestEnumENUM1) = 0 + fromEnum (WithEnum_TestEnumENUM2) = 1 + fromEnum (WithEnum_TestEnumENUM3) = 2 + succ (WithEnum_TestEnumENUM1) = WithEnum_TestEnumENUM2 + succ (WithEnum_TestEnumENUM2) = WithEnum_TestEnumENUM3 + succ _ = Hs.succError "WithEnum_TestEnum" + pred (WithEnum_TestEnumENUM2) = WithEnum_TestEnumENUM1 + pred (WithEnum_TestEnumENUM3) = WithEnum_TestEnumENUM2 + pred _ = Hs.predError "WithEnum_TestEnum" + +data WithNesting = WithNesting{withNestingNestedMessage :: + Hs.Maybe WithNesting_Nested} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithNesting where + nameOf _ = (Hs.fromString "WithNesting") + +instance HsProtobuf.Message WithNesting where + encodeMessage _ + WithNesting{withNestingNestedMessage = withNestingNestedMessage} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Nested withNestingNestedMessage))]) + decodeMessage _ + = (Hs.pure WithNesting) <*> + ((Hs.pure HsProtobuf.nested) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim (HsProtobuf.Named (HsProtobuf.Single "Nested"))) + (HsProtobuf.Single "nestedMessage") + [] + Hs.Nothing)] + +data WithNesting_Nested = WithNesting_Nested{withNesting_NestedNestedField1 + :: Hs.Text, + withNesting_NestedNestedField2 :: Hs.Int32, + withNesting_NestedNestedPacked :: Hs.Vector Hs.Int32, + withNesting_NestedNestedUnpacked :: Hs.Vector Hs.Int32} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithNesting_Nested where + nameOf _ = (Hs.fromString "WithNesting_Nested") + +instance HsProtobuf.Message WithNesting_Nested where + encodeMessage _ + WithNesting_Nested{withNesting_NestedNestedField1 = + withNesting_NestedNestedField1, + withNesting_NestedNestedField2 = withNesting_NestedNestedField2, + withNesting_NestedNestedPacked = withNesting_NestedNestedPacked, + withNesting_NestedNestedUnpacked = + withNesting_NestedNestedUnpacked} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + withNesting_NestedNestedField1), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) + withNesting_NestedNestedField2), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 3) + (HsProtobuf.PackedVec withNesting_NestedNestedPacked)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 4) + (HsProtobuf.UnpackedVec withNesting_NestedNestedUnpacked))]) + decodeMessage _ + = (Hs.pure WithNesting_Nested) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1)) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2)) + <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 3))) + <*> + ((Hs.pure HsProtobuf.unpackedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 4))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim HsProtobuf.String) + (HsProtobuf.Single "nestedField1") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Prim HsProtobuf.Int32) + (HsProtobuf.Single "nestedField2") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 3) + (HsProtobuf.Repeated HsProtobuf.Int32) + (HsProtobuf.Single "nestedPacked") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 4) + (HsProtobuf.Repeated HsProtobuf.Int32) + (HsProtobuf.Single "nestedUnpacked") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.False))] + Hs.Nothing)] + +data WithNestingRepeated = WithNestingRepeated{withNestingRepeatedNestedMessages + :: Hs.Vector WithNestingRepeated_Nested} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithNestingRepeated where + nameOf _ = (Hs.fromString "WithNestingRepeated") + +instance HsProtobuf.Message WithNestingRepeated where + encodeMessage _ + WithNestingRepeated{withNestingRepeatedNestedMessages = + withNestingRepeatedNestedMessages} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + (HsProtobuf.NestedVec withNestingRepeatedNestedMessages))]) + decodeMessage _ + = (Hs.pure WithNestingRepeated) <*> + ((Hs.pure HsProtobuf.nestedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Repeated + (HsProtobuf.Named (HsProtobuf.Single "Nested"))) + (HsProtobuf.Single "nestedMessages") + [] + Hs.Nothing)] + +data WithNestingRepeated_Nested = WithNestingRepeated_Nested{withNestingRepeated_NestedNestedField1 + :: Hs.Text, + withNestingRepeated_NestedNestedField2 + :: Hs.Int32, + withNestingRepeated_NestedNestedPacked + :: Hs.Vector Hs.Int32, + withNestingRepeated_NestedNestedUnpacked + :: Hs.Vector Hs.Int32} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithNestingRepeated_Nested where + nameOf _ = (Hs.fromString "WithNestingRepeated_Nested") + +instance HsProtobuf.Message WithNestingRepeated_Nested where + encodeMessage _ + WithNestingRepeated_Nested{withNestingRepeated_NestedNestedField1 = + withNestingRepeated_NestedNestedField1, + withNestingRepeated_NestedNestedField2 = + withNestingRepeated_NestedNestedField2, + withNestingRepeated_NestedNestedPacked = + withNestingRepeated_NestedNestedPacked, + withNestingRepeated_NestedNestedUnpacked = + withNestingRepeated_NestedNestedUnpacked} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + withNestingRepeated_NestedNestedField1), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) + withNestingRepeated_NestedNestedField2), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 3) + (HsProtobuf.PackedVec withNestingRepeated_NestedNestedPacked)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 4) + (HsProtobuf.UnpackedVec + withNestingRepeated_NestedNestedUnpacked))]) + decodeMessage _ + = (Hs.pure WithNestingRepeated_Nested) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1)) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2)) + <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 3))) + <*> + ((Hs.pure HsProtobuf.unpackedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 4))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim HsProtobuf.String) + (HsProtobuf.Single "nestedField1") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Prim HsProtobuf.Int32) + (HsProtobuf.Single "nestedField2") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 3) + (HsProtobuf.Repeated HsProtobuf.Int32) + (HsProtobuf.Single "nestedPacked") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 4) + (HsProtobuf.Repeated HsProtobuf.Int32) + (HsProtobuf.Single "nestedUnpacked") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.False))] + Hs.Nothing)] + +data NestedInts = NestedInts{nestedIntsNestedInt1 :: Hs.Int32, + nestedIntsNestedInt2 :: Hs.Int32} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named NestedInts where + nameOf _ = (Hs.fromString "NestedInts") + +instance HsProtobuf.Message NestedInts where + encodeMessage _ + NestedInts{nestedIntsNestedInt1 = nestedIntsNestedInt1, + nestedIntsNestedInt2 = nestedIntsNestedInt2} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + nestedIntsNestedInt1), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) + nestedIntsNestedInt2)]) + decodeMessage _ + = (Hs.pure NestedInts) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1)) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2)) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim HsProtobuf.Int32) + (HsProtobuf.Single "nestedInt1") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Prim HsProtobuf.Int32) + (HsProtobuf.Single "nestedInt2") + [] + Hs.Nothing)] + +data WithNestingRepeatedInts = WithNestingRepeatedInts{withNestingRepeatedIntsNestedInts + :: Hs.Vector NestedInts} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithNestingRepeatedInts where + nameOf _ = (Hs.fromString "WithNestingRepeatedInts") + +instance HsProtobuf.Message WithNestingRepeatedInts where + encodeMessage _ + WithNestingRepeatedInts{withNestingRepeatedIntsNestedInts = + withNestingRepeatedIntsNestedInts} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + (HsProtobuf.NestedVec withNestingRepeatedIntsNestedInts))]) + decodeMessage _ + = (Hs.pure WithNestingRepeatedInts) <*> + ((Hs.pure HsProtobuf.nestedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Repeated + (HsProtobuf.Named (HsProtobuf.Single "NestedInts"))) + (HsProtobuf.Single "nestedInts") + [] + Hs.Nothing)] + +data WithNestingInts = WithNestingInts{withNestingIntsNestedInts :: + Hs.Maybe NestedInts} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithNestingInts where + nameOf _ = (Hs.fromString "WithNestingInts") + +instance HsProtobuf.Message WithNestingInts where + encodeMessage _ + WithNestingInts{withNestingIntsNestedInts = + withNestingIntsNestedInts} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Nested withNestingIntsNestedInts))]) + decodeMessage _ + = (Hs.pure WithNestingInts) <*> + ((Hs.pure HsProtobuf.nested) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim + (HsProtobuf.Named (HsProtobuf.Single "NestedInts"))) + (HsProtobuf.Single "nestedInts") + [] + Hs.Nothing)] + +data WithRepetition = WithRepetition{withRepetitionRepeatedField1 + :: Hs.Vector Hs.Int32} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithRepetition where + nameOf _ = (Hs.fromString "WithRepetition") + +instance HsProtobuf.Message WithRepetition where + encodeMessage _ + WithRepetition{withRepetitionRepeatedField1 = + withRepetitionRepeatedField1} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + (HsProtobuf.PackedVec withRepetitionRepeatedField1))]) + decodeMessage _ + = (Hs.pure WithRepetition) <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Repeated HsProtobuf.Int32) + (HsProtobuf.Single "repeatedField1") + [] + Hs.Nothing)] + +data WithFixed = WithFixed{withFixedFixed1 :: + HsProtobuf.Fixed Hs.Word32, + withFixedFixed2 :: HsProtobuf.Fixed Hs.Int32, + withFixedFixed3 :: HsProtobuf.Fixed Hs.Word64, + withFixedFixed4 :: HsProtobuf.Fixed Hs.Int64} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithFixed where + nameOf _ = (Hs.fromString "WithFixed") + +instance HsProtobuf.Message WithFixed where + encodeMessage _ + WithFixed{withFixedFixed1 = withFixedFixed1, + withFixedFixed2 = withFixedFixed2, + withFixedFixed3 = withFixedFixed3, + withFixedFixed4 = withFixedFixed4} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + withFixedFixed1), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Signed withFixedFixed2)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 3) + withFixedFixed3), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 4) + (HsProtobuf.Signed withFixedFixed4))]) + decodeMessage _ + = (Hs.pure WithFixed) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1)) + <*> + ((Hs.pure HsProtobuf.signed) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2))) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 3)) + <*> + ((Hs.pure HsProtobuf.signed) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 4))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim HsProtobuf.Fixed32) + (HsProtobuf.Single "fixed1") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Prim HsProtobuf.SFixed32) + (HsProtobuf.Single "fixed2") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 3) + (HsProtobuf.Prim HsProtobuf.Fixed64) + (HsProtobuf.Single "fixed3") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 4) + (HsProtobuf.Prim HsProtobuf.SFixed64) + (HsProtobuf.Single "fixed4") + [] + Hs.Nothing)] + +data WithBytes = WithBytes{withBytesBytes1 :: Hs.ByteString, + withBytesBytes2 :: Hs.Vector Hs.ByteString} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithBytes where + nameOf _ = (Hs.fromString "WithBytes") + +instance HsProtobuf.Message WithBytes where + encodeMessage _ + WithBytes{withBytesBytes1 = withBytesBytes1, + withBytesBytes2 = withBytesBytes2} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + withBytesBytes1), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) + (HsProtobuf.UnpackedVec withBytesBytes2))]) + decodeMessage _ + = (Hs.pure WithBytes) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1)) + <*> + ((Hs.pure HsProtobuf.unpackedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim HsProtobuf.Bytes) + (HsProtobuf.Single "bytes1") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Repeated HsProtobuf.Bytes) + (HsProtobuf.Single "bytes2") + [] + Hs.Nothing)] + +data WithPacking = WithPacking{withPackingPacking1 :: + Hs.Vector Hs.Int32, + withPackingPacking2 :: Hs.Vector Hs.Int32} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithPacking where + nameOf _ = (Hs.fromString "WithPacking") + +instance HsProtobuf.Message WithPacking where + encodeMessage _ + WithPacking{withPackingPacking1 = withPackingPacking1, + withPackingPacking2 = withPackingPacking2} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + (HsProtobuf.UnpackedVec withPackingPacking1)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) + (HsProtobuf.PackedVec withPackingPacking2))]) + decodeMessage _ + = (Hs.pure WithPacking) <*> + ((Hs.pure HsProtobuf.unpackedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1))) + <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Repeated HsProtobuf.Int32) + (HsProtobuf.Single "packing1") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.False))] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Repeated HsProtobuf.Int32) + (HsProtobuf.Single "packing2") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing)] + +data AllPackedTypes = AllPackedTypes{allPackedTypesPackedWord32 :: + Hs.Vector Hs.Word32, + allPackedTypesPackedWord64 :: Hs.Vector Hs.Word64, + allPackedTypesPackedInt32 :: Hs.Vector Hs.Int32, + allPackedTypesPackedInt64 :: Hs.Vector Hs.Int64, + allPackedTypesPackedFixed32 :: + Hs.Vector (HsProtobuf.Fixed Hs.Word32), + allPackedTypesPackedFixed64 :: + Hs.Vector (HsProtobuf.Fixed Hs.Word64), + allPackedTypesPackedFloat :: Hs.Vector Hs.Float, + allPackedTypesPackedDouble :: Hs.Vector Hs.Double, + allPackedTypesPackedSFixed32 :: + Hs.Vector (HsProtobuf.Fixed Hs.Int32), + allPackedTypesPackedSFixed64 :: + Hs.Vector (HsProtobuf.Fixed Hs.Int64)} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named AllPackedTypes where + nameOf _ = (Hs.fromString "AllPackedTypes") + +instance HsProtobuf.Message AllPackedTypes where + encodeMessage _ + AllPackedTypes{allPackedTypesPackedWord32 = + allPackedTypesPackedWord32, + allPackedTypesPackedWord64 = allPackedTypesPackedWord64, + allPackedTypesPackedInt32 = allPackedTypesPackedInt32, + allPackedTypesPackedInt64 = allPackedTypesPackedInt64, + allPackedTypesPackedFixed32 = allPackedTypesPackedFixed32, + allPackedTypesPackedFixed64 = allPackedTypesPackedFixed64, + allPackedTypesPackedFloat = allPackedTypesPackedFloat, + allPackedTypesPackedDouble = allPackedTypesPackedDouble, + allPackedTypesPackedSFixed32 = allPackedTypesPackedSFixed32, + allPackedTypesPackedSFixed64 = allPackedTypesPackedSFixed64} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + (HsProtobuf.PackedVec allPackedTypesPackedWord32)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) + (HsProtobuf.PackedVec allPackedTypesPackedWord64)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 3) + (HsProtobuf.PackedVec allPackedTypesPackedInt32)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 4) + (HsProtobuf.PackedVec allPackedTypesPackedInt64)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 5) + (HsProtobuf.PackedVec allPackedTypesPackedFixed32)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 6) + (HsProtobuf.PackedVec allPackedTypesPackedFixed64)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 7) + (HsProtobuf.PackedVec allPackedTypesPackedFloat)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 8) + (HsProtobuf.PackedVec allPackedTypesPackedDouble)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 9) + (HsProtobuf.PackedVec + (Hs.fmap HsProtobuf.Signed allPackedTypesPackedSFixed32))), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 10) + (HsProtobuf.PackedVec + (Hs.fmap HsProtobuf.Signed allPackedTypesPackedSFixed64)))]) + decodeMessage _ + = (Hs.pure AllPackedTypes) <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1))) + <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2))) + <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 3))) + <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 4))) + <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 5))) + <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 6))) + <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 7))) + <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 8))) + <*> + ((Hs.pure (Hs.fmap HsProtobuf.signed)) <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 9)))) + <*> + ((Hs.pure (Hs.fmap HsProtobuf.signed)) <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 10)))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Repeated HsProtobuf.UInt32) + (HsProtobuf.Single "packedWord32") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Repeated HsProtobuf.UInt64) + (HsProtobuf.Single "packedWord64") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 3) + (HsProtobuf.Repeated HsProtobuf.Int32) + (HsProtobuf.Single "packedInt32") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 4) + (HsProtobuf.Repeated HsProtobuf.Int64) + (HsProtobuf.Single "packedInt64") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 5) + (HsProtobuf.Repeated HsProtobuf.Fixed32) + (HsProtobuf.Single "packedFixed32") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 6) + (HsProtobuf.Repeated HsProtobuf.Fixed64) + (HsProtobuf.Single "packedFixed64") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 7) + (HsProtobuf.Repeated HsProtobuf.Float) + (HsProtobuf.Single "packedFloat") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 8) + (HsProtobuf.Repeated HsProtobuf.Double) + (HsProtobuf.Single "packedDouble") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 9) + (HsProtobuf.Repeated HsProtobuf.SFixed32) + (HsProtobuf.Single "packedSFixed32") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 10) + (HsProtobuf.Repeated HsProtobuf.SFixed64) + (HsProtobuf.Single "packedSFixed64") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing)] + +data OutOfOrderFields = OutOfOrderFields{outOfOrderFieldsField1 :: + Hs.Vector Hs.Word32, + outOfOrderFieldsField2 :: Hs.Text, + outOfOrderFieldsField3 :: Hs.Int64, + outOfOrderFieldsField4 :: Hs.Vector Hs.Text} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named OutOfOrderFields where + nameOf _ = (Hs.fromString "OutOfOrderFields") + +instance HsProtobuf.Message OutOfOrderFields where + encodeMessage _ + OutOfOrderFields{outOfOrderFieldsField1 = outOfOrderFieldsField1, + outOfOrderFieldsField2 = outOfOrderFieldsField2, + outOfOrderFieldsField3 = outOfOrderFieldsField3, + outOfOrderFieldsField4 = outOfOrderFieldsField4} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2001) + (HsProtobuf.PackedVec outOfOrderFieldsField1)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 101) + outOfOrderFieldsField2), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 30) + outOfOrderFieldsField3), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1002) + (HsProtobuf.UnpackedVec outOfOrderFieldsField4))]) + decodeMessage _ + = (Hs.pure OutOfOrderFields) <*> + ((Hs.pure HsProtobuf.packedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2001))) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 101)) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 30)) + <*> + ((Hs.pure HsProtobuf.unpackedvec) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1002))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2001) + (HsProtobuf.Repeated HsProtobuf.UInt32) + (HsProtobuf.Single "field1") + [(HsProtobuf.DotProtoOption (HsProtobuf.Single "packed") + (HsProtobuf.BoolLit Hs.True))] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 101) + (HsProtobuf.Prim HsProtobuf.String) + (HsProtobuf.Single "field2") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 30) + (HsProtobuf.Prim HsProtobuf.Int64) + (HsProtobuf.Single "field3") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1002) + (HsProtobuf.Repeated HsProtobuf.String) + (HsProtobuf.Single "field4") + [] + Hs.Nothing)] + +data ShadowedMessage = ShadowedMessage{shadowedMessageName :: + Hs.Text, + shadowedMessageValue :: Hs.Int32} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named ShadowedMessage where + nameOf _ = (Hs.fromString "ShadowedMessage") + +instance HsProtobuf.Message ShadowedMessage where + encodeMessage _ + ShadowedMessage{shadowedMessageName = shadowedMessageName, + shadowedMessageValue = shadowedMessageValue} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) + shadowedMessageName), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + shadowedMessageValue)]) + decodeMessage _ + = (Hs.pure ShadowedMessage) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2)) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1)) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Prim HsProtobuf.String) + (HsProtobuf.Single "name") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim HsProtobuf.Int32) + (HsProtobuf.Single "value") + [] + Hs.Nothing)] + +data MessageShadower = MessageShadower{messageShadowerShadowedMessage + :: Hs.Maybe MessageShadower_ShadowedMessage, + messageShadowerName :: Hs.Text} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named MessageShadower where + nameOf _ = (Hs.fromString "MessageShadower") + +instance HsProtobuf.Message MessageShadower where + encodeMessage _ + MessageShadower{messageShadowerShadowedMessage = + messageShadowerShadowedMessage, + messageShadowerName = messageShadowerName} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Nested messageShadowerShadowedMessage)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) + messageShadowerName)]) + decodeMessage _ + = (Hs.pure MessageShadower) <*> + ((Hs.pure HsProtobuf.nested) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1))) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2)) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim + (HsProtobuf.Named (HsProtobuf.Single "ShadowedMessage"))) + (HsProtobuf.Single "shadowed_message") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Prim HsProtobuf.String) + (HsProtobuf.Single "name") + [] + Hs.Nothing)] + +data MessageShadower_ShadowedMessage = MessageShadower_ShadowedMessage{messageShadower_ShadowedMessageName + :: Hs.Text, + messageShadower_ShadowedMessageValue + :: Hs.Text} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named MessageShadower_ShadowedMessage where + nameOf _ = (Hs.fromString "MessageShadower_ShadowedMessage") + +instance HsProtobuf.Message MessageShadower_ShadowedMessage where + encodeMessage _ + MessageShadower_ShadowedMessage{messageShadower_ShadowedMessageName + = messageShadower_ShadowedMessageName, + messageShadower_ShadowedMessageValue = + messageShadower_ShadowedMessageValue} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + messageShadower_ShadowedMessageName), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) + messageShadower_ShadowedMessageValue)]) + decodeMessage _ + = (Hs.pure MessageShadower_ShadowedMessage) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1)) + <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 2)) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim HsProtobuf.String) + (HsProtobuf.Single "name") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) + (HsProtobuf.Prim HsProtobuf.String) + (HsProtobuf.Single "value") + [] + Hs.Nothing)] + +data WithQualifiedName = WithQualifiedName{withQualifiedNameQname1 + :: Hs.Maybe ShadowedMessage, + withQualifiedNameQname2 :: + Hs.Maybe MessageShadower_ShadowedMessage} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named WithQualifiedName where + nameOf _ = (Hs.fromString "WithQualifiedName") + +instance HsProtobuf.Message WithQualifiedName where + encodeMessage _ + WithQualifiedName{withQualifiedNameQname1 = + withQualifiedNameQname1, + withQualifiedNameQname2 = withQualifiedNameQname2} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 100) + (HsProtobuf.Nested withQualifiedNameQname1)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 200) + (HsProtobuf.Nested withQualifiedNameQname2))]) + decodeMessage _ + = (Hs.pure WithQualifiedName) <*> + ((Hs.pure HsProtobuf.nested) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 100))) + <*> + ((Hs.pure HsProtobuf.nested) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 200))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 100) + (HsProtobuf.Prim + (HsProtobuf.Named (HsProtobuf.Single "ShadowedMessage"))) + (HsProtobuf.Single "qname1") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 200) + (HsProtobuf.Prim + (HsProtobuf.Named + (HsProtobuf.Path ["MessageShadower", "ShadowedMessage"]))) + (HsProtobuf.Single "qname2") + [] + Hs.Nothing)] + +data UsingImported = UsingImported{usingImportedImportedNesting :: + Hs.Maybe GeneratedImportedTestTypes.WithNesting, + usingImportedLocalNesting :: Hs.Maybe WithNesting} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named UsingImported where + nameOf _ = (Hs.fromString "UsingImported") + +instance HsProtobuf.Message UsingImported where + encodeMessage _ + UsingImported{usingImportedImportedNesting = + usingImportedImportedNesting, + usingImportedLocalNesting = usingImportedLocalNesting} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 100) + (HsProtobuf.Nested usingImportedImportedNesting)), + (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 200) + (HsProtobuf.Nested usingImportedLocalNesting))]) + decodeMessage _ + = (Hs.pure UsingImported) <*> + ((Hs.pure HsProtobuf.nested) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 100))) + <*> + ((Hs.pure HsProtobuf.nested) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 200))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 100) + (HsProtobuf.Prim + (HsProtobuf.Named + (HsProtobuf.Path ["GeneratedImportedTestTypes", "WithNesting"]))) + (HsProtobuf.Single "importedNesting") + [] + Hs.Nothing), + (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 200) + (HsProtobuf.Prim + (HsProtobuf.Named (HsProtobuf.Single "WithNesting"))) + (HsProtobuf.Single "localNesting") + [] + Hs.Nothing)] + +data Wrapped = Wrapped{wrappedWrapped :: Hs.Maybe Wrapped} + deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic) + +instance HsProtobuf.Named Wrapped where + nameOf _ = (Hs.fromString "Wrapped") + +instance HsProtobuf.Message Wrapped where + encodeMessage _ Wrapped{wrappedWrapped = wrappedWrapped} + = (Hs.mconcat + [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Nested wrappedWrapped))]) + decodeMessage _ + = (Hs.pure Wrapped) <*> + ((Hs.pure HsProtobuf.nested) <*> + (HsProtobuf.at HsProtobuf.decodeMessageField + (HsProtobuf.FieldNumber 1))) + dotProto _ + = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) + (HsProtobuf.Prim (HsProtobuf.Named (HsProtobuf.Single "Wrapped"))) + (HsProtobuf.Single "wrapped") + [] + Hs.Nothing)] \ No newline at end of file diff --git a/tests/Main.hs b/tests/Main.hs index 10b49073..85aa7008 100644 --- a/tests/Main.hs +++ b/tests/Main.hs @@ -1,351 +1,229 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedLists #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE OverloadedLists #-} + {-# OPTIONS_GHC -fno-warn-orphans #-} module Main where -import Control.Applicative -import Control.Exception -import TestTypes -import TestCodeGen -import qualified Data.ByteString as B -import qualified Data.ByteString.Lazy as BL -import qualified Data.ByteString.Builder as BB -import qualified Data.ByteString.Char8 as BC -import Test.Tasty -import Test.Tasty.HUnit (Assertion, (@?=), (@=?), testCase, assertBool) -import Test.Tasty.QuickCheck (testProperty, (===)) -import Test.QuickCheck (Arbitrary, Property, - arbitrary, counterexample, oneof) -import Data.Int -import Data.Maybe (fromJust) -import Data.Word (Word64) -import qualified Data.Text.Lazy as TL -import Data.Serialize.Get(runGet) -import Data.Either (isRight) +import qualified Data.ByteString as B +import qualified Data.ByteString.Char8 as BC +import qualified Data.ByteString.Lazy as BL +import Data.Either (isRight) +import Data.Monoid +import Data.Proxy +import Data.String +import GHC.Exts (fromList) import Proto3.Suite -import Proto3.Suite.DotProto as AST -import Proto3.Wire -import Proto3.Wire.Decode (ParseError) -import qualified Proto3.Wire.Decode as Decode -import qualified Proto3.Wire.Encode as Encode -import Proto3.Wire.Types as P -import GHC.Exts (fromList) +import Proto3.Wire.Decode (ParseError) +import qualified Proto3.Wire.Decode as Decode +import Proto3.Wire.Types as P +import Test.QuickCheck (Arbitrary, Property, arbitrary, + counterexample, oneof) +import Test.Tasty +import Test.Tasty.HUnit (Assertion, assertBool, testCase, + (@=?), (@?=)) +import Test.Tasty.QuickCheck (testProperty, (===)) + +-- NB: GeneratedTestTypes.hs etc. should be manually generated via something +-- like: +-- +-- [nix-shell]$ compile-proto-file --proto test-files/test.proto > tests/GeneratedTestTypes.hs +-- [nix-shell]$ compile-proto-file --proto test-files/test_import.proto > tests/GeneratedImportedTestTypes.hs +-- +-- And these commands would need to be run whenever test.proto or +-- test_import.proto change. +-- +-- However, compile-proto-file hasn't been taken out of grpc-haskell and put +-- into this package where it belongs, and so doing the above doesn't work yet +-- while iterating on the code generation. Here's the quick and dirty way to +-- invoke CG in the meantime (a fix for this is intended soon): +-- +-- Load this module into ghci from the root of the repository, then: +-- +-- > Right (dp, tc) <- readDotProtoWithContext "/path/to/repo/root/test-files/test.proto" +-- > let Right src = renderHsModuleForDotProto dp tc +-- > writeFile "/path/to/repo/root/tests/GeneratedTestTypes.hs" src +-- > Right (dp, tc) <- readDotProtoWithContext "/path/to/repo/root/test-files/test_import.proto" +-- > let Right src = renderHsModuleForDotProto dp tc +-- > writeFile "/path/to/repo/root/tests/GeneratedImportedTestTypes.hs" src +-- +-- TODO: Get compile-proto-file into the repository. +-- TODO: Automate generation of these modules as a part of the build process. + +import ArbitraryGeneratedTestTypes () +import qualified GeneratedTestTypes as GTT + +import TestCodeGen main :: IO () main = defaultMain tests tests :: TestTree -tests = testGroup "Tests" [qcProperties, encodeUnitTests, decodeUnitTests, - parserUnitTests, dotProtoUnitTests, codeGenTests] - -instance Arbitrary WireType where - arbitrary = oneof $ map return [Varint, P.Fixed32, P.Fixed64, LengthDelimited] +tests = testGroup "Tests" + [ qcProperties + , encodeUnitTests + , decodeUnitTests + , parserUnitTests + , dotProtoUnitTests + , codeGenTests + ] -qcInverses :: (Message a, Arbitrary a, Eq a, Show a) => a -> Property -qcInverses msg = msg === (decode $ encode msg) - where decode x = case fromByteString x of - Left e -> error $ "got error parsing: " ++ show e - Right r -> r - encode = BL.toStrict . toLazyByteString +-------------------------------------------------------------------------------- +-- QuickCheck properties -deeplyNested :: String -> Int -> TestTree -deeplyNested name = go (qcInverses :: Trivial -> Property) - where - go :: (Message a, Named a, Arbitrary a, Eq a, Show a) => (a -> Property) -> Int -> TestTree - go prop 0 = testProperty name prop - go prop n = go (prop . fromJust . nested . unNestedAlways . unWrapped) (n - 1) +type MsgProp a = a -> Property qcProperties :: TestTree qcProperties = testGroup "QuickCheck properties" - [ testProperty "decode inverts encode for trivial messages" $ - (qcInverses :: Trivial -> Property) - - , testProperty "decode inverts encode for multi-field messages" $ - (qcInverses :: MultipleFields -> Property) - - , testProperty "decode inverts encode for enum messages" $ - (qcInverses :: WithEnum -> Property) + [ qcPropDecEncId + ] - , testProperty "decode inverts encode for nested messages" $ - (qcInverses :: WithNesting -> Property) +-- | Verifies that @decode . encode = id@ for various message types +qcPropDecEncId :: TestTree +qcPropDecEncId = testGroup "Property: (decode . encode = id) for various message types" + [ testProperty "Trivial" (prop :: MsgProp GTT.Trivial) + , testProperty "MultipleFields" (prop :: MsgProp GTT.MultipleFields) + , testProperty "WithEnum" (prop :: MsgProp GTT.WithEnum) + , testProperty "WithNesting" (prop :: MsgProp GTT.WithNesting) + , testProperty "WithRepetition" (prop :: MsgProp GTT.WithRepetition) + , testProperty "WithFixed" (prop :: MsgProp GTT.WithFixed) + , testProperty "WithBytes" (prop :: MsgProp GTT.WithBytes) + , testProperty "AllPackedTypes" (prop :: MsgProp GTT.AllPackedTypes) + , testProperty "SignedInts" (prop :: MsgProp GTT.SignedInts) + , testProperty "WithNestingRepeated" (prop :: MsgProp GTT.WithNestingRepeated) + , deeplyNest prop 1000 + ] + where + prop :: (Message a, Arbitrary a, Eq a, Show a) => MsgProp a + prop msg = msg === (dec . enc) msg + where + dec = either (error . ("error parsing: " <>) . show) id . fromByteString + enc = BL.toStrict . toLazyByteString - , testProperty "decode inverts encode for repeated field messages" $ - (qcInverses :: WithRepetition -> Property) + deeplyNest :: MsgProp GTT.Wrapped -> Int -> TestTree + deeplyNest pf 0 = testProperty "Deeply nested" pf + deeplyNest pf n = deeplyNest (pf . GTT.Wrapped . Just) (n-1) - , testProperty "decode inverts encode for messages with fixed fields" $ - (qcInverses :: WithFixed -> Property) - , testProperty "decode inverts encode for messages with bytes fields" $ - (qcInverses :: WithBytes -> Property) +-------------------------------------------------------------------------------- +-- Encoding - , testProperty "decode inverts encode for all packed repeated types" $ - (qcInverses :: AllPackedTypes -> Property) +encodeUnitTests :: TestTree +encodeUnitTests = testGroup "Encoder unit tests" + [ encoderMatchesGoldens + ] - , testProperty "decode inverts encode for signed integer types" $ - (qcInverses :: SignedInts -> Property) +-- TODO: We should consider generating the reference encodings +-- (test-files/make_reference_encodings.py) as a part of running the test suite +-- rather than having them in the repository. +encoderMatchesGoldens :: TestTree +encoderMatchesGoldens = testGroup "Encoder matches golden encodings" + [ check "trivial.bin" $ GTT.Trivial 123 + , check "trivial_negative.bin" $ GTT.Trivial (-1) + , check "multiple_fields.bin" $ GTT.MultipleFields 1.23 (-0.5) 123 1234567890 "Hello, world!" True + , check "signedints.bin" $ GTT.SignedInts (-42) (-84) + , check "with_nesting.bin" $ GTT.WithNesting $ Just $ GTT.WithNesting_Nested "123abc" 123456 [] [] + , check "with_enum0.bin" $ GTT.WithEnum $ Enumerated $ Right $ GTT.WithEnum_TestEnumENUM1 + , check "with_enum1.bin" $ GTT.WithEnum $ Enumerated $ Right $ GTT.WithEnum_TestEnumENUM2 + , check "with_repetition.bin" $ GTT.WithRepetition [1..5] + , check "with_bytes.bin" $ GTT.WithBytes (BC.pack "abc") (fromList $ map BC.pack ["abc","123"]) + , check "with_nesting_repeated.bin" $ GTT.WithNestingRepeated + [ GTT.WithNestingRepeated_Nested "123abc" 123456 [1,2,3,4] [5,6,7,8] + , GTT.WithNestingRepeated_Nested "abc123" 654321 [0,9,8,7] [6,5,4,3] + ] + ] + where + check fp v = testCase fp $ do + goldenEncoding <- BL.readFile (testFilesPfx <> fp) + toLazyByteString v @?= goldenEncoding - , testProperty "decode inverts encode for repeated messages" $ - (qcInverses :: WithNestingRepeated -> Property) +-------------------------------------------------------------------------------- +-- Decoding - , deeplyNested "decode inverts encode for deeply nested messages" 10000 +decodeUnitTests :: TestTree +decodeUnitTests = testGroup "Decoder unit tests" + [ decodeFromGoldens ] -encodeUnitTests :: TestTree -encodeUnitTests = testGroup "Encoding unit tests" - [encodeTrivialMessage, - encodeNegativeInt, - encodeMultipleFields, - encodeSignedInts, - encodeNestedMessage, - encodeEnumFirstAlternative, - encodeEnumSecondAlternative, - encodeRepetition, - encodeBytes, - --encodeNestedMaybe - encodeWithNestingRepeated - ] - -checkEncoding :: Message a => FilePath -> a -> IO () -checkEncoding fp x = do let ourEncoding = toLazyByteString x - referenceEncoding <- BL.readFile fp - ourEncoding @?= referenceEncoding - -encodeTrivialMessage :: TestTree -encodeTrivialMessage = testCase - "Encoding a trivial message matches the official implementation" $ - checkEncoding "test-files/trivial.bin" $ Trivial 123 - -encodeNegativeInt :: TestTree -encodeNegativeInt = testCase - "Encoding a message with a negative int matches the official implementation" $ - checkEncoding "test-files/trivial_negative.bin" $ Trivial (-1) - -encodeMultipleFields :: TestTree -encodeMultipleFields = testCase - "Encoding a message with many fields matches the official implementation" $ - checkEncoding "test-files/multiple_fields.bin" $ - MultipleFields 1.23 (-0.5) 123 1234567890 "Hello, world!" True - -encodeSignedInts :: TestTree -encodeSignedInts = testCase - "Encoding a message containing signed ints matches the official implementation" $ - checkEncoding "test-files/signedints.bin" (SignedInts (-42) (-84)) - -encodeNestedMessage :: TestTree -encodeNestedMessage = testCase - "Encoding a message with nesting matches the official implementation" $ - checkEncoding "test-files/with_nesting.bin" $ - WithNesting $ Nested $ Just $ NestedMsg "123abc" 123456 [] [] - -encodeEnumFirstAlternative :: TestTree -encodeEnumFirstAlternative = testCase - "Encoding an enum with case 0 matches the official implementation" $ - checkEncoding "test-files/with_enum0.bin" $ - WithEnum $ Enumerated (Right ENUM1) - -encodeEnumSecondAlternative :: TestTree -encodeEnumSecondAlternative = testCase - "Encoding an enum with case 1 matches the official implementation" $ - checkEncoding "test-files/with_enum1.bin" $ - WithEnum $ Enumerated (Right ENUM2) - -encodeRepetition :: TestTree -encodeRepetition = testCase - "Encoding a message with repetition matches the official implementation" $ - checkEncoding "test-files/with_repetition.bin" $ WithRepetition [1..5] - -encodeBytes :: TestTree -encodeBytes = testCase - "Encoding a message with bytes fields matches the official implementation" $ - checkEncoding "test-files/with_bytes.bin" $ - WithBytes (BC.pack "abc") (fromList $ map BC.pack ["abc","123"]) - -encodeWithNestingRepeated :: TestTree -encodeWithNestingRepeated = testCase - "Encoding repeated embedded messages matches the official implementation" $ - checkEncoding "test-files/with_nesting_repeated.bin" $ - WithNestingRepeated [NestedMsg "123abc" 123456 [1,2,3,4] [5,6,7,8], - NestedMsg "abc123" 654321 [0,9,8,7] [6,5,4,3]] +decodeFromGoldens :: TestTree +decodeFromGoldens = testGroup "Decode golden encodings into key/value lists" + [ check "trivial.bin" + , check "trivial_negative.bin" + , check "multiple_fields.bin" + , check "signedints.bin" + , check "with_nesting.bin" + , check "with_enum0.bin" + , check "with_enum1.bin" + , check "with_repetition.bin" + , check "with_bytes.bin" + , check "with_nesting_repeated.bin" + ] + where + check fp = testCase fp $ do + kvs <- Decode.decodeWire <$> B.readFile (testFilesPfx <> fp) + assertBool ("parsing " <> fp <> " into a key-value list succeeds") (isRight kvs) -decodeUnitTests :: TestTree -decodeUnitTests = testGroup "Decode unit tests" - [decodeKeyValsTrivial, - decodeKeyValsMultipleFields, - decodeKeyValsSignedInts, - decodeKeyValsNestedMessage, - decodeKeyValsEnumFirstAlternative, - decodeKeyValsEnumSecondAlternative, - decodeKeyValsRepetition] - -decodeKeyValsTest :: FilePath -> IO () -decodeKeyValsTest fp = do - bs <- B.readFile fp - let kvs = Decode.decodeWire bs - assertBool "parsing failed" (isRight kvs) - -decodeKeyValsTrivial :: TestTree -decodeKeyValsTrivial = testCase - "Decoding a trivial message to a key/val list succeeds" $ - decodeKeyValsTest "test-files/trivial.bin" - -decodeKeyValsMultipleFields :: TestTree -decodeKeyValsMultipleFields = testCase - "Decoding a multi-field message to a key/val list succeeds" $ - decodeKeyValsTest "test-files/multiple_fields.bin" - -decodeKeyValsSignedInts :: TestTree -decodeKeyValsSignedInts = testCase - "Decoding a message containing signed ints to a key/val list succeeds" $ - decodeKeyValsTest "test-files/signedints.bin" - -decodeKeyValsNestedMessage :: TestTree -decodeKeyValsNestedMessage = testCase - "Decoding a nested message to a key/val list succeeds" $ - decodeKeyValsTest "test-files/with_nesting.bin" - -decodeKeyValsEnumFirstAlternative :: TestTree -decodeKeyValsEnumFirstAlternative = testCase - "Decoding an Enum (set to the first alternative) to a key/val list succeeds" $ - decodeKeyValsTest "test-files/with_enum0.bin" - -decodeKeyValsEnumSecondAlternative :: TestTree -decodeKeyValsEnumSecondAlternative = testCase - "Decoding an Enum (set to 2nd alternative) to a key/val list succeeds" $ - decodeKeyValsTest "test-files/with_enum1.bin" - -decodeKeyValsRepetition :: TestTree -decodeKeyValsRepetition = testCase - "Decoding a message with a repeated field to a key/val list succeeds" $ - decodeKeyValsTest "test-files/with_repetition.bin" +-------------------------------------------------------------------------------- +-- Parser parserUnitTests :: TestTree -parserUnitTests = testGroup "Parsing unit tests" - [parseTrivial - ,parseMultipleFields - ,parseSignedInts - ,parseNestedMessage - ,parseEnumFirstAlternative - ,parseEnumSecondAlternative - ,parseRepetition - ,parseFixed - ,parseBytes - ,parsePackedUnpacked - ,parseAllPackedTypes - ,parseWithNestingRepeated - ,parseWithNestingRepeatedAbsent - ,parseWithNestingInt - ] - -testParser :: (Show a, Eq a) => - FilePath - -> (B.ByteString -> Either ParseError a) -> a -> IO () +parserUnitTests = testGroup "Parser unit tests" + [ parseFromGoldens + ] + +parseFromGoldens :: TestTree +parseFromGoldens = testGroup "Parse golden encodings" + [ check "trivial.bin" $ GTT.Trivial 123 + , check "multiple_fields.bin" $ GTT.MultipleFields 1.23 (-0.5) 123 1234567890 "Hello, world!" True + , check "signedints.bin" $ GTT.SignedInts (-42) (-84) + , check "with_nesting.bin" $ GTT.WithNesting $ Just $ GTT.WithNesting_Nested "123abc" 123456 [] [] + , check "with_enum0.bin" $ GTT.WithEnum $ Enumerated $ Right $ GTT.WithEnum_TestEnumENUM1 + , check "with_enum1.bin" $ GTT.WithEnum $ Enumerated $ Right $ GTT.WithEnum_TestEnumENUM2 + , check "with_repetition.bin" $ GTT.WithRepetition [1..5] + , check "with_fixed.bin" $ GTT.WithFixed (Fixed 16) (Fixed (-123)) (Fixed 4096) (Fixed (-4096)) + , check "with_bytes.bin" $ GTT.WithBytes (BC.pack "abc") (fromList $ map BC.pack ["abc","123"]) + , check "with_packing.bin" $ GTT.WithPacking [1,2,3] [1,2,3] + , check "all_packed_types.bin" $ GTT.AllPackedTypes + [1,2,3] + [1,2,3] + [-1,-2,-3] + [-1,-2,-3] + (fromList $ map Fixed [1..3]) + (fromList $ map Fixed [1..3]) + [1.0,2.0] + [1.0,-1.0] + (fromList $ map Fixed [1,2,3]) + (fromList $ map Fixed [1,2,3]) + , check "with_nesting_repeated.bin" $ GTT.WithNestingRepeated + [ GTT.WithNestingRepeated_Nested "123abc" 123456 [1,2,3,4] [5,6,7,8] + , GTT.WithNestingRepeated_Nested "abc123" 654321 [0,9,8,7] [6,5,4,3] + ] + , -- Checks parsing repeated embedded messages when one is expected (i.e., + -- this tests correct merging; this value was encoded as a + -- WithNestingRepeated). + check "with_nesting_repeated.bin" $ GTT.WithNesting $ Just $ GTT.WithNesting_Nested "abc123" 654321 [1,2,3,4,0,9,8,7] [5,6,7,8,6,5,4,3] + , -- Checks that embedded message merging works correctly when fields have + -- default values; this value was encoded as a WithNestingRepeatedInts + check "with_nesting_ints.bin" $ GTT.WithNestingInts $ Just $ GTT.NestedInts 2 2 + ] + where + check fp = testCase fp . testParser (testFilesPfx <> fp) fromByteString + +testParser :: (Show a, Eq a) + => FilePath -> (B.ByteString -> Either ParseError a) -> a -> IO () testParser fp p reference = do bs <- B.readFile fp case p bs of - Left err -> error $ "Got error: " ++ show err + Left err -> error $ "Got error: " ++ show err Right ourResult -> ourResult @?= reference -parseTrivial :: TestTree -parseTrivial = testCase - "Parsing a trivial message matches the official implementation" $ - testParser "test-files/trivial.bin" fromByteString $ Trivial 123 - -parseMultipleFields :: TestTree -parseMultipleFields = testCase - "Parsing a message with multiple fields matches the official implementation" $ - testParser "test-files/multiple_fields.bin" fromByteString - $ MultipleFields 1.23 (-0.5) 123 1234567890 "Hello, world!" True - -parseSignedInts :: TestTree -parseSignedInts = testCase - "Parsing a message containing signed ints matches the official implementation" $ - testParser "test-files/signedints.bin" fromByteString $ SignedInts (-42) (-84) - -parseNestedMessage :: TestTree -parseNestedMessage = testCase - "Parsing a nested message matches the official implementation" $ - testParser "test-files/with_nesting.bin" fromByteString $ - WithNesting $ Nested $ Just $ NestedMsg "123abc" 123456 [] [] - -parseEnumFirstAlternative :: TestTree -parseEnumFirstAlternative = testCase - "Parsing an enum (first case) message matches the official implementation" $ - testParser "test-files/with_enum0.bin" fromByteString $ - WithEnum $ Enumerated (Right ENUM1) - -parseEnumSecondAlternative :: TestTree -parseEnumSecondAlternative = testCase - "Parsing an enum (2nd case) message matches the official implementation" $ - testParser "test-files/with_enum1.bin" fromByteString $ - WithEnum $ Enumerated (Right ENUM2) - -parseRepetition :: TestTree -parseRepetition = testCase - "Parsing a message with a repeated field matches the official implementation" - $ - testParser "test-files/with_repetition.bin" fromByteString $ - WithRepetition [1..5] - -parseFixed :: TestTree -parseFixed = testCase - "Parsing a message with fixed types matches the official implementation" $ - testParser "test-files/with_fixed.bin" fromByteString $ - WithFixed (Fixed 16) (Signed $ Fixed (-123)) - (Fixed 4096) (Signed $ Fixed (-4096)) - -parseBytes :: TestTree -parseBytes = testCase - "Parsing a message containing bytes matches the official implementation" $ - testParser "test-files/with_bytes.bin" fromByteString $ - WithBytes (BC.pack "abc") (fromList $ map BC.pack ["abc","123"]) - -parsePackedUnpacked :: TestTree -parsePackedUnpacked = testCase - "Parsing packed and unpacked fields matches the official implementation" $ - testParser "test-files/with_packing.bin" fromByteString $ - WithPacking [1,2,3] [1,2,3] - -parseAllPackedTypes :: TestTree -parseAllPackedTypes = testCase - "Parsing all types of packed fields matches the official implementation" $ - testParser "test-files/all_packed_types.bin" fromByteString $ - AllPackedTypes [1,2,3] - [1,2,3] - [-1,-2,-3] - [-1,-2,-3] - (fromList $ map Fixed [1..3]) - (fromList $ map Fixed [1..3]) - [1.0,2.0] - [1.0,-1.0] - (fromList $ map (Signed . Fixed) [1,2,3]) - (fromList $ map (Signed . Fixed) [1,2,3]) - -parseWithNestingRepeated :: TestTree -parseWithNestingRepeated = testCase - "Parsing repeated embedded messages matches the official implementation" $ - testParser "test-files/with_nesting_repeated.bin" fromByteString $ - WithNestingRepeated [NestedMsg "123abc" 123456 [1,2,3,4] [5,6,7,8], - NestedMsg "abc123" 654321 [0,9,8,7] [6,5,4,3]] - -parseWithNestingRepeatedAbsent :: TestTree -parseWithNestingRepeatedAbsent = testCase - "Parsing repeated embedded messages when one is expected: correct merging" $ - testParser "test-files/with_nesting_repeated.bin" fromByteString $ - WithNestingRepeatedAbsent $ Nested $ - Just $ NestedMsg "abc123" 654321 [1,2,3,4,0,9,8,7] [5,6,7,8,6,5,4,3] - -parseWithNestingInt :: TestTree -parseWithNestingInt = testCase - "Embedded message merging works correctly when fields have default values" $ - testParser "test-files/with_nesting_ints.bin" fromByteString $ - WithNestingRepeatedInts $ Nested $ Just $ NestedInt 2 2 - testDotProtoParse :: FilePath -> DotProto -> Assertion -testDotProtoParse file ast = do contents <- readFile file - case parseProto contents of - Left err -> error $ show err - Right result -> ast @=? result +testDotProtoParse file ast = do + contents <- readFile file + case parseProto contents of + Left err -> error $ show err + Right result -> ast @=? result testDotProtoPrint :: DotProto -> String -> Assertion testDotProtoPrint ast expected = expected @=? toProtoFileDef ast @@ -356,47 +234,47 @@ testDotProtoRoundtrip ast = let Right result = parseProto $ toProtoFileDef ast dotProtoUnitTests :: TestTree dotProtoUnitTests = testGroup ".proto parsing tests" - [ dotProtoParseTrivial - , dotProtoPrintTrivial - , dotProtoRoundtripTrivial - , dotProtoRoundtripSimpleMessage - , qcDotProtoRoundtrip - ] + [ dotProtoParseTrivial + , dotProtoPrintTrivial + , dotProtoRoundtripTrivial + , dotProtoRoundtripSimpleMessage + , qcDotProtoRoundtrip + ] trivialDotProto :: DotProto trivialDotProto = DotProto [] [] DotProtoNoPackage [] dotProtoParseTrivial :: TestTree dotProtoParseTrivial = testCase - "Parsing a content-less file behaves as expected" $ + "Parse a content-less file" $ testDotProtoParse "test-files/trivial.proto" trivialDotProto dotProtoPrintTrivial :: TestTree dotProtoPrintTrivial = testCase - "Printing a content-less DotProto behaves as expected" $ + "Print a content-less DotProto" $ testDotProtoPrint trivialDotProto "syntax = \"proto3\";" dotProtoRoundtripTrivial :: TestTree dotProtoRoundtripTrivial = testCase - "Printing then parsing a content-less DotProto returns an empty DotProto" $ + "Printing then parsing a content-less DotProto yields an empty DotProto" $ testDotProtoRoundtrip trivialDotProto dotProtoSimpleMessage :: DotProto -dotProtoSimpleMessage = DotProto [] [] DotProtoNoPackage [DotProtoMessage (Single "MessageTest") - [DotProtoMessageField $ DotProtoField (fieldNumber 1) - (Prim Int32) - (Single "testfield") - [] - Nothing ]] +dotProtoSimpleMessage = DotProto [] [] DotProtoNoPackage + [ DotProtoMessage (Single "MessageTest") + [ DotProtoMessageField $ + DotProtoField (fieldNumber 1) (Prim Int32) (Single "testfield") [] Nothing + ] + ] dotProtoRoundtripSimpleMessage :: TestTree dotProtoRoundtripSimpleMessage = testCase - "Rountrip for a single, flat message" $ + "Round-trip for a single flat message" $ testDotProtoRoundtrip dotProtoSimpleMessage qcDotProtoRoundtrip :: TestTree qcDotProtoRoundtrip = testProperty - "Rountrip for a randomly-generated .proto AST" roundtrip + "Round-trip for a randomly-generated .proto AST" roundtrip where roundtrip :: DotProto -> Property roundtrip ast = let generated = toProtoFileDef ast @@ -417,3 +295,20 @@ qcDotProtoRoundtrip = testProperty ++ "\n\nWhen attempting to parse:\n\n" ++ generated ++ "\n\nInitial AST:\n\n" + +-------------------------------------------------------------------------------- +-- Helpers + +dotProtoFor :: (Named a, Message a) => Proxy a -> DotProto +dotProtoFor proxy = DotProto [] [] DotProtoNoPackage + [ DotProtoMessage (Single (nameOf proxy)) (DotProtoMessageField <$> dotProto proxy) + ] + +showDotProtoFor :: (Named a, Message a) => Proxy a -> IO () +showDotProtoFor = putStrLn . toProtoFileDef . dotProtoFor + +instance Arbitrary WireType where + arbitrary = oneof $ map return [Varint, P.Fixed32, P.Fixed64, LengthDelimited] + +testFilesPfx :: IsString a => a +testFilesPfx = "test-files/" diff --git a/tests/TestTypes.hs b/tests/OldTestTypes.hs similarity index 94% rename from tests/TestTypes.hs rename to tests/OldTestTypes.hs index dd13409f..44bc1470 100644 --- a/tests/TestTypes.hs +++ b/tests/OldTestTypes.hs @@ -1,7 +1,8 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} -module TestTypes where +module OldTestTypes where import qualified Data.ByteString as B import Data.Int @@ -31,6 +32,7 @@ data MultipleFields = multiFieldBool :: Bool} deriving (Show, Generic, Eq) instance Message MultipleFields +instance Named MultipleFields instance Arbitrary MultipleFields where arbitrary = MultipleFields @@ -73,6 +75,7 @@ instance Arbitrary NestedMsg where data WithNesting = WithNesting {nestedMessage :: Nested NestedMsg} deriving (Show, Generic, Eq) instance Message WithNesting +instance Named WithNesting instance Arbitrary WithNesting where arbitrary = WithNesting <$> arbitrary @@ -97,6 +100,7 @@ instance Arbitrary a => Arbitrary (Wrapped a) where data WithRepetition = WithRepetition {repeatedField1 :: PackedVec Int32} deriving (Show, Generic, Eq) instance Message WithRepetition +instance Named WithRepetition instance Arbitrary WithRepetition where arbitrary = WithRepetition <$> arbitrary @@ -107,6 +111,7 @@ data WithFixed = WithFixed {fixed1 :: (Fixed Word32), fixed4 :: (Signed (Fixed Int64))} deriving (Show, Generic, Eq) instance Message WithFixed +instance Named WithFixed instance Arbitrary WithFixed where arbitrary = WithFixed <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary @@ -115,6 +120,7 @@ data WithBytes = WithBytes {bytes1 :: B.ByteString, bytes2 :: UnpackedVec B.ByteString} deriving (Show, Generic, Eq) instance Message WithBytes +instance Named WithBytes instance Arbitrary B.ByteString where arbitrary = fmap B.pack arbitrary @@ -126,6 +132,7 @@ data WithPacking = WithPacking {packing1 :: UnpackedVec Int32, packing2 :: PackedVec Int32} deriving (Show, Generic, Eq) instance Message WithPacking +instance Named WithPacking instance Arbitrary WithPacking where arbitrary = WithPacking <$> arbitrary <*> arbitrary @@ -143,6 +150,7 @@ data AllPackedTypes = packedSFixed64 :: PackedVec (Signed (Fixed Int64))} deriving (Show, Generic, Eq) instance Message AllPackedTypes +instance Named AllPackedTypes instance Arbitrary AllPackedTypes where arbitrary = AllPackedTypes <$> arbitrary <*> arbitrary <*> arbitrary @@ -155,6 +163,7 @@ data SignedInts = signed64 :: Signed Int64} deriving (Show, Generic, Eq) instance Message SignedInts +instance Named SignedInts instance Arbitrary SignedInts where arbitrary = SignedInts <$> arbitrary <*> arbitrary @@ -163,6 +172,7 @@ data WithNestingRepeated = WithNestingRepeated {nestedMessages :: NestedVec NestedMsg} deriving (Show, Eq, Generic) instance Message WithNestingRepeated +instance Named WithNestingRepeated instance Arbitrary WithNestingRepeated where arbitrary = WithNestingRepeated <$> arbitrary @@ -184,3 +194,4 @@ data WithNestingRepeatedInts = WithNestingRepeatedInts {nestedInts :: Nested NestedInt} deriving (Show, Eq, Generic) instance Message WithNestingRepeatedInts +instance Named WithNestingRepeatedInts diff --git a/tests/SimpleDecodeDotProto.hs b/tests/SimpleDecodeDotProto.hs index 4eea71ed..c484ad31 100644 --- a/tests/SimpleDecodeDotProto.hs +++ b/tests/SimpleDecodeDotProto.hs @@ -4,8 +4,7 @@ module Main where -import Test -import qualified TestImport + import Test.Tasty import Test.Tasty.HUnit (Assertion, (@?=), (@=?), testCase) import Control.Applicative @@ -15,6 +14,9 @@ import qualified Data.ByteString.Char8 as BC import System.IO import System.Exit +import GeneratedTestTypes +import qualified GeneratedImportedTestTypes + main :: IO () main = do putStr "\n" defaultMain tests @@ -77,7 +79,7 @@ testCase3 = testCase "Nested enumeration" $ testCase4 = testCase "Nested message" $ do WithNesting { withNestingNestedMessage = a } <- readProto - a @?= Just (WithNesting_Nested "testCase4 nestedField1" 0xABCD) + a @?= Just (WithNesting_Nested "testCase4 nestedField1" 0xABCD [] []) WithNesting { withNestingNestedMessage = b } <- readProto b @?= Nothing @@ -96,16 +98,16 @@ testCase5 = testCase "Nested repeated message" $ testCase6 = testCase "Nested repeated int message" $ do WithNestingRepeatedInts { withNestingRepeatedIntsNestedInts = a } <- readProto - a @?= [ WithNestingRepeatedInts_NestedInts 636513 619021 ] + a @?= [ NestedInts 636513 619021 ] WithNestingRepeatedInts { withNestingRepeatedIntsNestedInts = b } <- readProto b @?= [] WithNestingRepeatedInts { withNestingRepeatedIntsNestedInts = c } <- readProto - c @?= [ WithNestingRepeatedInts_NestedInts 636513 619021 - , WithNestingRepeatedInts_NestedInts 423549 687069 - , WithNestingRepeatedInts_NestedInts 545506 143731 - , WithNestingRepeatedInts_NestedInts 193605 385360 ] + c @?= [ NestedInts 636513 619021 + , NestedInts 423549 687069 + , NestedInts 545506 143731 + , NestedInts 193605 385360 ] testCase7 = testCase "Repeated int32 field" $ do WithRepetition { withRepetitionRepeatedField1 = a } <- readProto @@ -115,23 +117,23 @@ testCase7 = testCase "Repeated int32 field" $ b @?= [1..10000] testCase8 = testCase "Fixed-width integer types" $ - do WithFixedTypes { .. } <- readProto - withFixedTypesFixed1 @?= 0 - withFixedTypesFixed2 @?= 0 - withFixedTypesFixed3 @?= 0 - withFixedTypesFixed4 @?= 0 - - WithFixedTypes { .. } <- readProto - withFixedTypesFixed1 @?= maxBound - withFixedTypesFixed2 @?= maxBound - withFixedTypesFixed3 @?= maxBound - withFixedTypesFixed4 @?= maxBound - - WithFixedTypes { .. } <- readProto - withFixedTypesFixed1 @?= minBound - withFixedTypesFixed2 @?= minBound - withFixedTypesFixed3 @?= minBound - withFixedTypesFixed4 @?= minBound + do WithFixed { .. } <- readProto + withFixedFixed1 @?= 0 + withFixedFixed2 @?= 0 + withFixedFixed3 @?= 0 + withFixedFixed4 @?= 0 + + WithFixed { .. } <- readProto + withFixedFixed1 @?= maxBound + withFixedFixed2 @?= maxBound + withFixedFixed3 @?= maxBound + withFixedFixed4 @?= maxBound + + WithFixed { .. } <- readProto + withFixedFixed1 @?= minBound + withFixedFixed2 @?= minBound + withFixedFixed3 @?= minBound + withFixedFixed4 @?= minBound testCase9 = testCase "Bytes fields" $ do WithBytes { .. } <- readProto @@ -216,15 +218,17 @@ testCase14 = testCase "Qualified name resolution" $ withQualifiedNameQname2 @?= Just (MessageShadower_ShadowedMessage "string value" "hello world") testCase15 = testCase "Imported message resolution" $ - do TestImport.WithNesting { .. } <- readProto - withNestingNestedMessage1 @?= Just (TestImport.WithNesting_Nested 1 2) + do GeneratedImportedTestTypes.WithNesting { .. } <- readProto + withNestingNestedMessage1 @?= Just (GeneratedImportedTestTypes.WithNesting_Nested 1 2) withNestingNestedMessage2 @?= Nothing testCase16 = testCase "Proper resolution of shadowed message names" $ do UsingImported { .. } <- readProto - usingImportedImportedNesting @?= Just (TestImport.WithNesting (Just (TestImport.WithNesting_Nested 1 2)) - (Just (TestImport.WithNesting_Nested 3 4))) - usingImportedLocalNesting @?= Just (WithNesting (Just (WithNesting_Nested "field" 0xBEEF))) + usingImportedImportedNesting @?= + Just (GeneratedImportedTestTypes.WithNesting + (Just (GeneratedImportedTestTypes.WithNesting_Nested 1 2)) + (Just (GeneratedImportedTestTypes.WithNesting_Nested 3 4))) + usingImportedLocalNesting @?= Just (WithNesting (Just (WithNesting_Nested "field" 0xBEEF [] []))) allTestsDone = testCase "Receive end of test suite sentinel message" $ do MultipleFields{..} <- readProto diff --git a/tests/SimpleEncodeDotProto.hs b/tests/SimpleEncodeDotProto.hs index 8caf221d..816e2238 100644 --- a/tests/SimpleEncodeDotProto.hs +++ b/tests/SimpleEncodeDotProto.hs @@ -3,8 +3,8 @@ module Main where -import Test -import qualified TestImport +import GeneratedTestTypes +import qualified GeneratedImportedTestTypes import Proto3.Suite import qualified Data.ByteString.Lazy as BL @@ -39,7 +39,7 @@ testCase3 = testCase4 :: IO () testCase4 = - do let nested = WithNesting_Nested "testCase4 nestedField1" 0xABCD + do let nested = WithNesting_Nested "testCase4 nestedField1" 0xABCD [] [] outputMessage (WithNesting (Just nested)) outputMessage (WithNesting Nothing) @@ -54,10 +54,10 @@ testCase5 = testCase6 :: IO () testCase6 = - do let nested1 = WithNestingRepeatedInts_NestedInts 636513 619021 - nested2 = WithNestingRepeatedInts_NestedInts 423549 687069 - nested3 = WithNestingRepeatedInts_NestedInts 545506 143731 - nested4 = WithNestingRepeatedInts_NestedInts 193605 385360 + do let nested1 = NestedInts 636513 619021 + nested2 = NestedInts 423549 687069 + nested3 = NestedInts 545506 143731 + nested4 = NestedInts 193605 385360 outputMessage (WithNestingRepeatedInts [nested1]) outputMessage (WithNestingRepeatedInts []) outputMessage (WithNestingRepeatedInts [nested1, nested2, nested3, nested4]) @@ -69,9 +69,9 @@ testCase7 = testCase8 :: IO () testCase8 = - do outputMessage (WithFixedTypes 0 0 0 0) - outputMessage (WithFixedTypes maxBound maxBound maxBound maxBound) - outputMessage (WithFixedTypes minBound minBound minBound minBound) + do outputMessage (WithFixed 0 0 0 0) + outputMessage (WithFixed maxBound maxBound maxBound maxBound) + outputMessage (WithFixed minBound minBound minBound minBound) testCase9 :: IO () testCase9 = @@ -113,19 +113,19 @@ testCase14 = testCase15 :: IO () testCase15 = - outputMessage (TestImport.WithNesting { TestImport.withNestingNestedMessage1 = - Just (TestImport.WithNesting_Nested { TestImport.withNesting_NestedNestedField1 = 1 - , TestImport.withNesting_NestedNestedField2 = 2 }) - , TestImport.withNestingNestedMessage2 = Nothing }) + outputMessage (GeneratedImportedTestTypes.WithNesting { GeneratedImportedTestTypes.withNestingNestedMessage1 = + Just (GeneratedImportedTestTypes.WithNesting_Nested { GeneratedImportedTestTypes.withNesting_NestedNestedField1 = 1 + , GeneratedImportedTestTypes.withNesting_NestedNestedField2 = 2 }) + , GeneratedImportedTestTypes.withNestingNestedMessage2 = Nothing }) testCase16 :: IO () testCase16 = outputMessage (UsingImported { usingImportedImportedNesting = - Just (TestImport.WithNesting - (Just (TestImport.WithNesting_Nested 1 2)) - (Just (TestImport.WithNesting_Nested 3 4))) + Just (GeneratedImportedTestTypes.WithNesting + (Just (GeneratedImportedTestTypes.WithNesting_Nested 1 2)) + (Just (GeneratedImportedTestTypes.WithNesting_Nested 3 4))) , usingImportedLocalNesting = - Just (WithNesting (Just (WithNesting_Nested "field" 0xBEEF))) }) + Just (WithNesting (Just (WithNesting_Nested "field" 0xBEEF [] []))) }) main :: IO () main = do testCase1 diff --git a/tests/TestCodeGen.hs b/tests/TestCodeGen.hs index b646f08b..be231563 100644 --- a/tests/TestCodeGen.hs +++ b/tests/TestCodeGen.hs @@ -1,26 +1,18 @@ +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} module TestCodeGen where -import Control.Monad -import Control.Monad.IO.Class import Control.Applicative -import Data.List -import qualified Data.Text as T -import Data.String (IsString) -import Test.Tasty -import Test.Tasty.HUnit (Assertion, (@?=), (@=?), testCase, assertBool) -import Test.Tasty.QuickCheck (testProperty, (===)) -import Test.QuickCheck (Arbitrary(..), Property, elements) -import Test.QuickCheck.Monadic (monadicIO) +import Data.String (IsString) +import qualified Data.Text as T import System.Exit -import Turtle +import Test.Tasty +import Test.Tasty.HUnit (testCase, (@?=)) +import Turtle hiding (err) -import Proto3.Suite.DotProto import Proto3.Suite.DotProto.Generate -import Proto3.Suite -import GHC.Int codeGenTests :: TestTree codeGenTests = testGroup "Code generator unit tests" @@ -31,17 +23,17 @@ codeGenTests = testGroup "Code generator unit tests" ] camelCaseMessageNames :: TestTree -camelCaseMessageNames = testGroup "CamelCase'ing of message names" +camelCaseMessageNames = testGroup "CamelCasing of message names" [ testCase "Capitalizes letters after underscores" (typeLikeName "protocol_analysis" @?= Right "ProtocolAnalysis") , testCase "Preserves casing of interior letters" (typeLikeName "analyze_HTTP" @?= Right "AnalyzeHTTP") , testCase "Handles non-alphanumeric characters after underscore" (typeLikeName "analyze_http_2" @?= Right "AnalyzeHttp2") , testCase "Preserves one underscore in double underscore sequence" (typeLikeName "Analyze__HTTP" @?= Right "Analyze_HTTP") - , testCase "Handles names prefixed with undedrscore" (typeLikeName "_message_name" @?= Right "XMessageName") + , testCase "Handles names prefixed with underscore" (typeLikeName "_message_name" @?= Right "XMessageName") , testCase "Preserves trailing underscore" (typeLikeName "message_name_" @?= Right "MessageName_") ] camelCaseFieldNames :: TestTree -camelCaseFieldNames = testGroup "camelCase'ing of field names" +camelCaseFieldNames = testGroup "camelCasing of field names" [ testCase "Preserves capitalization patterns" (fieldLikeName "IP" @?= "ip") , testCase "Preserves underscores" (fieldLikeName "IP_address" @?= "ip_address") ] @@ -53,13 +45,9 @@ simpleEncodeDotProto = compileTestDotProto - exitCode <- proc "tests/encode.sh" [hsTmpDir] empty - exitCode @?= ExitSuccess - - exitCode <- shell (T.concat ["protoc --python_out=", pyTmpDir, " test-files/test.proto"]) empty - exitCode @?= ExitSuccess - exitCode <- shell (T.concat ["protoc --python_out=", pyTmpDir, " test-files/test_import.proto"]) empty - exitCode @?= ExitSuccess + (@?= ExitSuccess) =<< proc "tests/encode.sh" [hsTmpDir] empty + (@?= ExitSuccess) =<< shell (T.concat ["protoc --python_out=", pyTmpDir, " test-files/test.proto"]) empty + (@?= ExitSuccess) =<< shell (T.concat ["protoc --python_out=", pyTmpDir, " test-files/test_import.proto"]) empty touch (pyTmpDir "test_files" "__init__.py") m <- need "PYTHONPATH" @@ -69,13 +57,9 @@ simpleEncodeDotProto = export "PYTHONPATH" (pythonPath <> ":" <> pyTmpDir) let cmd = (hsTmpDir <> "/simpleEncodeDotProto | python tests/check_simple_dot_proto.py") - - -- Can be useful when debugging intermediate codegen artifacts: - -- putStrLn (T.unpack $ "\nexport PYTHONPATH=" <> pythonPath <> ":" <> pyTmpDir) - -- assertBool ("EARLY TERM BEFORE: " <> T.unpack cmd) False - - exitCode <- shell cmd empty - exitCode @?= ExitFailure 12 -- We exit the python test with a special error code to make sure all tests completed + -- The python test exits with a special error code to indicate all tests + -- were successful + (@?= ExitFailure 12) =<< shell cmd empty -- Not using bracket so that we can inspect the output to fix the tests rmtree hsTmpDir @@ -89,13 +73,9 @@ simpleDecodeDotProto = compileTestDotProto - exitCode <- proc "tests/decode.sh" [hsTmpDir] empty - exitCode @?= ExitSuccess - - exitCode <- shell (T.concat ["protoc --python_out=", pyTmpDir, " test-files/test.proto"]) empty - exitCode @?= ExitSuccess - exitCode <- shell (T.concat ["protoc --python_out=", pyTmpDir, " test-files/test_import.proto"]) empty - exitCode @?= ExitSuccess + (@?= ExitSuccess) =<< proc "tests/decode.sh" [hsTmpDir] empty + (@?= ExitSuccess) =<< shell (T.concat ["protoc --python_out=", pyTmpDir, " test-files/test.proto"]) empty + (@?= ExitSuccess) =<< shell (T.concat ["protoc --python_out=", pyTmpDir, " test-files/test_import.proto"]) empty touch (pyTmpDir "test_files" "__init__.py") m <- need "PYTHONPATH" @@ -105,13 +85,7 @@ simpleDecodeDotProto = export "PYTHONPATH" (pythonPath <> ":" <> pyTmpDir) let cmd = "python tests/send_simple_dot_proto.py | " <> hsTmpDir <> "/simpleDecodeDotProto " - - -- Can be useful when debugging intermediate codegen artifacts: - -- putStrLn (T.unpack $ "\nexport PYTHONPATH=" <> pythonPath <> ":" <> pyTmpDir) - -- assertBool ("EARLY TERM BEFORE: " <> T.unpack cmd) False - - exitCode <- shell cmd empty - exitCode @?= ExitSuccess + (@?= ExitSuccess) =<< shell cmd empty rmtree hsTmpDir rmtree pyTmpDir @@ -122,19 +96,18 @@ hsTmpDir, pyTmpDir :: IsString a => a hsTmpDir = "test-files/hs-tmp" pyTmpDir = "test-files/py-tmp" -compileTestDotProto = - do dpRes <- readDotProtoWithContext "test-files/test.proto" - case dpRes of - Left err -> fail (show err) - Right (dp, ctxt) -> - case renderHsModuleForDotProto dp ctxt of - Left err -> fail ("compileTestDotProto: Error compiling test.proto: " <> show err) - Right hsSrc -> writeFile (hsTmpDir <> "/Test.hs") hsSrc - - dpRes <- readDotProtoWithContext "test-files/test_import.proto" - case dpRes of - Left err -> fail (show err) - Right (dp, ctxt) -> - case renderHsModuleForDotProto dp ctxt of - Left err -> fail ("compileTestDotProto: Error compiling test_import.proto: " <> show err) - Right hsSrc -> writeFile (hsTmpDir <> "/TestImport.hs") hsSrc +compileTestDotProto :: IO () +compileTestDotProto = do + readDotProtoWithContext "test-files/test.proto" >>= \case + Left err -> fail (show err) + Right (dp, ctxt) -> + case renderHsModuleForDotProto dp ctxt of + Left err -> fail ("compileTestDotProto: Error compiling test.proto: " <> show err) + Right hsSrc -> writeFile (hsTmpDir <> "/GeneratedTestTypes.hs") hsSrc + + readDotProtoWithContext "test-files/test_import.proto" >>= \case + Left err -> fail (show err) + Right (dp, ctxt) -> + case renderHsModuleForDotProto dp ctxt of + Left err -> fail ("compileTestDotProto: Error compiling test_import.proto: " <> show err) + Right hsSrc -> writeFile (hsTmpDir <> "/GeneratedImportedTestTypes.hs") hsSrc diff --git a/tests/check_simple_dot_proto.py b/tests/check_simple_dot_proto.py index a4d7886b..ad1a2c8c 100644 --- a/tests/check_simple_dot_proto.py +++ b/tests/check_simple_dot_proto.py @@ -60,6 +60,8 @@ def read_proto(cls): assert case4a.HasField('nestedMessage') assert case4a.nestedMessage.nestedField1 == "testCase4 nestedField1" assert case4a.nestedMessage.nestedField2 == 0xABCD +assert case4a.nestedMessage.nestedPacked == [] +assert case4a.nestedMessage.nestedUnpacked == [] case4b = read_proto(WithNesting) assert not case4b.HasField('nestedMessage') @@ -109,19 +111,19 @@ def read_proto(cls): assert list(case7b.repeatedField1) == range(1,10001) # Test case 8: Fixed-width integer types -case8a = read_proto(WithFixedTypes) +case8a = read_proto(WithFixed) assert case8a.fixed1 == 0 assert case8a.fixed2 == 0 assert case8a.fixed3 == 0 assert case8a.fixed4 == 0 -case8b = read_proto(WithFixedTypes) +case8b = read_proto(WithFixed) assert case8b.fixed1 == 2**32 - 1 assert case8b.fixed2 == (2**32 - 1) / 2 assert case8b.fixed3 == 2**64 - 1 assert case8b.fixed4 == (2**64 - 1) / 2 -case8c = read_proto(WithFixedTypes) +case8c = read_proto(WithFixed) assert case8c.fixed1 == 0 assert case8c.fixed2 == -(2**31) assert case8c.fixed3 == 0 @@ -241,6 +243,8 @@ def read_proto(cls): assert case16.importedNesting.nestedMessage2.nestedField2 == 4 assert case16.localNesting.nestedMessage.nestedField1 == "field" assert case16.localNesting.nestedMessage.nestedField2 == 0xBEEF +assert case16.localNesting.nestedMessage.nestedPacked == [] +assert case16.localNesting.nestedMessage.nestedUnpacked == [] # Wait for the special 'done' messsage done_msg = read_proto(MultipleFields) diff --git a/tests/decode.sh b/tests/decode.sh index 47d50acf..06379367 100755 --- a/tests/decode.sh +++ b/tests/decode.sh @@ -2,12 +2,12 @@ hsTmpDir=$1 -ghc \ - --make \ - -odir $hsTmpDir \ - -hidir $hsTmpDir \ - -o $hsTmpDir/simpleDecodeDotProto \ - $hsTmpDir/Test.hs \ - $hsTmpDir/TestImport.hs \ - tests/SimpleDecodeDotProto.hs \ +ghc \ + --make \ + -odir $hsTmpDir \ + -hidir $hsTmpDir \ + -o $hsTmpDir/simpleDecodeDotProto \ + $hsTmpDir/GeneratedTestTypes.hs \ + $hsTmpDir/GeneratedImportedTestTypes.hs \ + tests/SimpleDecodeDotProto.hs \ >/dev/null diff --git a/tests/encode.sh b/tests/encode.sh index dc4e72aa..d9ca84ba 100755 --- a/tests/encode.sh +++ b/tests/encode.sh @@ -2,12 +2,12 @@ hsTmpDir=$1 -ghc \ - --make \ - -odir $hsTmpDir \ - -hidir $hsTmpDir \ - -o $hsTmpDir/simpleEncodeDotProto \ - $hsTmpDir/Test.hs \ - $hsTmpDir/TestImport.hs \ - tests/SimpleEncodeDotProto.hs \ +ghc \ + --make \ + -odir $hsTmpDir \ + -hidir $hsTmpDir \ + -o $hsTmpDir/simpleEncodeDotProto \ + $hsTmpDir/GeneratedTestTypes.hs \ + $hsTmpDir/GeneratedImportedTestTypes.hs \ + tests/SimpleEncodeDotProto.hs \ >/dev/null diff --git a/tests/send_simple_dot_proto.py b/tests/send_simple_dot_proto.py index 7cc7b9f2..2133eac2 100644 --- a/tests/send_simple_dot_proto.py +++ b/tests/send_simple_dot_proto.py @@ -38,8 +38,10 @@ def write_proto(msg): # Test case 4: Nested messages write_proto( WithNesting(nestedMessage= - WithNesting.Nested(nestedField1 = "testCase4 nestedField1", - nestedField2 = 0xABCD))) + WithNesting.Nested(nestedField1 = "testCase4 nestedField1", + nestedField2 = 0xABCD, + nestedPacked = [], + nestedUnpacked = []))) write_proto(WithNesting()) # Test case 5: Nested repeated message @@ -58,28 +60,28 @@ def write_proto(msg): write_proto(WithNestingRepeated()) # Test case 6: Nested repeated int message -write_proto(WithNestingRepeatedInts(nestedInts=[WithNestingRepeatedInts.NestedInts(nestedInt1 = 636513, nestedInt2 = 619021)])) +write_proto(WithNestingRepeatedInts(nestedInts=[NestedInts(nestedInt1 = 636513, nestedInt2 = 619021)])) write_proto(WithNestingRepeatedInts(nestedInts=[])) write_proto(WithNestingRepeatedInts(nestedInts= - [ WithNestingRepeatedInts.NestedInts(nestedInt1 = 636513, nestedInt2 = 619021), - WithNestingRepeatedInts.NestedInts(nestedInt1 = 423549, nestedInt2 = 687069), - WithNestingRepeatedInts.NestedInts(nestedInt1 = 545506, nestedInt2 = 143731), - WithNestingRepeatedInts.NestedInts(nestedInt1 = 193605, nestedInt2 = 385360) ])) + [ NestedInts(nestedInt1 = 636513, nestedInt2 = 619021), + NestedInts(nestedInt1 = 423549, nestedInt2 = 687069), + NestedInts(nestedInt1 = 545506, nestedInt2 = 143731), + NestedInts(nestedInt1 = 193605, nestedInt2 = 385360) ])) # Test case 7: Repeated int32 field write_proto(WithRepetition()) write_proto(WithRepetition(repeatedField1 = range(1, 10001))) # Test case 8: Fixed-width integer types -write_proto(WithFixedTypes(fixed1 = 0, fixed2 = 0, fixed3 = 0, fixed4 = 0)) -write_proto(WithFixedTypes(fixed1 = 2**32 - 1, - fixed2 = (2**32 - 1) / 2, - fixed3 = 2**64 - 1, - fixed4 = (2**64 - 1) / 2)) -write_proto(WithFixedTypes(fixed1 = 0, - fixed2 = -(2**31), - fixed3 = 0, - fixed4 = -(2**63))) +write_proto(WithFixed(fixed1 = 0, fixed2 = 0, fixed3 = 0, fixed4 = 0)) +write_proto(WithFixed(fixed1 = 2**32 - 1, + fixed2 = (2**32 - 1) / 2, + fixed3 = 2**64 - 1, + fixed4 = (2**64 - 1) / 2)) +write_proto(WithFixed(fixed1 = 0, + fixed2 = -(2**31), + fixed3 = 0, + fixed4 = -(2**63))) # Test case 9: bytes fields write_proto(WithBytes(bytes1 = "\x00\x00\x00\x01\x02\x03\xFF\xFF\x00\x01", @@ -160,7 +162,7 @@ def write_proto(msg): # Test case 16: Proper resolution of shadowed message names write_proto(UsingImported(importedNesting = test_import.WithNesting(nestedMessage1 = test_import.WithNesting.Nested(nestedField1 = 1, nestedField2 = 2), nestedMessage2 = test_import.WithNesting.Nested(nestedField1 = 3, nestedField2 = 4)), - localNesting = WithNesting(nestedMessage = WithNesting.Nested(nestedField1 = "field", nestedField2 = 0xBEEF)))) + localNesting = WithNesting(nestedMessage = WithNesting.Nested(nestedField1 = "field", nestedField2 = 0xBEEF, nestedPacked = [], nestedUnpacked = [])))) # Send the special 'done' message write_proto(MultipleFields(multiFieldString = "All tests complete")) diff --git a/tests/tests.patch b/tests/tests.patch index 48fb4a83..ab76588f 100644 --- a/tests/tests.patch +++ b/tests/tests.patch @@ -8,11 +8,11 @@ index 59ad7cc..d1df62b 100755 hsTmpDir=$1 --ghc \ -+@ghc@/bin/ghc \ - --make \ - -odir $hsTmpDir \ - -hidir $hsTmpDir \ +-ghc \ ++@ghc@/bin/ghc \ + --make \ + -odir $hsTmpDir \ + -hidir $hsTmpDir \ diff --git a/tests/encode.sh b/tests/encode.sh index 8ebea7e..bc79de2 100755 --- a/tests/encode.sh @@ -23,8 +23,8 @@ index 8ebea7e..bc79de2 100755 hsTmpDir=$1 --ghc \ -+@ghc@/bin/ghc \ - --make \ - -odir $hsTmpDir \ - -hidir $hsTmpDir \ +-ghc \ ++@ghc@/bin/ghc \ + --make \ + -odir $hsTmpDir \ + -hidir $hsTmpDir \