From: Evgenii Akentev Date: Sun, 23 Jul 2023 15:18:22 +0000 (+0400) Subject: Add proper description. X-Git-Url: https://git.ak3n.com/?a=commitdiff_plain;h=75263fd14f5d10312759c45acb1142590aa4ef32;p=line-indexed-cursor.git Add proper description. --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 58eae78..14dee2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -# Revision history for line-indexed-file-cursor +# Revision history for line-indexed-cursor -## 0.1.0.0 -- YYYY-mm-dd +## 0.1.0.0 -- 2023-08-23 * First version. Released on an unsuspecting world. diff --git a/line-indexed-cursor.cabal b/line-indexed-cursor.cabal index bdf6791..648c9b2 100644 --- a/line-indexed-cursor.cabal +++ b/line-indexed-cursor.cabal @@ -1,6 +1,8 @@ cabal-version: 3.0 name: line-indexed-cursor version: 0.1.0.0 +synopsis: Line-indexed file reader. +description: Lazily builds the index with the line numbers while reading the file making it possible to rewind to them quickly later. license: MIT license-file: LICENSE author: Evgenii Akentev @@ -15,7 +17,6 @@ common warnings -Wincomplete-record-updates -Wredundant-constraints -Widentities -Wunused-packages -Wmissing-deriving-strategies - library import: warnings exposed-modules: System.IO.LineIndexedCursor diff --git a/src/System/IO/LineIndexedCursor.hs b/src/System/IO/LineIndexedCursor.hs index 871c23c..f720038 100644 --- a/src/System/IO/LineIndexedCursor.hs +++ b/src/System/IO/LineIndexedCursor.hs @@ -21,7 +21,7 @@ module System.IO.LineIndexedCursor import Data.Maybe (fromMaybe) import qualified Data.Array as A import Data.ByteString (ByteString, hGetLine) -import Control.Concurrent.MVar +import Control.Concurrent.MVar (MVar, newMVar, readMVar, modifyMVar, modifyMVar_) import System.IO (Handle, hTell, hSeek, SeekMode(..), hIsEOF) defaultListCapacity :: Integer diff --git a/test/Main.hs b/test/Main.hs index 0d15f26..2546772 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -33,18 +33,6 @@ main = hspec $ do l'' <- getCurrentLine c l'' `shouldBe` Just "Pellentesque accumsan dolor at nisl pulvinar, ut bibendum diam egestas." - ln' <- goToLine c 3 - ln' `shouldBe` 3 - - ln'' <- goToLine c 2 - ln'' `shouldBe` 2 - - ln''' <- goToLine c 1 - ln''' `shouldBe` 1 - - ln'''' <- goToLine c 0 - ln'''' `shouldBe` 0 - it "goToLine works" $ \(_, c) -> do ln <- goToLine c 10 ln `shouldBe` 10 @@ -84,7 +72,7 @@ main = hspec $ do s <- getCursorState c s `shouldBe` [0,57,117,191,244,316,384,429,511,561,616,668,715,761,799,851,907,941,981,1024,1068] - it "read line, then go to beginning and forth" $ \(_, c) -> do + it "read line, then go to the beginning and forth" $ \(_, c) -> do cln <- getCurrentLineNumber c cln `shouldBe` 0 @@ -126,3 +114,15 @@ main = hspec $ do ln'''' <- goToLine c 10 ln'''' `shouldBe` 10 + + ln''''' <- goToLine c 3 + ln''''' `shouldBe` 3 + + ln'''''' <- goToLine c 2 + ln'''''' `shouldBe` 2 + + ln''''''' <- goToLine c 1 + ln''''''' `shouldBe` 1 + + ln'''''''' <- goToLine c 0 + ln'''''''' `shouldBe` 0 \ No newline at end of file