@@ -6,12 +6,13 @@ module UnitTests (ioTests, tests) where
66
77import Control.Applicative (Const(..))
88import 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, (.=), (.:), (.:?), (.:!))
1010import Data.Aeson.Encode (encodeToTextBuilder)
1111import Data.Aeson.Internal (JSONPathElement(..), formatError)
1212import Data.Aeson.TH (deriveJSON)
1313import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields)
1414import Data.Char (toUpper)
15+import Data.Hashable (hash)
1516import Data.List.NonEmpty (NonEmpty(..))
1617import Data.Maybe (fromMaybe)
1718import Data.Proxy (Proxy(..))
@@ -63,6 +64,7 @@ tests = testGroup "unit" [
6364 , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
6465 , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
6566 , testGroup "JSONPath" $ fmap (testCase "-") jsonPath
67+ , testGroup "Hashable laws" $ fmap (testCase "-") hashableLaws
6668 , testGroup "Issue #351" $ fmap (testCase "-") issue351
6769 ]
6870
@@ -261,6 +263,18 @@ jsonPath = [
261263 (eitherDecode "[0,1,true]" :: Either String (Seq Int))
262264 ]
263265
266+------------------------------------------------------------------------------
267+-- Check that the hashes of two equal Value are the same
268+------------------------------------------------------------------------------
269+
270+hashableLaws :: [Assertion]
271+hashableLaws = [
272+ assertEqual "Hashable Object" (hash a) (hash b)
273+ ]
274+ where
275+ a = object ["223" .= False, "807882556" .= True]
276+ b = object ["807882556" .= True, "223" .= False]
277+
264278------------------------------------------------------------------------------
265279-- Regressions
266280------------------------------------------------------------------------------