table-layout 0.9.0.2 → 0.9.1.0
raw patch · 4 files changed
+30/−6 lines, 4 files
Files
- CHANGELOG.md +7/−0
- src/Text/Layout/Table/Justify.hs +8/−5
- table-layout.cabal +1/−1
- test-suite/TestSpec.hs +14/−0
CHANGELOG.md view
@@ -2,6 +2,13 @@ ## [Unreleased] +## [0.9.1.0] - 2020-12-21++### Fixed++- Fix recently introduced errors which made text justification completely+ unusable. Add test coverage for relevant functions. (#15)+ ## [0.9.0.2] - 2020-12-20 ### Fixed
src/Text/Layout/Table/Justify.hs view
@@ -6,6 +6,7 @@ ( -- * Text justification justify , justifyText+ , Line(..) , fitWords , concatPadLine @@ -15,6 +16,8 @@ , mixedDimorphicSummandsBy ) where +import Data.List (foldl')+ import Text.Layout.Table.Primitives.Basic -- | Uses 'words' to split the text into words and justifies it with 'justify'.@@ -37,7 +40,7 @@ { lineLength :: Int -- ^ The length of the current line with a single space as separator between the words. , lineWordCount :: Int -- ^ The number of words on the current line. , lineWords :: [String] -- ^ The actual words of the line.- } deriving Show+ } deriving (Eq, Show) -- | Join the words on a line together by filling it with spaces in between. concatPadLine@@ -62,9 +65,9 @@ -> [String] -- ^ The words to join with whitespaces. -> [Line] -- ^ The list of line information. fitWords width = --gather 0 0 []- finishFitState . foldr fitStep (FitState 0 0 [] [])+ finishFitState . foldl' fitStep (FitState 0 0 [] []) where- fitStep word s@FitState {..} =+ fitStep s@FitState {..} word = let wLen = length word newLineLen = fitStateLineLen + 1 + wLen reinit f = FitState wLen 1 [word] $ f fitStateLines@@ -83,10 +86,10 @@ -- | Completes the current line. finishLine :: FitState -> Line-finishLine FitState {..} = Line fitStateLineLen fitStateWordCount fitStateWords+finishLine FitState {..} = Line fitStateLineLen fitStateWordCount $ reverse fitStateWords finishFitState :: FitState -> [Line]-finishFitState s@FitState {..} = finishLines fitStateLines+finishFitState s@FitState {..} = reverse $ finishLines fitStateLines where finishLines = case fitStateWordCount of 0 -> id
table-layout.cabal view
@@ -6,7 +6,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.9.0.2+version: 0.9.1.0 synopsis: Format tabular data as grid or table.
test-suite/TestSpec.hs view
@@ -12,6 +12,7 @@ import Text.Layout.Table.Cell (determineCuts, CutInfo(..), determineCutAction, CutAction(..), applyCutInfo, viewRange) import Text.Layout.Table.Spec.OccSpec import Text.Layout.Table.Primitives.Basic+import Text.Layout.Table.Justify spec :: Spec spec = do@@ -154,9 +155,22 @@ length (alignFixed' p n (s :: String) :: String) `shouldBe` n describe "text justification" $ do+ describe "fitWords" $ do+ it "single word" $ fitWords 5 ["test"] `shouldBe` [Line 4 1 ["test"]]+ it "two words" $ fitWords 3 ["a", "b"] `shouldBe` [Line 3 2 ["a", "b"]]+ it "breaking words" $+ fitWords 2 ["a", "b"] `shouldBe` [Line 1 1 ["a"], Line 1 1 ["b"]]+ it "breaking words, multiple words per line" $+ fitWords 3 ["a", "b", "c", "d"] `shouldBe` [Line 3 2 ["a", "b"], Line 3 2 ["c", "d"]]+ describe "justify" $ do it "break lines" $ justify 3 ["not", "now"] `shouldBe` ["not", "now"] it "words in right order" $ justify 10 ["not", "now"] `shouldBe` ["not now"]+ it "" $ justify 3 ["a", "b", "c", "d", "e"] `shouldBe` ["a b", "c d", "e"]++ describe "concatPadLine" $ do+ it "even" $ concatPadLine 9 (Line 9 3 ["It", "is", "on"]) `shouldBe` "It is on"+ it "odd" $ concatPadLine 13 (Line 11 4 ["It", "is", "on", "us"]) `shouldBe` "It is on us" where customCM = doubleCutMark "<.." "..>" unevenCM = doubleCutMark "<" "-->"