From ab8e407df3b7a86650756c43b8df7470e1ddd0ef Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 14 Feb 2017 15:42:14 -0500 Subject: [PATCH] Get the tests compiling again. --- test/AlignmentSpec.hs | 4 ++-- test/PatchOutputSpec.hs | 2 +- test/Source/Spec.hs | 19 ++++++++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/test/AlignmentSpec.hs b/test/AlignmentSpec.hs index e965d71d2..f14b8d4ca 100644 --- a/test/AlignmentSpec.hs +++ b/test/AlignmentSpec.hs @@ -222,7 +222,7 @@ toAlignBranchInputs elements = (sources, join . (`evalState` both 0 0) . travers alignBranchElement element = case element of Child key contents -> Child key <$> joinCrosswalk lines contents Margin contents -> Margin <$> joinCrosswalk lines contents - where lines = fmap Source.sourceText . Source.actualLines . Source.fromText + where lines = fmap Source.toText . Source.actualLines . Source.fromText sources = foldMap Source.fromText <$> bothContents elements ranges = fmap (filter (\ (Range start end) -> start /= end)) $ Source.actualLineRanges <$> (Source.totalRange <$> sources) <*> sources bothContents = foldMap (modifyJoin (fromThese [] []) . fmap (:[]) . branchElementContents) @@ -273,7 +273,7 @@ instance Show (PrettyDiff a) where where prettyPrinted = showLine (maximum (0 : (maximum . fmap length <$> shownLines))) <$> shownLines >>= ('\n':) shownLines = catMaybes $ toBoth <$> lines showLine n line = uncurry ((<>) . (++ " | ")) (fromThese (replicate n ' ') (replicate n ' ') (runJoin (pad n <$> line))) - showDiff (range, _) = filter (/= '\n') . Text.unpack . Source.sourceText . Source.slice range + showDiff (range, _) = filter (/= '\n') . Text.unpack . Source.toText . Source.slice range pad n string = (<>) (take n string) (replicate (max 0 (n - length string)) ' ') toBoth them = showDiff <$> them `applyThese` modifyJoin (uncurry These) sources diff --git a/test/PatchOutputSpec.hs b/test/PatchOutputSpec.hs index c0d674979..35b9ebcb2 100644 --- a/test/PatchOutputSpec.hs +++ b/test/PatchOutputSpec.hs @@ -14,4 +14,4 @@ spec :: Spec spec = parallel $ do describe "hunks" $ do it "empty diffs have empty hunks" $ - hunks (wrap $ pure (Range 0 0 :. Nil) :< Leaf ("" :: Text)) (both (SourceBlob (fromList "") "abcde" "path2.txt" (Just defaultPlainBlob)) (SourceBlob (fromList "") "xyz" "path2.txt" (Just defaultPlainBlob))) `shouldBe` [Hunk {offset = pure 0, changes = [], trailingContext = []}] + hunks (wrap $ pure (Range 0 0 :. Nil) :< Leaf ("" :: Text)) (both (SourceBlob Source.empty "abcde" "path2.txt" (Just defaultPlainBlob)) (SourceBlob Source.empty "xyz" "path2.txt" (Just defaultPlainBlob))) `shouldBe` [Hunk {offset = pure 0, changes = [], trailingContext = []}] diff --git a/test/Source/Spec.hs b/test/Source/Spec.hs index 43a7b3609..1dccd064e 100644 --- a/test/Source/Spec.hs +++ b/test/Source/Spec.hs @@ -8,37 +8,38 @@ import Source import SourceSpan import Test.Hspec import Test.Hspec.LeanCheck +import Test.LeanCheck spec :: Spec spec = parallel $ do describe "actualLineRanges" $ do prop "produces 1 more range than there are newlines" $ - \ source -> Prologue.length (actualLineRanges (totalRange source) source) `shouldBe` succ (Text.count "\n" (sourceText source)) + \ source -> Prologue.length (actualLineRanges (totalRange source) source) `shouldBe` succ (Text.count "\n" (toText source)) prop "produces exhaustive ranges" $ \ source -> foldMap (`slice` source) (actualLineRanges (totalRange source) source) `shouldBe` source describe "sourceSpanToRange" $ do - prop "computes single-line ranges" $ - \ s -> let source = fromList s + prop "computes single-line ranges" . forAll (unListableByteString `mapT` tiers) $ + \ s -> let source = Source s spans = zipWith (\ i Range {..} -> SourceSpan (SourcePos i 0) (SourcePos i (end - start))) [0..] ranges ranges = actualLineRanges (totalRange source) source in sourceSpanToRange source <$> spans `shouldBe` ranges - prop "computes multi-line ranges" $ - \ s -> let source = fromList s in + prop "computes multi-line ranges" . forAll (unListableByteString `mapT` tiers) $ + \ s -> let source = Source s in sourceSpanToRange source (totalSpan source) `shouldBe` totalRange source - prop "computes sub-line ranges" $ - \ s -> let source = fromList ('*' : s <> "*") in + prop "computes sub-line ranges" . forAll (unListableByteString `mapT` tiers) $ + \ s -> let source = Source ("*" <> s <> "*") in sourceSpanToRange source (insetSpan (totalSpan source)) `shouldBe` insetRange (totalRange source) describe "totalSpan" $ do prop "covers single lines" $ - \ n -> totalSpan (fromList (replicate n '*')) `shouldBe` SourceSpan (SourcePos 0 0) (SourcePos 0 (max 0 n)) + \ n -> totalSpan (fromText (Text.replicate n "*")) `shouldBe` SourceSpan (SourcePos 0 0) (SourcePos 0 (max 0 n)) prop "covers multiple lines" $ - \ n -> totalSpan (fromList (intersperse '\n' (replicate n '*'))) `shouldBe` SourceSpan (SourcePos 0 0) (SourcePos (max 0 (pred n)) (if n > 0 then 1 else 0)) + \ n -> totalSpan (fromText (Text.intersperse '\n' (Text.replicate n "*"))) `shouldBe` SourceSpan (SourcePos 0 0) (SourcePos (max 0 (pred n)) (if n > 0 then 1 else 0)) totalSpan :: Source -> SourceSpan totalSpan source = SourceSpan (SourcePos 0 0) (SourcePos (pred (Prologue.length ranges)) (end lastRange - start lastRange))