-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Test monadic programs using state machine based models -- -- See README at -- https://github.com/stevana/quickcheck-state-machine#readme @package quickcheck-state-machine @version 0.9.0 -- | A list diff. module Test.StateMachine.TreeDiff.List -- | List difference. -- --
-- >>> diffBy (==) "hello" "world" -- [Swp 'h' 'w',Swp 'e' 'o',Swp 'l' 'r',Cpy 'l',Swp 'o' 'd'] ---- --
-- >>> diffBy (==) "kitten" "sitting" -- [Swp 'k' 's',Cpy 'i',Cpy 't',Cpy 't',Swp 'e' 'i',Cpy 'n',Ins 'g'] ---- --
-- \xs ys -> length (diffBy (==) xs ys) >= max (length xs) (length (ys :: String)) ---- --
-- \xs ys -> length (diffBy (==) xs ys) <= length xs + length (ys :: String) ---- -- Note: currently this has O(n*m) memory requirements, for the -- sake of more obviously correct implementation. diffBy :: forall a. (a -> a -> Bool) -> [a] -> [a] -> [Edit a] -- | List edit operations -- -- The Swp constructor is redundant, but it let us spot a -- recursion point when performing tree diffs. data Edit a -- | insert Ins :: a -> Edit a -- | delete Del :: a -> Edit a -- | copy unchanged Cpy :: a -> Edit a -- | swap, i.e. delete + insert Swp :: a -> a -> Edit a instance GHC.Show.Show a => GHC.Show.Show (Test.StateMachine.TreeDiff.List.Edit a) -- | This module uses Expr for richer diffs than based on -- Tree. module Test.StateMachine.TreeDiff.Expr -- | A untyped Haskell-like expression. -- -- Having richer structure than just Tree allows to have richer -- diffs. data Expr -- | application App :: ConstructorName -> [Expr] -> Expr -- | record constructor Rec :: ConstructorName -> Map FieldName Expr -> Expr -- | list constructor Lst :: [Expr] -> Expr -- | Constructor name is a string type ConstructorName = String -- | Record field name is a string too. type FieldName = String -- | Type used in the result of ediff. data EditExpr EditApp :: ConstructorName -> [Edit EditExpr] -> EditExpr EditRec :: ConstructorName -> Map FieldName (Edit EditExpr) -> EditExpr EditLst :: [Edit EditExpr] -> EditExpr -- | unchanged tree EditExp :: Expr -> EditExpr -- | List edit operations -- -- The Swp constructor is redundant, but it let us spot a -- recursion point when performing tree diffs. data Edit a -- | insert Ins :: a -> Edit a -- | delete Del :: a -> Edit a -- | copy unchanged Cpy :: a -> Edit a -- | swap, i.e. delete + insert Swp :: a -> a -> Edit a -- | Diff two Expr. -- -- For examples see ediff in Data.TreeDiff.Class. exprDiff :: Expr -> Expr -> Edit EditExpr instance GHC.Show.Show Test.StateMachine.TreeDiff.Expr.Expr instance GHC.Classes.Eq Test.StateMachine.TreeDiff.Expr.Expr instance GHC.Show.Show Test.StateMachine.TreeDiff.Expr.EditExpr instance Test.QuickCheck.Arbitrary.Arbitrary Test.StateMachine.TreeDiff.Expr.Expr -- | A ToExpr class. module Test.StateMachine.TreeDiff.Class -- | Difference between two ToExpr values. -- --
-- >>> let x = (1, Just 2) :: (Int, Maybe Int) -- -- >>> let y = (1, Nothing) -- -- >>> prettyEditExpr (ediff x y) -- _×_ 1 -(Just 2) +Nothing ---- --
-- >>> data Foo = Foo { fooInt :: Either Char Int, fooBool :: [Maybe Bool], fooString :: String } deriving (Eq, Generic)
--
-- >>> instance ToExpr Foo
--
--
--
-- >>> prettyEditExpr $ ediff (Foo (Right 2) [Just True] "fo") (Foo (Right 3) [Just True] "fo")
-- Foo {fooBool = [Just True], fooInt = Right -2 +3, fooString = "fo"}
--
--
--
-- >>> prettyEditExpr $ ediff (Foo (Right 42) [Just True, Just False] "old") (Foo (Right 42) [Nothing, Just False, Just True] "new")
-- Foo
-- {fooBool = [-Just True, +Nothing, Just False, +Just True],
-- fooInt = Right 42,
-- fooString = -"old" +"new"}
--
ediff :: ToExpr a => a -> a -> Edit EditExpr
-- | Compare different types.
--
-- Note: Use with care as you can end up comparing apples with
-- oranges.
--
-- -- >>> prettyEditExpr $ ediff' ["foo", "bar"] [Just "foo", Nothing] -- [-"foo", +Just "foo", -"bar", +Nothing] --ediff' :: (ToExpr a, ToExpr b) => a -> b -> Edit EditExpr -- | toExpr converts a Haskell value into untyped Haskell-like -- syntax tree, Expr. -- --
-- >>> toExpr ((1, Just 2) :: (Int, Maybe Int)) -- App "_\215_" [App "1" [],App "Just" [App "2" []]] --class ToExpr a toExpr :: ToExpr a => a -> Expr toExpr :: (ToExpr a, Generic a, All2 ToExpr (GCode a), GFrom a, GDatatypeInfo a) => a -> Expr listToExpr :: ToExpr a => [a] -> Expr -- | An alternative implementation for literal types. We use show -- representation of them. defaultExprViaShow :: Show a => a -> Expr -- |
-- >>> prettyExpr $ sopToExpr (gdatatypeInfo (Proxy :: Proxy String)) (gfrom "foo") -- _:_ 'f' "oo" --sopToExpr :: All2 ToExpr xss => DatatypeInfo xss -> SOP I xss -> Expr instance Test.StateMachine.TreeDiff.Class.ToExpr Test.StateMachine.TreeDiff.Expr.Expr instance Test.StateMachine.TreeDiff.Class.ToExpr () instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Types.Bool instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Types.Ordering instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Num.Integer.Integer instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Num.Natural.Natural instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Types.Float instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Types.Double instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Types.Int instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Int.Int8 instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Int.Int16 instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Int.Int32 instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Int.Int64 instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Types.Word instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Word.Word8 instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Word.Word16 instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Word.Word32 instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Word.Word64 instance Test.StateMachine.TreeDiff.Class.ToExpr (Data.Proxy.Proxy a) instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Types.Char instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (GHC.Maybe.Maybe a) instance (Test.StateMachine.TreeDiff.Class.ToExpr a, Test.StateMachine.TreeDiff.Class.ToExpr b) => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Either.Either a b) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr [a] instance (Test.StateMachine.TreeDiff.Class.ToExpr a, Test.StateMachine.TreeDiff.Class.ToExpr b) => Test.StateMachine.TreeDiff.Class.ToExpr (a, b) instance (Test.StateMachine.TreeDiff.Class.ToExpr a, Test.StateMachine.TreeDiff.Class.ToExpr b, Test.StateMachine.TreeDiff.Class.ToExpr c) => Test.StateMachine.TreeDiff.Class.ToExpr (a, b, c) instance (Test.StateMachine.TreeDiff.Class.ToExpr a, Test.StateMachine.TreeDiff.Class.ToExpr b, Test.StateMachine.TreeDiff.Class.ToExpr c, Test.StateMachine.TreeDiff.Class.ToExpr d) => Test.StateMachine.TreeDiff.Class.ToExpr (a, b, c, d) instance (Test.StateMachine.TreeDiff.Class.ToExpr a, Test.StateMachine.TreeDiff.Class.ToExpr b, Test.StateMachine.TreeDiff.Class.ToExpr c, Test.StateMachine.TreeDiff.Class.ToExpr d, Test.StateMachine.TreeDiff.Class.ToExpr e) => Test.StateMachine.TreeDiff.Class.ToExpr (a, b, c, d, e) instance (Test.StateMachine.TreeDiff.Class.ToExpr a, GHC.Real.Integral a) => Test.StateMachine.TreeDiff.Class.ToExpr (GHC.Real.Ratio a) instance Data.Fixed.HasResolution a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Fixed.Fixed a) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Functor.Identity.Identity a) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Functor.Const.Const a b) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Control.Applicative.ZipList a) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (GHC.Base.NonEmpty a) instance Test.StateMachine.TreeDiff.Class.ToExpr GHC.Base.Void instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Semigroup.Internal.Dual a) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Semigroup.Internal.Sum a) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Semigroup.Internal.Product a) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Monoid.First a) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Monoid.Last a) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Semigroup.Min a) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Semigroup.Max a) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Semigroup.First a) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Semigroup.Last a) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Tree.Tree a) instance (Test.StateMachine.TreeDiff.Class.ToExpr k, Test.StateMachine.TreeDiff.Class.ToExpr v) => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Map.Internal.Map k v) instance Test.StateMachine.TreeDiff.Class.ToExpr k => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Set.Internal.Set k) instance Test.StateMachine.TreeDiff.Class.ToExpr v => Test.StateMachine.TreeDiff.Class.ToExpr (Data.IntMap.Internal.IntMap v) instance Test.StateMachine.TreeDiff.Class.ToExpr Data.IntSet.Internal.IntSet instance Test.StateMachine.TreeDiff.Class.ToExpr v => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Sequence.Internal.Seq v) instance Test.StateMachine.TreeDiff.Class.ToExpr Data.Text.Internal.Lazy.Text instance Test.StateMachine.TreeDiff.Class.ToExpr Data.Text.Internal.Text instance Test.StateMachine.TreeDiff.Class.ToExpr Data.Time.Calendar.Days.Day instance Test.StateMachine.TreeDiff.Class.ToExpr Data.Time.Clock.Internal.UTCTime.UTCTime instance Test.StateMachine.TreeDiff.Class.ToExpr Data.ByteString.Lazy.Internal.ByteString instance Test.StateMachine.TreeDiff.Class.ToExpr Data.ByteString.Internal.Type.ByteString instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Vector.Vector a) instance (Test.StateMachine.TreeDiff.Class.ToExpr a, Data.Vector.Unboxed.Base.Unbox a) => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Vector.Unboxed.Base.Vector a) instance (Test.StateMachine.TreeDiff.Class.ToExpr a, Foreign.Storable.Storable a) => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Vector.Storable.Vector a) instance (Test.StateMachine.TreeDiff.Class.ToExpr a, Data.Primitive.Types.Prim a) => Test.StateMachine.TreeDiff.Class.ToExpr (Data.Vector.Primitive.Vector a) -- | Utilities to pretty print Expr and EditExpr module Test.StateMachine.TreeDiff.Pretty -- | Because we don't want to commit to single pretty printing library, we -- use explicit dictionary. data Pretty doc Pretty :: (ConstructorName -> doc) -> ([(FieldName, doc)] -> doc) -> ([doc] -> doc) -> (doc -> doc) -> (doc -> doc) -> (doc -> doc) -> ([doc] -> doc) -> (doc -> doc) -> (doc -> doc -> doc) -> Pretty doc [ppCon] :: Pretty doc -> ConstructorName -> doc [ppRec] :: Pretty doc -> [(FieldName, doc)] -> doc [ppLst] :: Pretty doc -> [doc] -> doc [ppCpy] :: Pretty doc -> doc -> doc [ppIns] :: Pretty doc -> doc -> doc [ppDel] :: Pretty doc -> doc -> doc [ppSep] :: Pretty doc -> [doc] -> doc [ppParens] :: Pretty doc -> doc -> doc [ppHang] :: Pretty doc -> doc -> doc -> doc -- | Pretty print an Expr using explicit pretty-printing dictionary. ppExpr :: Pretty doc -> Expr -> doc -- | Pretty print an Edit EditExpr using explicit -- pretty-printing dictionary. ppEditExpr :: Pretty doc -> Edit EditExpr -> doc -- | Like ppEditExpr but print unchanged parts only shallowly ppEditExprCompact :: Pretty doc -> Edit EditExpr -> doc -- | Pretty via pretty library. prettyPretty :: Pretty Doc -- | Pretty print Expr using pretty. -- --
-- >>> prettyExpr $ Rec "ex" (Map.fromList [("[]", App "bar" [])])
-- ex {`[]` = bar}
--
prettyExpr :: Expr -> Doc
-- | Pretty print Edit EditExpr using
-- pretty.
prettyEditExpr :: Edit EditExpr -> Doc
-- | Compact prettyEditExpr.
prettyEditExprCompact :: Edit EditExpr -> Doc
-- | Pretty via ansi-wl-pprint library (with colors).
ansiWlPretty :: Pretty Doc
-- | Pretty print Expr using ansi-wl-pprint.
ansiWlExpr :: Expr -> Doc
-- | Pretty print Edit EditExpr using
-- ansi-wl-pprint.
ansiWlEditExpr :: Edit EditExpr -> Doc
-- | Compact ansiWlEditExpr
ansiWlEditExprCompact :: Edit EditExpr -> Doc
-- | Like ansiWlPretty but color the background.
ansiWlBgPretty :: Pretty Doc
-- | Pretty print Expr using ansi-wl-pprint.
ansiWlBgExpr :: Expr -> Doc
-- | Pretty print Edit EditExpr using
-- ansi-wl-pprint.
ansiWlBgEditExpr :: Edit EditExpr -> Doc
-- | Compact ansiWlBgEditExpr.
ansiWlBgEditExprCompact :: Edit EditExpr -> Doc
-- | Escape field or constructor name
--
-- -- >>> putStrLn $ escapeName "Foo" -- Foo ---- --
-- >>> putStrLn $ escapeName "_×_" -- _×_ ---- --
-- >>> putStrLn $ escapeName "-3" -- `-3` ---- --
-- >>> putStrLn $ escapeName "kebab-case" -- kebab-case ---- --
-- >>> putStrLn $ escapeName "inner space" -- `inner space` ---- --
-- >>> putStrLn $ escapeName $ show "looks like a string" -- "looks like a string" ---- --
-- >>> putStrLn $ escapeName $ show "tricky" ++ " " -- `"tricky" ` ---- --
-- >>> putStrLn $ escapeName "[]" -- `[]` ---- --
-- >>> putStrLn $ escapeName "_,_" -- `_,_` --escapeName :: String -> String -- | Implements CanDiff with our vendored version of -- tree-diff. module Test.StateMachine.TreeDiff.Diffing instance Test.StateMachine.TreeDiff.Class.ToExpr Test.StateMachine.Types.References.Var instance (Test.StateMachine.TreeDiff.Class.ToExpr a, Test.StateMachine.TreeDiff.Class.ToExpr (Test.StateMachine.Lockstep.NAry.MockHandleN t a)) => Test.StateMachine.TreeDiff.Class.ToExpr (Test.StateMachine.Lockstep.NAry.Refs t Test.StateMachine.Types.References.Concrete a) instance Test.StateMachine.TreeDiff.Class.ToExpr x => Test.StateMachine.Diffing.CanDiff x instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Test.StateMachine.Types.References.Symbolic a) instance Test.StateMachine.TreeDiff.Class.ToExpr a => Test.StateMachine.TreeDiff.Class.ToExpr (Test.StateMachine.Types.References.Concrete a) instance Test.StateMachine.TreeDiff.Class.ToExpr (r a) => Test.StateMachine.TreeDiff.Class.ToExpr (Test.StateMachine.Types.References.Reference a r) instance Test.StateMachine.TreeDiff.Class.ToExpr (Test.StateMachine.Types.References.Opaque a) instance Test.StateMachine.TreeDiff.Class.ToExpr (Test.StateMachine.Lockstep.Simple.MockHandle t) => Test.StateMachine.TreeDiff.Class.ToExpr (Test.StateMachine.Lockstep.NAry.MockHandleN (Test.StateMachine.Lockstep.Simple.Simple t) (Test.StateMachine.Lockstep.Simple.RealHandle t)) instance Data.SOP.Constraint.All (Data.SOP.Constraint.And Test.StateMachine.TreeDiff.Class.ToExpr (Data.SOP.Constraint.Compose Test.StateMachine.TreeDiff.Class.ToExpr (Test.StateMachine.Lockstep.NAry.MockHandleN t))) (Test.StateMachine.Lockstep.NAry.RealHandles t) => Test.StateMachine.TreeDiff.Class.ToExpr (Test.StateMachine.Lockstep.NAry.Refss t Test.StateMachine.Types.References.Concrete) instance (Test.StateMachine.TreeDiff.Class.ToExpr (Test.StateMachine.Lockstep.NAry.MockState t), Data.SOP.Constraint.All (Data.SOP.Constraint.And Test.StateMachine.TreeDiff.Class.ToExpr (Data.SOP.Constraint.Compose Test.StateMachine.TreeDiff.Class.ToExpr (Test.StateMachine.Lockstep.NAry.MockHandleN t))) (Test.StateMachine.Lockstep.NAry.RealHandles t)) => Test.StateMachine.TreeDiff.Class.ToExpr (Test.StateMachine.Lockstep.NAry.Model t Test.StateMachine.Types.References.Concrete) -- | Diffing of (expression) trees. -- -- Diffing arbitrary Haskell data. First we convert values to untyped -- haskell-like expression Expr using generically derivable -- ToExpr class. Then we can diff two Expr values. The -- conversion and diffing is done by ediff function. See type and -- function haddocks for an examples. -- -- Interesting modules: -- --
-- >>> let x = Node 'a' [Node 'b' [], Node 'c' [return 'd', return 'e'], Node 'f' []] -- -- >>> ppTree PP.char x -- (a b (c d e) f) ---- -- If we modify an argument in a tree, we'll notice it's changed: -- --
-- >>> let y = Node 'a' [Node 'b' [], Node 'c' [return 'x', return 'e'], Node 'f' []] -- -- >>> ppTree PP.char y -- (a b (c x e) f) ---- --
-- >>> ppEditTree PP.char (treeDiff x y) -- (a b (c -d +x e) f) ---- -- If we modify a constructor, the whole sub-trees is replaced, though -- there might be common subtrees. -- --
-- >>> let z = Node 'a' [Node 'b' [], Node 'd' [], Node 'f' []] -- -- >>> ppTree PP.char z -- (a b d f) ---- --
-- >>> ppEditTree PP.char (treeDiff x z) -- (a b -(c d e) +d f) ---- -- If we add arguments, they are spotted too: -- --
-- >>> let w = Node 'a' [Node 'b' [], Node 'c' [return 'd', return 'x', return 'e'], Node 'f' []] -- -- >>> ppTree PP.char w -- (a b (c d x e) f) ---- --
-- >>> ppEditTree PP.char (treeDiff x w) -- (a b (c d +x e) f) --treeDiff :: Eq a => Tree a -> Tree a -> Edit (EditTree a) -- | Type used in the result of treeDiff. -- -- It's essentially a Tree, but the forest list is changed from -- [tree a] to [Edit (tree a)]. This highlights -- that treeDiff performs a list diff on each tree level. data EditTree a EditNode :: a -> [Edit (EditTree a)] -> EditTree a -- | List edit operations -- -- The Swp constructor is redundant, but it let us spot a -- recursion point when performing tree diffs. data Edit a -- | insert Ins :: a -> Edit a -- | delete Del :: a -> Edit a -- | copy unchanged Cpy :: a -> Edit a -- | swap, i.e. delete + insert Swp :: a -> a -> Edit a instance GHC.Show.Show a => GHC.Show.Show (Test.StateMachine.TreeDiff.Tree.EditTree a)