@@ -6,12 +6,13 @@ module UnitTests (ioTests, tests) where
7import Control.Applicative (Const(..))
7import Control.Applicative (Const(..))
8import Control.Monad (forM)
8import Control.Monad (forM)
9−import Data.Aeson (decode, eitherDecode, encode, genericToJSON, genericToEncoding, FromJSON(..), withObject, (.:), (.:?), (.:!))
9+import Data.Aeson (decode, eitherDecode, encode, genericToJSON, genericToEncoding, object, FromJSON(..), withObject, (.=), (.:), (.:?), (.:!))
10import Data.Aeson.Encode (encodeToTextBuilder)
10import Data.Aeson.Encode (encodeToTextBuilder)
11import Data.Aeson.Internal (JSONPathElement(..), formatError)
11import Data.Aeson.Internal (JSONPathElement(..), formatError)
12import Data.Aeson.TH (deriveJSON)
12import Data.Aeson.TH (deriveJSON)
13import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields)
13import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields)
14import Data.Char (toUpper)
14import Data.Char (toUpper)
15+import Data.Hashable (hash)
15import Data.List.NonEmpty (NonEmpty(..))
16import Data.List.NonEmpty (NonEmpty(..))
16import Data.Maybe (fromMaybe)
17import Data.Maybe (fromMaybe)
17import Data.Proxy (Proxy(..))
18import Data.Proxy (Proxy(..))
@@ -63,6 +64,7 @@ tests = testGroup "unit" [
63 , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
64 , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
64 , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
65 , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
65 , testGroup "JSONPath" $ fmap (testCase "-") jsonPath
66 , testGroup "JSONPath" $ fmap (testCase "-") jsonPath
67+ , testGroup "Hashable laws" $ fmap (testCase "-") hashableLaws
66 , testGroup "Issue #351" $ fmap (testCase "-") issue351
68 , testGroup "Issue #351" $ fmap (testCase "-") issue351
@@ -261,6 +263,18 @@ jsonPath = [
261 (eitherDecode "[0,1,true]" :: Either String (Seq Int))
263 (eitherDecode "[0,1,true]" :: Either String (Seq Int))
266+------------------------------------------------------------------------------
267+-- Check that the hashes of two equal Value are the same
268+------------------------------------------------------------------------------
270+hashableLaws :: [Assertion]
272+ assertEqual "Hashable Object" (hash a) (hash b)
275+ a = object ["223" .= False, "807882556" .= True]
276+ b = object ["807882556" .= True, "223" .= False]
264------------------------------------------------------------------------------
278------------------------------------------------------------------------------
265-- Regressions
279-- Regressions
266------------------------------------------------------------------------------
280------------------------------------------------------------------------------