pure cln
goToLine' :: CursorHandle -> Integer -> IO Integer
-goToLine' CursorHandle{..} ln = do
- modifyMVar linesIdx $ \(idx, size, _) -> do
+goToLine' ch@CursorHandle{..} ln =
+ if (ln < 0) then getCurrentLineNumber' ch
+ else modifyMVar linesIdx $ \(idx, size, _) -> do
if ln > size then do
hSeek fileHandle AbsoluteSeek (idx !! 0)
-- try to read until the requested line number
l <- getCurrentLine c
l `shouldBe` Just "Sed elementum velit sit amet orci mollis tincidunt."
+ it "goToLine is negative" $ \(_, c) -> do
+ ln <- goToLine c (-10)
+ ln `shouldBe` 0
+
+ l <- getCurrentLine c
+ l `shouldBe` Just "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
+
it "goToLine is too big" $ \(_, c) -> do
l <- getCurrentLine c
l `shouldBe` Just "Lorem ipsum dolor sit amet, consectetur adipiscing elit."