Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Conversation

@patrickt
Copy link
Contributor

As we begin to transition to Hedgehog (#122), this instance stood out as one we could absolutely delete: it’s a roundabout way of expressing what we mean in the Data.Source tests, namely that we want to generate random UTF-8 ByteStrings and run our computations over them.

Patrick Thomson added 2 commits June 14, 2019 11:53
This was created with a whole mess of Leancheck combinators. A
Hedgehog approach makes things easier.
prop "covers multiple lines" $
\ n -> totalSpan (fromText (Text.intersperse '\n' (Text.replicate n "*"))) `shouldBe` Span (Pos 1 1) (Pos (max 1 n) (if n > 0 then 2 else 1))

describe "newlineIndices" $ do
Copy link
Contributor Author

@patrickt patrickt Jun 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In keeping with my philosophy of “do as little as possible so I don’t end up rewriting the whole test suite in an act of Pyrrhic futility”, I’ve left the tests that didn’t use LeanCheck as specs with describe.

import qualified Data.Source
import Data.Functor.Identity

source :: (GenBase m ~ Identity, MonadGen m) => Hedgehog.Range Int -> m Data.Source.Source
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GenBase constraint is a weird artifact of the Hedgehog API.

import qualified Test.Tasty as Tasty
import Test.Tasty.Hedgehog (testProperty)

prop :: HasCallStack => String -> (Source -> PropertyT IO ()) -> Tasty.TestTree
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrote this little helper to save keystrokes and modify as few of the specs as possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice ✨

@@ -0,0 +1,12 @@
{-# LANGUAGE TypeFamilies #-}
module Generators
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figure we’re gonna have a lot of generators, many of which may depend on each other.

@patrickt patrickt requested a review from a team June 14, 2019 16:39
import qualified Test.Tasty as Tasty
import Test.Tasty.Hedgehog (testProperty)

prop :: HasCallStack => String -> (Source -> PropertyT IO ()) -> Tasty.TestTree
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice ✨

@patrickt patrickt merged commit 78dad09 into master Jun 14, 2019
@patrickt patrickt deleted the remove-orphan-bytestring-listable branch June 14, 2019 21:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants