1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
{-# LANGUAGE TemplateHaskell #-}
module Ormolu.Diff.TextSpec (spec) where
import Ormolu.Diff.Text
import Ormolu.Terminal
import Ormolu.Utils.IO
import Path
import System.FilePath qualified as FP
import Test.Hspec
spec :: Spec
spec =
describe "printTextDiff" $ do
stdTest "one-line-added" "empty" "one-line"
stdTest "one-line-removed" "one-line" "empty"
stdTest "no-preceding" "main-foo" "main"
stdTest "no-following" "main" "main-v2"
stdTest "simple-hunk" "main-and-foo" "main-and-foo-v2"
stdTest "joined-hunk" "main-and-bar" "main-and-bar-v2"
stdTest "two-hunks" "main-and-baz" "main-and-baz-v2"
stdTest "trimming" "spaced" "spaced-v2"
stdTest "trailing-blank-line" "no-trailing-blank-line" "with-trailing-blank-line"
stdTest "trimming-trailing-both-eof" "applicative-before" "applicative-after"
stdTest "trimming-trailing-both-out-of-margin" "longer" "longer-v2"
-- | Test diff printing.
stdTest ::
-- | Name of the test case
String ->
-- | Location of input A
FilePath ->
-- | Location of input B
FilePath ->
Spec
stdTest name pathA pathB = it name $ do
inputA <-
parseRelFile (FP.addExtension pathA "hs")
>>= readFileUtf8 . toFilePath . (diffInputsDir </>)
inputB <-
parseRelFile (FP.addExtension pathB "hs")
>>= readFileUtf8 . toFilePath . (diffInputsDir </>)
let expectedDiffPath = FP.addExtension name "txt"
expectedDiffText <-
parseRelFile expectedDiffPath
>>= readFileUtf8 . toFilePath . (diffOutputsDir </>)
Just actualDiff <- pure $ diffText inputA inputB "TEST"
runTermPure (printTextDiff actualDiff) `shouldBe` expectedDiffText
diffTestsDir :: Path Rel Dir
diffTestsDir = $(mkRelDir "data/diff-tests")
diffInputsDir :: Path Rel Dir
diffInputsDir = diffTestsDir </> $(mkRelDir "inputs")
diffOutputsDir :: Path Rel Dir
diffOutputsDir = diffTestsDir </> $(mkRelDir "outputs")
|