packages feed

portray-diff 0.1.0.0 → 0.1.0.1

raw patch · 3 files changed

+30/−20 lines, 3 filesdep ~portrayPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependency ranges changed: portray

API changes (from Hackage documentation)

+ Data.Portray.Diff: instance Data.Portray.Diff.Diff Data.Portray.Ident
+ Data.Portray.Diff: instance Data.Portray.Diff.Diff Data.Portray.IdentKind

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@ # 0.1.0.0  Initial version.++# 0.1.0.1++* Update to portray-0.2.0.
portray-diff.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: f9a64f5729d39cde1994044ecdc55d87ed5625e7186133b0920fcb34e939149b+-- hash: 84c038bd3ae071ca5d8573d57e88e5ed82ec69dfc2c67a8fe1c79712c0bab245  name:           portray-diff-version:        0.1.0.0+version:        0.1.0.1 synopsis:       Visualize the structural differences between two values. description:    This uses @GHC.Generics@ to provide structural diffs between two values in                 pretty-printed form.  This is primarily useful for test assertions and manual@@ -40,7 +40,7 @@       base >=4.12 && <4.16     , containers >=0.6 && <0.7     , dlist >=0.6 && <1.1-    , portray >=0.1 && <0.2+    , portray >=0.2 && <0.3     , text >=0.1 && <1.3     , wrapped >=0.1 && <0.2   default-language: Haskell2010
src/Data/Portray/Diff.hs view
@@ -43,6 +43,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE MagicHash #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuantifiedConstraints #-}@@ -68,17 +69,17 @@ import Data.Semigroup (Any(..)) import Data.Sequence (Seq) import Data.Text (Text)-import qualified Data.Text as T import Data.Type.Equality ((:~:)(..)) import Data.Word (Word8, Word16, Word32, Word64)-import GHC.Exts (IsList(..))+import GHC.Exts (IsList(..), fromString, proxy#) import qualified GHC.Exts as Exts (toList) import GHC.Generics-import GHC.TypeLits (KnownSymbol, symbolVal)+import GHC.TypeLits (KnownSymbol, symbolVal') import Type.Reflection (TypeRep, SomeTypeRep(..))  import Data.Portray          ( Portray(..), Portrayal(..), PortrayalF(..), Fix(..)+         , IdentKind(..), Ident(..)          , Infixity(..), Assoc(..), FactorPortrayal(..)          , showAtom, portrayType          )@@ -95,7 +96,7 @@   diff (Wrapped x) (Wrapped y) = gdiff x y (from x) (from y)  vs, diffVs :: Portrayal -> Portrayal -> Portrayal-vs a b = Binop "/=" (Infixity AssocNope 4) a b+vs a b = Binop (Ident OpIdent "/=") (Infixity AssocNope 4) a b diffVs = vs  -- | Diff on an atomic type, just by using the Eq and Portray instances without@@ -116,7 +117,7 @@ instance (Selector s, Diff a) => GDiffRecord (S1 s (K1 i a)) where   gdiffRecord (M1 (K1 a)) (M1 (K1 b)) =     foldMap D.singleton $  -- Maybe diff to DList of (zero or one) diffs.-      FactorPortrayal (T.pack $ selName @s undefined) <$>+      FactorPortrayal (fromString $ selName @s undefined) <$>       diff a b  instance (GDiffRecord f, GDiffRecord g) => GDiffRecord (f :*: g) where@@ -140,7 +141,7 @@  instance Diff a => GDiffCtor (S1 s (K1 i a)) where   gdiffCtor (M1 (K1 a)) (M1 (K1 b)) = case diff a b of-    Nothing -> (mempty, D.singleton "_")+    Nothing -> (mempty, D.singleton (Opaque "_"))     Just d -> (Any True, D.singleton d)  instance (GDiffCtor f, GDiffCtor g) => GDiffCtor (f :*: g) where@@ -153,18 +154,19 @@       => GDiff a (C1 ('MetaCons n fx 'True) f) where   gdiff _ _ (M1 a) (M1 b) = case D.toList (gdiffRecord a b) of     [] -> Nothing-    ds -> Just $ Record (Atom $ T.pack $ symbolVal @n undefined) ds+    ds -> Just $ Record (Name $ fromString $ symbolVal' @n proxy#) ds  instance (KnownSymbol n, GDiffCtor f)       => GDiff a (C1 ('MetaCons n fx 'False) f) where   gdiff _ _ (M1 a) (M1 b) = case gdiffCtor a b of     (Any False, _ ) -> Nothing     (Any True , ds) -> Just $ case nm of-      -- Print tuple constructors with tuple syntax.+      -- Print tuple constructors with tuple syntax.  Ignore infix+      -- constructors, since they'd make for pretty hard-to-read diffs.       '(':',':_ -> Tuple (D.toList ds)-      _ -> Apply (Atom $ T.pack nm) (D.toList ds)+      _ -> Apply (Name $ fromString nm) (D.toList ds)    where-    nm = symbolVal @n undefined+    nm = symbolVal' @n proxy#  instance (Portray a, GDiff a f, GDiff a g) => GDiff a (f :+: g) where   gdiff origA origB a b = case (a, b) of@@ -219,15 +221,15 @@   diff as0 bs0 =     if all isNothing d       then Nothing-      else Just $ List $ fromMaybe "_" <$> d+      else Just $ List $ fromMaybe (Opaque "_") <$> d    where     -- Extended @zipWith diff@ which doesn't drop on mismatched lengths.     go :: [a] -> [a] -> [Maybe Portrayal]     go [] [] = []     go (a:as) [] =-      Just (portray a `vs` "_") : go as []+      Just (portray a `vs` Opaque "_") : go as []     go [] (b:bs) =-      Just ("_" `vs` portray b) : go [] bs+      Just (Opaque "_" `vs` portray b) : go [] bs     go (a:as) (b:bs) = diff a b : go as bs      d = go as0 bs0@@ -256,12 +258,14 @@     -- Note: we could have used 'align', but "these" has a ton of dependencies     -- and it'd only save a few lines of code.     aOnly, bOnly, valDiffs, allDiffs :: IM.IntMap Portrayal-    aOnly = IM.map (\a -> portray a `vs` "_") $ IM.difference as bs-    bOnly = IM.map (\b -> "_" `vs` portray b) $ IM.difference bs as+    aOnly = IM.map (\a -> portray a `vs` Opaque "_") $ IM.difference as bs+    bOnly = IM.map (\b -> Opaque "_" `vs` portray b) $ IM.difference bs as     valDiffs = IM.mapMaybe id $ IM.intersectionWith diff as bs     allDiffs = IM.unions [aOnly, bOnly, valDiffs]  deriving via Wrapped Generic Assoc instance Diff Assoc+deriving via Wrapped Generic IdentKind instance Diff IdentKind+deriving via Wrapped Generic Ident instance Diff Ident deriving via Wrapped Generic Infixity instance Diff Infixity deriving via Wrapped Generic (FactorPortrayal a)   instance Diff a => Diff (FactorPortrayal a)@@ -287,7 +291,9 @@     | x == y = Nothing     | otherwise =         Just $ Apply-          (TyApp "SomeTypeRep" (portrayType tx `diffVs` portrayType ty))-          ["typeRep"]+          (TyApp+            (Name $ Ident ConIdent "SomeTypeRep")+            (portrayType tx `diffVs` portrayType ty))+          [Name $ Ident VarIdent "typeRep"]  instance Diff (a :~: b) where diff Refl Refl = Nothing