module Dino.Verification where
import Prelude
import Data.Text (Text)
import qualified Data.Text as Text
import Text.PrettyPrint.ANSI.Leijen (Doc)
import qualified Text.PrettyPrint.ANSI.Leijen as PP
import Dino.AST.Diff
import Dino.Interpretation
verifyAssertEqStructurally ::
CollectAssertions Reified a -> [(Text, Maybe (Edit NumRep))]
verifyAssertEqStructurally e =
[ (lab, diff (unReified ref) (unReified act))
| (lab, AssertEq ref act) <- as
]
where
as = fold $ prodSnd $ prodSnd $ unIntensional $ unCollectAssertions e
presentStructuralVerificationAsDocs :: [(Text, Maybe (Edit NumRep))] -> [Doc]
presentStructuralVerificationAsDocs as = map mkCase as
where
l = maximum (0 : map (Text.length . fst) as)
l' = min l 20
showLabel lab =
Text.unpack lab ++ ":" ++ replicate (l' - Text.length lab) ' '
mkCase (lab, d) =
PP.string (showLabel lab) <> PP.space <> diffAsTestResult d <> end
where
end = maybe mempty (const $ mempty PP.<$> mempty) d
presentStructuralVerification :: [(Text, Maybe (Edit NumRep))] -> IO ()
presentStructuralVerification =
PP.putDoc . PP.vsep . presentStructuralVerificationAsDocs