packages feed

debug-print 0.1.0.0 → 0.2.0.0

raw patch · 6 files changed

+123/−6 lines, 6 filesdep +aeson-qq

Dependencies added: aeson-qq

Files

CHANGELOG.md view
@@ -1,6 +1,12 @@-## [_Unreleased_](https://github.com/freckle/debug-print/compare/v0.1.0.0...main)+## [_Unreleased_](https://github.com/freckle/debug-print/compare/v0.2.0.0...main) -## [v0.1.0.0](https://github.com/freckle/nonempty-zipper/compare/v0.0.0.0...v0.1.0.0)+## [v0.2.0.0](https://github.com/freckle/debug-print/compare/v0.2.0.0...v0.2.0.0)++To reduce clutter in output, the default `Generic`-derived `ToDebugPrintRecord`+instance now elides any field whose values is empty text, an empty list, or an+empty object.++## [v0.1.0.0](https://github.com/freckle/debug-print/compare/v0.0.0.0...v0.1.0.0)  The parameter of `DebugPrintValueInt` is changed from `Int` to `Integer`. 
README.lhs view
@@ -26,13 +26,15 @@ data Report = Report   { milliseconds :: Int   , errors :: [Text]+  , fileName :: Maybe Text   }   deriving stock Generic   deriving anyclass (ToDebugPrintRecord, ToDebugPrintValue)  report :: Report report = Report{ milliseconds = 5_824-               , errors = ["Warning! Problems."] }+                , errors = ["Warning! Problems."]+                , fileName = Nothing } ```  ```haskell
README.md view
@@ -26,13 +26,15 @@ data Report = Report   { milliseconds :: Int   , errors :: [Text]+  , fileName :: Maybe Text   }   deriving stock Generic   deriving anyclass (ToDebugPrintRecord, ToDebugPrintValue)  report :: Report report = Report{ milliseconds = 5_824-               , errors = ["Warning! Problems."] }+                , errors = ["Warning! Problems."]+                , fileName = Nothing } ```  ```haskell
debug-print.cabal view
@@ -1,6 +1,6 @@ cabal-version:   2.0 name:            debug-print-version:         0.1.0.0+version:         0.2.0.0 license:         MIT license-file:    LICENSE maintainer:      Freckle Education@@ -101,6 +101,34 @@         debug-print,         hspec >=2.11.11,         markdown-unlit >=0.6.0,+        text >=2.1.1++    if impl(ghc >=9.8)+        ghc-options:+            -Wno-missing-role-annotations -Wno-missing-poly-kind-signatures++test-suite spec+    type:               exitcode-stdio-1.0+    main-is:            Main.hs+    hs-source-dirs:     tests+    other-modules:      Paths_debug_print+    autogen-modules:    Paths_debug_print+    default-language:   GHC2021+    default-extensions:+        DefaultSignatures DeriveAnyClass DerivingVia NoFieldSelectors+        NoImplicitPrelude NoMonomorphismRestriction OverloadedStrings+        StrictData++    ghc-options:+        -Weverything -Wno-all-missed-specialisations+        -Wno-missing-import-lists -Wno-missing-kind-signatures+        -Wno-missing-safe-haskell-mode -Wno-safe -Wno-unsafe++    build-depends:+        aeson-qq >=0.8.4,+        base >=4.19.2.0 && <5,+        debug-print,+        hspec >=2.11.11,         text >=2.1.1      if impl(ghc >=9.8)
internal/DebugPrint/Core.hs view
@@ -134,7 +134,11 @@   gToRecord (M1 x) = gToRecord x  instance (Selector s, ToDebugPrintValueRep f) => ToDebugPrintRecordRep (S1 s f) where-  gToRecord s1@(M1 x) = DebugPrintRecord $ Map.singleton (T.pack (selName s1)) (gToValue x)+  gToRecord s1@(M1 x) = DebugPrintRecord $ case gToValue x of+    DebugPrintValueText y | T.null y -> Map.empty+    DebugPrintValueVector y | V.null y -> Map.empty+    DebugPrintValueRecord (DebugPrintRecord y) | Map.null y -> Map.empty+    y -> Map.singleton (T.pack (selName s1)) y  --- 
+ tests/Main.hs view
@@ -0,0 +1,75 @@+{-# LANGUAGE QuasiQuotes #-}++module Main (main) where++import Prelude++import Data.Aeson.QQ+import Data.Text (Text)+import DebugPrint+import DebugPrint.Aeson+import GHC.Generics (Generic)+import Test.Hspec++data Report = Report+  { milliseconds :: Int+  , errors :: [Text]+  , fileName :: Maybe Text+  }+  deriving stock (Generic)+  deriving anyclass (ToDebugPrintRecord, ToDebugPrintValue)++data Place = Place+  { country :: Text+  , region :: Text+  }+  deriving stock (Generic)+  deriving anyclass (ToDebugPrintRecord, ToDebugPrintValue)++data Journey = Journey+  { from :: Place+  , to :: Place+  }+  deriving stock (Generic)+  deriving anyclass (ToDebugPrintRecord, ToDebugPrintValue)++main :: IO ()+main = hspec $ do+  describe "debugPrintValueToAeson" $ do+    it "Omits Nothing fields" $ do+      debugPrintValueToAeson+        Report+          { milliseconds = 5_824+          , errors = ["Warning! Problems."]+          , fileName = Nothing+          }+        `shouldBe` [aesonQQ| { errors: ["Warning! Problems."], milliseconds: 5824 } |]++    it "Omits empty Vector fields" $ do+      debugPrintValueToAeson+        Report+          { milliseconds = 0+          , errors = []+          , fileName = Just "records.csv"+          }+        `shouldBe` [aesonQQ| { fileName: ["records.csv"], milliseconds: 0 } |]++    it "Omits empty Text" $ do+      debugPrintValueToAeson+        Place+          { country = "USA"+          , region = ""+          }+        `shouldBe` [aesonQQ| {country: "USA" } |]++    it "Omits empty objects" $ do+      debugPrintValueToAeson+        Journey+          { from =+              Place+                { country = "USA"+                , region = ""+                }+          , to = Place {country = "", region = ""}+          }+        `shouldBe` [aesonQQ| { from: { country: "USA" } } |]