Skip to content

Commit

Permalink
Merge pull request #95 from haskellari/ediffGolden1
Browse files Browse the repository at this point in the history
Add ediffGolden1
  • Loading branch information
phadej authored Oct 19, 2024
2 parents 5efb53e + b95f6ad commit 3bc46be
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.2

- Add 'ediffGolden1', a variant of 'ediffGolden' with an additional argument.

## 0.3.1

- Support GHC-8.6.5...9.10.1
Expand Down
19 changes: 17 additions & 2 deletions src/Data/TreeDiff/Golden.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- | "Golden tests" using 'ediff' comparison.
module Data.TreeDiff.Golden (
ediffGolden,
ediffGolden1,
) where

import Data.TreeDiff
Expand Down Expand Up @@ -41,9 +42,23 @@ ediffGolden
-> FilePath -- ^ path to "golden file"
-> IO a -- ^ result value
-> testTree
ediffGolden impl testName fp x = impl testName expect actual cmp wrt
ediffGolden impl testName fp x = ediffGolden1 impl' testName fp (\() -> x) where
impl' n expect actual = impl n expect (actual ())

-- | Like 'ediffGolden1' but with an additional argument for generation of actual value.
--
-- @since 0.3.2
--
ediffGolden1
:: (Eq a, ToExpr a)
=> (testName -> IO Expr -> (arg -> IO Expr) -> (Expr -> Expr -> IO (Maybe String)) -> (Expr -> IO ()) -> testTree) -- ^ 'goldenTest'
-> testName -- ^ test name
-> FilePath -- ^ path to "golden file"
-> (arg -> IO a) -- ^ result value
-> testTree
ediffGolden1 impl testName fp x = impl testName expect actual cmp wrt
where
actual = fmap toExpr x
actual arg = fmap toExpr (x arg)
expect = do
contents <- BS.readFile fp
case parse (exprParser <* eof) fp $ TE.decodeUtf8 contents of
Expand Down
3 changes: 1 addition & 2 deletions tree-diff.cabal
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cabal-version: 2.2
name: tree-diff
version: 0.3.1
x-revision: 1
version: 0.3.2
synopsis: Diffing of (expression) trees.
category: Data, Testing
description:
Expand Down

0 comments on commit 3bc46be

Please sign in to comment.