-
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.
- Loading branch information
1 parent
7caf15b
commit 14e1f50
Showing
8 changed files
with
59 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Changes | ||
|
||
## Version 1.0.0 | ||
## Version 0.1.0.0 | ||
|
||
_2024-12-17_ | ||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,16 @@ | ||
-- | | ||
-- | ||
-- Module : Test.Tasty.Golden.Extra.Internal | ||
-- Copyright : (C) 2024 Bellroy Pty Ltd | ||
-- License : BSD-3-Clause | ||
-- Maintainer : Bellroy Tech Team <[email protected]> | ||
-- Stability : experimental | ||
-- | ||
-- Common types and functions used by the other modules in `tasty-golden-extra`. | ||
module Test.Tasty.Golden.Extra.Internal | ||
( assertJsonEqual, | ||
( checkJsonDifference, | ||
maybeDifference, | ||
JsonDifference (..), | ||
) | ||
where | ||
|
||
|
@@ -9,8 +20,26 @@ import Data.Aeson.Patch (patchOperations) | |
import Data.Text.Lazy qualified as TL | ||
import Text.Pretty.Simple (pShowNoColor) | ||
|
||
assertJsonEqual :: Aeson.Value -> Aeson.Value -> IO (Maybe String) | ||
assertJsonEqual goldenJson actualJson = | ||
pure $ case patchOperations $ diff goldenJson actualJson of | ||
[] -> Nothing | ||
ds -> Just $ "Files contain different JSON values: " <> TL.unpack (pShowNoColor ds) | ||
-- | Represents the result of comparing two JSON values - either the JSON is | ||
-- identical, or there are differences and you are given an error message | ||
-- containing the differences. | ||
data JsonDifference | ||
= JsonIdentical | ||
| JsonDifferent String | ||
|
||
-- | Convert a `JsonDifference` to a `Maybe String` containing the error message. | ||
maybeDifference :: JsonDifference -> Maybe String | ||
maybeDifference JsonIdentical = Nothing | ||
maybeDifference (JsonDifferent diffString) = Just diffString | ||
|
||
-- | Compare two JSON values and return a `JsonDifference` representing the result. | ||
checkJsonDifference :: | ||
Aeson.Value -> | ||
Aeson.Value -> | ||
JsonDifference | ||
checkJsonDifference goldenJson actualJson = | ||
case patchOperations $ diff goldenJson actualJson of | ||
[] -> JsonIdentical | ||
ds -> | ||
JsonDifferent $ | ||
"Files contain different JSON values:\n" <> TL.unpack (pShowNoColor ds) |
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