mirror of
https://github.com/github/semantic.git
synced 2024-12-25 07:55:12 +03:00
Rename unSource to toList.
This commit is contained in:
parent
e4225faa20
commit
0bb6462fad
@ -9,17 +9,17 @@ newtype Source a = Source { getVector :: Vector.Vector a }
|
|||||||
makeSource :: [a] -> Source a
|
makeSource :: [a] -> Source a
|
||||||
makeSource = Source . Vector.fromList
|
makeSource = Source . Vector.fromList
|
||||||
|
|
||||||
unSource :: Source a -> [a]
|
toList :: Source a -> [a]
|
||||||
unSource (Source vector) = Vector.toList vector
|
toList = Vector.toList . getVector
|
||||||
|
|
||||||
slice :: Range -> Source a -> Source a
|
slice :: Range -> Source a -> Source a
|
||||||
slice range (Source vector) = Source $ Vector.slice (start range) (end range - start range) vector
|
slice range (Source vector) = Source $ Vector.slice (start range) (end range - start range) vector
|
||||||
|
|
||||||
toString :: Source Char -> String
|
toString :: Source Char -> String
|
||||||
toString = unSource
|
toString = toList
|
||||||
|
|
||||||
at :: Source a -> Int -> a
|
at :: Source a -> Int -> a
|
||||||
at = (!!) . unSource
|
at = (!!) . toList
|
||||||
|
|
||||||
null :: Source a -> Bool
|
null :: Source a -> Bool
|
||||||
null (Source vector) = Vector.null vector
|
null (Source vector) = Vector.null vector
|
||||||
|
@ -48,11 +48,11 @@ spec = do
|
|||||||
|
|
||||||
prop "preserves line counts in equal sources" $
|
prop "preserves line counts in equal sources" $
|
||||||
\ source ->
|
\ 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" $
|
prop "produces the maximum line count in inequal sources" $
|
||||||
\ sourceA sourceB ->
|
\ 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
|
describe "adjoinRowsBy" $ do
|
||||||
prop "is identity on top of no rows" $
|
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)
|
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 :: Maybe Bool -> Maybe (Maybe Bool)
|
||||||
openMaybe (Just a) = Just (Just a)
|
openMaybe (Just a) = Just (Just a)
|
||||||
|
Loading…
Reference in New Issue
Block a user