-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit test for null value suppression
- Loading branch information
Showing
6 changed files
with
82 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"bar": null, "foo": "blah"} |
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,4 @@ | ||
{ | ||
"bar": null, | ||
"foo": "blah" | ||
} |
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,3 @@ | ||
{ | ||
"foo": "blah" | ||
} |
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,48 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
import Test.Framework | ||
import Test.Framework.Providers.HUnit | ||
|
||
import Data.Aeson | ||
import Data.Aeson.Encode.Pretty | ||
import qualified Data.ByteString.Lazy as B | ||
import qualified Data.ByteString.Lazy.UTF8 as U (toString) | ||
import Data.Map (Map) | ||
import Test.HUnit (assertEqual) | ||
import System.FilePath.Posix | ||
import Data.String.Utils (rstrip) | ||
|
||
testDataDir :: FilePath | ||
testDataDir = "test/data/suppress-nulls" | ||
|
||
eitherDecodeMap :: IO (Map String (Maybe String)) | ||
eitherDecodeMap = do | ||
d <- eitherDecode <$> B.readFile (testDataDir </> "input.json") | ||
case d of | ||
Left err -> error $ "ERROR: " ++ err | ||
Right val -> return val | ||
|
||
|
||
prettifyMap :: Bool -> Map String (Maybe String) -> String | ||
prettifyMap s m = U.toString $ encodePretty' (Config 4 compare s) m | ||
|
||
|
||
testEquality :: Bool -> FilePath -> IO () | ||
testEquality suppress data_filename = do | ||
vals <- eitherDecodeMap | ||
let pretty_output_computed = prettifyMap suppress vals | ||
reference_output_file_content <- readFile $ testDataDir </> data_filename | ||
let pretty_output_expected = rstrip $ reference_output_file_content | ||
|
||
assertEqual "Checking equality..." pretty_output_expected pretty_output_computed | ||
|
||
|
||
tests = [ | ||
testGroup "Null value suppression" [ | ||
testCase "nulls-allowed" $ testEquality True "null-values-allowed.json" | ||
, testCase "nulls-suppressed" $ testEquality False "null-values-suppressed.json" | ||
] | ||
] | ||
|
||
|
||
main = defaultMain tests |