Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve doctests #242

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Proto3/Suite/DotProto/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ import qualified Turtle hiding (encodeString)
import qualified Turtle.Compat as Turtle (encodeString)
import Turtle (FilePath, (</>), (<.>))

-- $setup
-- >>> :set -XTypeApplications

--------------------------------------------------------------------------------

--
Expand Down
4 changes: 2 additions & 2 deletions src/Proto3/Suite/JSONPB/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ parseField :: FromJSONPB a
=> A.Object -> Key -> A.Parser a
parseField = A.explicitParseField parseJSONPB

-- | >>> isDefault (def @E.Encoding)
-- | >>> isDefault (def :: E.Encoding)
-- True
instance HasDefault E.Encoding where
def = E.empty
isDefault = E.nullEncoding

-- | >>> isDefault (def @A.Value)
-- | >>> isDefault (def :: A.Value)
-- True
instance HasDefault A.Value where
def = A.Null
Expand Down
11 changes: 6 additions & 5 deletions src/Proto3/Suite/Tutorial.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
-- |
-- = Tutorial
--
-- >>> :set -XOverloadedStrings
--
-- This module contains a worked example of encoding and decoding messages,
-- and exporting a corresponding .proto file from Haskell types.
--
Expand Down Expand Up @@ -41,6 +39,9 @@ import Proto3.Suite (Enumerated, Nested, NestedVec, PackedVec,
enum, message, packageFromDefs, toProtoFileDef)
import Proto3.Wire.Class (ProtoEnum)

-- $setup
-- >>> :set -XOverloadedStrings

-- |
-- == Defining Message Types
--
Expand All @@ -65,7 +66,7 @@ import Proto3.Wire.Class (ProtoEnum)
--
-- We can also decode messages using `fromByteString`:
--
-- >>> Proto3.Suite.fromByteString "\b*\DC2\SOH{" :: Either [Proto3.Suite..Decode.Parser.ParseError] Foo
-- >>> Proto3.Suite.fromByteString "\b*\DC2\SOH{" :: Either Proto3.Wire.Decode.ParseError Foo
-- Right (Foo {fooX = 42, fooY = PackedVec {packedvec = [123]}})
data Foo = Foo
{ fooX :: Word32
Expand Down Expand Up @@ -125,12 +126,12 @@ data Shape
-- }
-- message Foo {
-- uint32 fooX = 1;
-- repeated int32 fooY = 2 [packed=true];
-- repeated int32 fooY = 2 [packed = true];
-- }
-- message Bar {
-- Shape barShape = 1;
-- Foo barFoo = 2;
-- repeated Foo foos = 3 [packed=false];
-- repeated Foo foos = 3;
-- }

protoFile :: String
Expand Down
12 changes: 6 additions & 6 deletions tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ docTests :: TestTree
docTests = testCase "doctests" $ do
putStrLn "Running all doctests..."
Test.DocTest.doctest
[ "-isrc"
, "-itests"
, "-igen"
[ "--verbose"
, "-isrc"
#ifdef SWAGGER
#ifdef SWAGGER_WRAPPER_FORMAT
, "-isrc/swagger-wrapper-format"
Expand All @@ -85,8 +84,9 @@ docTests = testCase "doctests" $ do
, "-DLARGE_RECORDS"
#endif
, "src/Proto3/Suite/DotProto/Internal.hs"
, "src/Proto3/Suite/DotProto/Generate.hs"
, "src/Proto3/Suite/JSONPB/Class.hs"
, "tests/TestCodeGen.hs"
, "src/Proto3/Suite/Tutorial.hs"
]

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -327,11 +327,11 @@ qcDotProtoRoundtrip = testProperty
++ "\n\nInitial AST:\n\n"

dotProtoRoundtripExtend :: TestTree
dotProtoRoundtripExtend =
dotProtoRoundtripExtend =
let expected :: DotProto
expected = DotProto [] [] DotProtoNoPackage [] (DotProtoMeta (Path ("test-files" NE.:| ["test_proto_extend"])))
in testCase
"Round-trip for a message extension"
"Round-trip for a message extension"
(testDotProtoRoundtrip expected)

--------------------------------------------------------------------------------
Expand Down
Loading