diff --git a/src/Source.hs b/src/Source.hs index 0a0a23527..379995f9b 100644 --- a/src/Source.hs +++ b/src/Source.hs @@ -9,17 +9,17 @@ newtype Source a = Source { getVector :: Vector.Vector a } makeSource :: [a] -> Source a makeSource = Source . Vector.fromList -unSource :: Source a -> [a] -unSource (Source vector) = Vector.toList vector +toList :: Source a -> [a] +toList = Vector.toList . getVector slice :: Range -> Source a -> Source a slice range (Source vector) = Source $ Vector.slice (start range) (end range - start range) vector toString :: Source Char -> String -toString = unSource +toString = toList at :: Source a -> Int -> a -at = (!!) . unSource +at = (!!) . toList null :: Source a -> Bool null (Source vector) = Vector.null vector diff --git a/test/SplitSpec.hs b/test/SplitSpec.hs index 88ef8eec9..a61bd7d29 100644 --- a/test/SplitSpec.hs +++ b/test/SplitSpec.hs @@ -48,11 +48,11 @@ spec = do prop "preserves line counts in equal sources" $ \ source -> - length (splitAnnotatedByLines (source, source) (getTotalRange source, getTotalRange source) (mempty, mempty) (Indexed . fst $ foldl combineIntoLeaves ([], 0) source)) `shouldBe` length (filter (== '\n') $ unSource source) + 1 + length (splitAnnotatedByLines (source, source) (getTotalRange source, getTotalRange source) (mempty, mempty) (Indexed . fst $ foldl combineIntoLeaves ([], 0) source)) `shouldBe` length (filter (== '\n') $ toList source) + 1 prop "produces the maximum line count in inequal sources" $ \ sourceA sourceB -> - length (splitAnnotatedByLines (sourceA, sourceB) (getTotalRange sourceA, getTotalRange sourceB) (mempty, mempty) (Indexed $ zipWith (leafWithRangesInSources sourceA sourceB) (actualLineRanges (getTotalRange sourceA) sourceA) (actualLineRanges (getTotalRange sourceB) sourceB))) `shouldBe` max (length (filter (== '\n') $ unSource sourceA) + 1) (length (filter (== '\n') $ unSource sourceB) + 1) + length (splitAnnotatedByLines (sourceA, sourceB) (getTotalRange sourceA, getTotalRange sourceB) (mempty, mempty) (Indexed $ zipWith (leafWithRangesInSources sourceA sourceB) (actualLineRanges (getTotalRange sourceA) sourceA) (actualLineRanges (getTotalRange sourceB) sourceB))) `shouldBe` max (length (filter (== '\n') $ toList sourceA) + 1) (length (filter (== '\n') $ toList sourceB) + 1) describe "adjoinRowsBy" $ do prop "is identity on top of no rows" $ @@ -110,7 +110,7 @@ spec = do combineIntoLeaves (leaves, start) char = (leaves ++ [ Free $ Annotated (Info (Range start $ start + 1) mempty, Info (Range start $ start + 1) mempty) (Leaf [ char ]) ], start + 1) - leafWithRangesInSources sourceA sourceB rangeA rangeB = Free $ Annotated (Info rangeA mempty, Info rangeB mempty) (Leaf $ unSource sourceA ++ unSource sourceB) + leafWithRangesInSources sourceA sourceB rangeA rangeB = Free $ Annotated (Info rangeA mempty, Info rangeB mempty) (Leaf $ toList sourceA ++ toList sourceB) openMaybe :: Maybe Bool -> Maybe (Maybe Bool) openMaybe (Just a) = Just (Just a)