on develop help sign in
fix bug in wrapWithOffsetAndAlignment and add tests
494a520pdlla
src/Data/Text/Zipper.hs+1−1
@@ -367,7 +367,7 @@ wrapWithOffsetAndAlignment
367 -> [WrappedLine] -- (words on that line, hidden space char, offset from beginning of line)
367 -> [WrappedLine] -- (words on that line, hidden space char, offset from beginning of line)
368wrapWithOffsetAndAlignment _ maxWidth _ _ | maxWidth <= 0 = []
368wrapWithOffsetAndAlignment _ maxWidth _ _ | maxWidth <= 0 = []
369wrapWithOffsetAndAlignment alignment maxWidth n txt = assert (n <= maxWidth) r where
369wrapWithOffsetAndAlignment alignment maxWidth n txt = assert (n <= maxWidth) r where
370− r' = splitWordsAtDisplayWidth maxWidth $ T.replicate n " " : wordsWithWhitespace txt
370+ r' = splitWordsAtDisplayWidth maxWidth $ wordsWithWhitespace ( T.replicate n "." <> txt)
371 fmapfn (t,b) = case alignment of
371 fmapfn (t,b) = case alignment of
372 TextAlignment_Left -> WrappedLine t b 0
372 TextAlignment_Left -> WrappedLine t b 0
373 TextAlignment_Right -> WrappedLine t b (maxWidth-l)
373 TextAlignment_Right -> WrappedLine t b (maxWidth-l)
test/Data/Text/ZipperSpec.hs+12−2
@@ -9,14 +9,15 @@ import Prelude
9import Test.Hspec
9import Test.Hspec
10
10
11import qualified Data.Map as Map
11import qualified Data.Map as Map
12−import Data.Text
12+import qualified Data.Text as T
13+import Control.Monad
13
14
14import Data.Text.Zipper
15import Data.Text.Zipper
15
16
16
17
17someSentence = "12345 1234 12"
18someSentence = "12345 1234 12"
18
19
19−splitSentenceAtDisplayWidth :: Int -> Text -> [(Text, Bool)]
20+splitSentenceAtDisplayWidth :: Int -> T.Text -> [(T.Text, Bool)]
20splitSentenceAtDisplayWidth w t = splitWordsAtDisplayWidth w (wordsWithWhitespace t)
21splitSentenceAtDisplayWidth w t = splitWordsAtDisplayWidth w (wordsWithWhitespace t)
21
22
22spec :: Spec
23spec :: Spec
@@ -38,6 +39,7 @@ spec = do
38 wrapWithOffsetAndAlignment TextAlignment_Left 5 0 someSentence `shouldBe` [(WrappedLine "12345" True 0), (WrappedLine "1234" True 0), (WrappedLine "12" False 0)]
39 wrapWithOffsetAndAlignment TextAlignment_Left 5 0 someSentence `shouldBe` [(WrappedLine "12345" True 0), (WrappedLine "1234" True 0), (WrappedLine "12" False 0)]
39 wrapWithOffsetAndAlignment TextAlignment_Right 5 0 someSentence `shouldBe` [(WrappedLine "12345" True 0), (WrappedLine "1234" True 1), (WrappedLine "12" False 3)]
40 wrapWithOffsetAndAlignment TextAlignment_Right 5 0 someSentence `shouldBe` [(WrappedLine "12345" True 0), (WrappedLine "1234" True 1), (WrappedLine "12" False 3)]
40 wrapWithOffsetAndAlignment TextAlignment_Center 5 0 someSentence `shouldBe` [(WrappedLine "12345" True 0), (WrappedLine "1234" True 0), (WrappedLine "12" False 1)]
41 wrapWithOffsetAndAlignment TextAlignment_Center 5 0 someSentence `shouldBe` [(WrappedLine "12345" True 0), (WrappedLine "1234" True 0), (WrappedLine "12" False 1)]
42+ wrapWithOffsetAndAlignment TextAlignment_Left 5 1 someSentence `shouldBe` [(WrappedLine "1234" False 0), (WrappedLine "5" True 0), (WrappedLine "1234" True 0), (WrappedLine "12" False 0)]
41 it "eolSpacesToLogicalLines" $ do
43 it "eolSpacesToLogicalLines" $ do
42 eolSpacesToLogicalLines
44 eolSpacesToLogicalLines
43 [
45 [
@@ -83,3 +85,11 @@ spec = do
83 _displayLines_cursorPos dl4 `shouldBe` (5,0)
85 _displayLines_cursorPos dl4 `shouldBe` (5,0)
84 _displayLines_cursorPos dl5 `shouldBe` (4,0)
86 _displayLines_cursorPos dl5 `shouldBe` (4,0)
85 _displayLines_cursorPos dl6 `shouldBe` (4,0)
87 _displayLines_cursorPos dl6 `shouldBe` (4,0)
88+ it "displayLinesWithAlignment - spans" $ do
89+ let
90+ someText = top $ fromText "0123456789abcdefgh"
91+ -- outer span length should be invariant when changing TextAlignment and CursorPosition
92+ forM_ [0..4] $ \x -> do
93+ forM_ [TextAlignment_Left, TextAlignment_Center, TextAlignment_Right] $ \ta -> do
94+ length (_displayLines_spans $ (displayLinesWithAlignment ta 5 () () someText) {_displayLines_cursorPos = (x,x)}) `shouldBe` 4
95+ length (_displayLines_spans $ (displayLinesWithAlignment ta 10 () () someText) {_displayLines_cursorPos = (x,x)}) `shouldBe` 2