forked from awakesecurity/gRPC-haskell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefer codegen over deriving
Generic
in test suite (awakesecurity#14)
* Misc cleanup/refactor pass on test suite descriptions and structure (awakesecurity#13) * Rename module TestTypes => OldTestTypes * Rename test.proto and test_import.proto package names to GeneratedTestTypes and GeneratedImportedTestTypes respectively * +tests/Generated{,Imported}TestTypes.hs and related changes * Add (:: Int) annotation to enum bound to avoid default type warning in generated modules * (qcPropDecEncId test) Replace OldTestTypes types with GeneratedTestTypes types * Remove dependency on quickcheck-text * Add and support additional fields for `WithNesting` in test.proto We did this to match prior `NestedMsg` use in `OldTestTypes` as part of the effort of redirecting the test suite to operate on code generated from .protos rather than hand-rolled types. * Use GeneratedTestTypes for remainder of the current types under test (after making small tweaks for type parity) * Add pretty-show dep so it can be used in the repl * Fix bug in the `MessageField` instance for `PackedVec Word32` * Add helpers/instances for pprinting simplified, single-message DotProtos from corresponding Haskell types; comments * Minor module reorg * Remove warnings
- Loading branch information
1 parent
dc1e4b1
commit 3ee83b5
Showing
20 changed files
with
1,683 additions
and
502 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)] |
Oops, something went wrong.