module Skeletest.Internal.Utils.Diff (
  showLineDiff,
) where

import Data.Algorithm.DiffContext (getContextDiffNew, prettyContextDiff)
import Data.Text (Text)
import Data.Text qualified as Text
import Text.PrettyPrint qualified as PP

showLineDiff :: (Text, Text) -> (Text, Text) -> Text
showLineDiff :: (Text, Text) -> (Text, Text) -> Text
showLineDiff (Text
fromName, Text
fromContent) (Text
toName, Text
toContent) =
  String -> Text
Text.pack (String -> Text) -> (Doc -> String) -> Doc -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> String
PP.render (Doc -> Text) -> Doc -> Text
forall a b. (a -> b) -> a -> b
$
    Doc -> Doc -> (Text -> Doc) -> ContextDiff Text -> Doc
forall c. Doc -> Doc -> (c -> Doc) -> ContextDiff c -> Doc
prettyContextDiff (Text -> Doc
ppText Text
fromName) (Text -> Doc
ppText Text
toName) Text -> Doc
ppText (ContextDiff Text -> Doc) -> ContextDiff Text -> Doc
forall a b. (a -> b) -> a -> b
$
      Maybe Int -> [Text] -> [Text] -> ContextDiff Text
forall a. Eq a => Maybe Int -> [a] -> [a] -> ContextDiff a
getContextDiffNew (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
5) (Text -> [Text]
Text.lines Text
fromContent) (Text -> [Text]
Text.lines Text
toContent)
  where
    ppText :: Text -> Doc
ppText = String -> Doc
PP.text (String -> Doc) -> (Text -> String) -> Text -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
Text.unpack