1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 18:23:44 +03:00

Rename adjoinBy → adjoinRowsBy.

This commit is contained in:
Rob Rix 2015-12-21 12:57:50 -05:00
parent d4cfb276a4
commit 64362581c4
2 changed files with 13 additions and 13 deletions

View File

@ -196,7 +196,7 @@ annotatedToRows (Annotated (Info left leftCategories, Info right rightCategories
ranges = (left, right)
sources = (before, after)
childRows = appendRemainder . foldl sumRows ([], starts ranges)
appendRemainder (rows, previousIndices) = reverse . foldl (adjoinBy openElement) [] $ rows ++ contextRows (ends ranges) previousIndices sources
appendRemainder (rows, previousIndices) = reverse . foldl (adjoinRowsBy openElement) [] $ rows ++ contextRows (ends ranges) previousIndices sources
starts (left, right) = (start left, start right)
ends (left, right) = (end left, end right)
sumRows (rows, previousIndices) child = (allRows, ends childRanges)
@ -227,28 +227,28 @@ rowFromMaybeRows a b = Row (maybe EmptyLine (Line False . (:[])) a) (maybe Empty
maybeLast :: Foldable f => f a -> Maybe a
maybeLast = foldl (flip $ const . Just) Nothing
adjoinBy :: (a -> Maybe a) -> [Row a] -> Row a -> [Row a]
adjoinBy _ [] row = [row]
adjoinRowsBy :: (a -> Maybe a) -> [Row a] -> Row a -> [Row a]
adjoinRowsBy _ [] row = [row]
adjoinBy f rows (Row left' right') | Just _ <- openLineBy f $ leftLines rows, Just _ <- openLineBy f $ rightLines rows = zipWith Row lefts rights
adjoinRowsBy f rows (Row left' right') | Just _ <- openLineBy f $ leftLines rows, Just _ <- openLineBy f $ rightLines rows = zipWith Row lefts rights
where lefts = adjoinLinesBy f (leftLines rows) left'
rights = adjoinLinesBy f (rightLines rows) right'
adjoinBy f rows (Row left' right') | Just _ <- openLineBy f $ leftLines rows = case right' of
adjoinRowsBy f rows (Row left' right') | Just _ <- openLineBy f $ leftLines rows = case right' of
EmptyLine -> rest
_ -> Row EmptyLine right' : rest
where rest = zipWith Row lefts rights
lefts = adjoinLinesBy f (leftLines rows) left'
rights = rightLines rows
adjoinBy f rows (Row left' right') | Just _ <- openLineBy f $ rightLines rows = case left' of
adjoinRowsBy f rows (Row left' right') | Just _ <- openLineBy f $ rightLines rows = case left' of
EmptyLine -> rest
_ -> Row left' EmptyLine : rest
where rest = zipWith Row lefts rights
lefts = leftLines rows
rights = adjoinLinesBy f (rightLines rows) right'
adjoinBy _ rows row = row : rows
adjoinRowsBy _ rows row = row : rows
leftLines :: [Row a] -> [Line a]
leftLines rows = left <$> rows

View File

@ -112,26 +112,26 @@ spec = do
([ Row (Line False [ span "t\776" ]) (Line False [ span "\7831"]) ], (Range 0 2, Range 0 1))
describe "adjoinBy" $ do
describe "adjoinRowsBy" $ do
prop "is identity on top of no rows" $
\ a -> adjoinBy openElement [] a == [ a ]
\ a -> adjoinRowsBy openElement [] a == [ a ]
prop "appends onto open rows" $
forAll ((arbitrary `suchThat` isOpen) >>= \ a -> ((,) a) <$> (arbitrary `suchThat` isOpen)) $
\ (a@(Row (Line ac1 as1) (Line bc1 bs1)), b@(Row (Line ac2 as2) (Line bc2 bs2))) ->
adjoinBy openElement [ a ] b `shouldBe` [ Row (Line (ac1 || ac2) $ as1 ++ as2) (Line (bc1 || bc2) $ bs1 ++ bs2) ]
adjoinRowsBy openElement [ a ] b `shouldBe` [ Row (Line (ac1 || ac2) $ as1 ++ as2) (Line (bc1 || bc2) $ bs1 ++ bs2) ]
prop "does not append onto closed rows" $
forAll ((arbitrary `suchThat` isClosed) >>= \ a -> ((,) a) <$> (arbitrary `suchThat` isClosed)) $
\ (a, b) -> adjoinBy openElement [ a ] b `shouldBe` [ b, a ]
\ (a, b) -> adjoinRowsBy openElement [ a ] b `shouldBe` [ b, a ]
prop "does not promote elements through empty lines onto closed lines" $
forAll ((arbitrary `suchThat` isClosed) >>= \ a -> ((,) a) <$> (arbitrary `suchThat` isClosed)) $
\ (a, b) -> adjoinBy openElement [ Row EmptyLine EmptyLine, a ] b `shouldBe` [ b, Row EmptyLine EmptyLine, a ]
\ (a, b) -> adjoinRowsBy openElement [ Row EmptyLine EmptyLine, a ] b `shouldBe` [ b, Row EmptyLine EmptyLine, a ]
prop "promotes elements through empty lines onto open lines" $
forAll ((arbitrary `suchThat` isOpen) >>= \ a -> ((,) a) <$> (arbitrary `suchThat` isOpen)) $
\ (a, b) -> adjoinBy openElement [ Row EmptyLine EmptyLine, a ] b `shouldBe` Row EmptyLine EmptyLine : adjoinBy openElement [ a ] b
\ (a, b) -> adjoinRowsBy openElement [ Row EmptyLine EmptyLine, a ] b `shouldBe` Row EmptyLine EmptyLine : adjoinRowsBy openElement [ a ] b
describe "termToLines" $ do
it "splits multi-line terms into multiple lines" $