1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00

Rename makeSourcefromList.

This commit is contained in:
Rob Rix 2015-12-23 23:37:51 -05:00
parent b138864068
commit 69aadf4ec5
3 changed files with 9 additions and 9 deletions

View File

@ -6,8 +6,8 @@ import qualified Data.Vector as Vector
newtype Source a = Source { getVector :: Vector.Vector a }
deriving (Eq, Show, Functor, Foldable)
makeSource :: [a] -> Source a
makeSource = Source . Vector.fromList
fromList :: [a] -> Source a
fromList = Source . Vector.fromList
toList :: Source a -> [a]
toList = Vector.toList . getVector

View File

@ -52,7 +52,7 @@ split diff before after = return . renderHtml
hasChanges diff = or $ const True <$> diff
sources = (makeSource before, makeSource after)
sources = (fromList before, fromList after)
numberRows :: [(Int, Line a, Int, Line a)] -> Row a -> [(Int, Line a, Int, Line a)]
numberRows [] (Row EmptyLine EmptyLine) = []
@ -158,7 +158,7 @@ actualLines source | length source == 0 = [ source ]
actualLines source = case Source.break (== '\n') source of
(l, lines') -> case uncons lines' of
Nothing -> [ l ]
Just (_, lines') -> (makeSource $ toString l ++ "\n") : actualLines lines'
Just (_, lines') -> (fromList $ toString l ++ "\n") : actualLines lines'
-- | Compute the line ranges within a given range of a string.
actualLineRanges :: Range -> Source Char -> [Range]

View File

@ -27,7 +27,7 @@ instance Arbitrary a => Arbitrary (Line a) where
const EmptyLine <$> (arbitrary :: Gen ()) ]
instance Arbitrary a => Arbitrary (Source a) where
arbitrary = makeSource <$> arbitrary
arbitrary = fromList <$> arbitrary
arbitraryLeaf :: Gen (Source Char, Info, Syntax (Source Char) f)
arbitraryLeaf = toTuple <$> arbitrary
@ -82,22 +82,22 @@ spec = do
describe "openLineBy" $ do
it "produces the earliest non-empty line in a list, if open" $
openLineBy (openTerm $ makeSource "\n ") [
openLineBy (openTerm $ fromList "\n ") [
Line [ Info (Range 1 2) mempty :< Leaf "" ],
Line [ Info (Range 0 1) mempty :< Leaf "" ]
] `shouldBe` (Just $ Line [ Info (Range 1 2) mempty :< Leaf "" ])
it "returns Nothing if the earliest non-empty line is closed" $
openLineBy (openTerm $ makeSource "\n") [
openLineBy (openTerm $ fromList "\n") [
Line [ Info (Range 0 1) mempty :< Leaf "" ]
] `shouldBe` Nothing
describe "openTerm" $ do
it "returns Just the term if its substring does not end with a newline" $
let term = Info (Range 0 2) mempty :< Leaf "" in openTerm (makeSource " ") term `shouldBe` Just term
let term = Info (Range 0 2) mempty :< Leaf "" in openTerm (fromList " ") term `shouldBe` Just term
it "returns Nothing for terms whose substring ends with a newline" $
openTerm (makeSource " \n") (Info (Range 0 2) mempty :< Leaf "") `shouldBe` Nothing
openTerm (fromList " \n") (Info (Range 0 2) mempty :< Leaf "") `shouldBe` Nothing
where
isOpenBy f (Row a b) = Maybe.isJust (openLineBy f [ a ]) && Maybe.isJust (openLineBy f [ b ])