packages feed

hspec-expectations-json 1.0.2.0 → 1.0.2.1

raw patch · 4 files changed

+92/−18 lines, 4 filesdep ~Diffdep ~HUnitdep ~QuickCheckPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: Diff, HUnit, QuickCheck, aeson, aeson-pretty, aeson-qq, hspec, scientific, text, unordered-containers, vector

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,4 +1,8 @@-## [_Unreleased_](https://github.com/freckle/hspec-expectations-json/compare/v1.0.1.0...main)+## [_Unreleased_](https://github.com/freckle/hspec-expectations-json/compare/v1.0.2.1...main)++## [v1.0.2.1](https://github.com/freckle/hspec-expectations-json/compare/v1.0.2.0...v1.0.2.1)++- Fixed issue with `expandHeterogenousArrays` not working for nested Objects  ## [v1.0.2.0](https://github.com/freckle/hspec-expectations-json/compare/v1.0.1.1...v1.0.2.0) 
hspec-expectations-json.cabal view
@@ -1,6 +1,6 @@ cabal-version:   1.18 name:            hspec-expectations-json-version:         1.0.2.0+version:         1.0.2.1 license:         MIT license-file:    LICENSE copyright:       2020 Freckle Education@@ -59,15 +59,15 @@         TypeApplications TypeFamilies      build-depends:-        Diff,-        HUnit,-        aeson,-        aeson-pretty,+        Diff >=0.3.4,+        HUnit >=1.6.0.0,+        aeson >=1.3.1.1,+        aeson-pretty >=0.8.7,         base >=4.11 && <5,-        scientific,-        text,-        unordered-containers,-        vector+        scientific >=0.3.6.2,+        text >=1.2.3.1,+        unordered-containers >=0.2.9.0,+        vector >=0.12.0.2  test-suite spec     type:               exitcode-stdio-1.0@@ -89,9 +89,9 @@         TypeApplications TypeFamilies      build-depends:-        QuickCheck,-        aeson,-        aeson-qq,+        QuickCheck >=2.11.3,+        aeson >=1.3.1.1,+        aeson-qq >=0.8.2,         base >=4.11 && <5,-        hspec,+        hspec >=2.5.5,         hspec-expectations-json
library/Test/Hspec/Expectations/Json/Internal.hs view
@@ -102,14 +102,33 @@ -- -- ex: [{a:1}, {b:1}] -> [{a:1, b:null}, {a:null, b:1}] expandHeterogenousArrays :: Value -> Value-expandHeterogenousArrays = go KeyMap.empty+expandHeterogenousArrays = go mempty  where   collectAllKeys = \case     Object km -> Null <$ km     _ -> KeyMap.empty-  go allKeys = \case-    Object km -> Object $ expandHeterogenousArrays <$> KeyMap.union km allKeys-    Array vec -> Array $ go (foldMap collectAllKeys vec) <$> vec+  go vec = \case+    Object km ->+      let+        -- Set all keys not present in this level of the object to null+        nullCurrentLevel :: Object+        nullCurrentLevel = KeyMap.union km (foldMap collectAllKeys vec)+        -- `mapWithKey` is not available for all version of `KeyMap`+        mapWithKey f = KeyMap.fromList . fmap f . KeyMap.toList+        -- Recurse over all properties+        nullChildren :: Object -> Object+        nullChildren = mapWithKey $ \(k, v) -> (k, go (siblingProperties k) v)+        -- Gather all values at the specified key+        siblingProperties k =+          V.mapMaybe+            ( \case+                Object km' -> KeyMap.lookup k km'+                _ -> Nothing+            )+            vec+      in+        Object $ nullChildren nullCurrentLevel+    Array v -> Array $ go v <$> v     x -> x  newtype Sortable = Sortable Value
tests/Test/Hspec/Expectations/JsonSpec.hs view
@@ -159,6 +159,57 @@        a `shouldMatchJsonWithOmittedNullFields` b +    it "ignores omitted null fields in nested objects" $ do+      let+        a =+          [aesonQQ|+[+  {+    "a": {+      "a": 1+    },+    "b": {+      "b": 1+    }+  },+  {+    "a": {+      "b": 2+    },+    "b": {+      "c": 2+    }+  }+]+|]+        b =+          [aesonQQ|+[+  {+    "a": {+      "a": 1,+      "b": null+    },+    "b": {+      "b": 1,+      "c": null+    }+  },+  {+    "a": {+      "a": null,+      "b": 2+    },+    "b": {+      "b": null,+      "c": 2+    }+  }+]+|]++      a `shouldMatchJsonWithOmittedNullFields` b+ -- it "is an example failure, to checking how they're printed" $ do --   let --     a = [aesonQQ|