on develop help sign in
correct test
commitcb1959fe63fd1a1e3964adf61ef1b8f2468bf7af authorpdlla <chippermonky@gmail.com> dateSun 13 Jun 2021, 16:32 (5 years ago) parentf572a3e
1 file changed+72−71
test/Data/Text/ZipperSpec.hs+72−71
test/Data/Text/ZipperSpec.hs+72−71
@@ -21,75 +21,76 @@ splitSentenceAtDisplayWidth :: Int -> T.Text -> [(T.Text, Bool)]
2121splitSentenceAtDisplayWidth w t = splitWordsAtDisplayWidth w (wordsWithWhitespace t)
2222
2323spec :: Spec
24−spec = do
24+spec =
2525 describe "Zipper" $ do
26− it "wordsWithWhitespace" $ do
27− wordsWithWhitespace "" `shouldBe` []
28− wordsWithWhitespace "😱😱😱" `shouldBe` ["😱😱😱"]
29− wordsWithWhitespace "abcd efgf f" `shouldBe` ["abcd ","efgf ", "f"]
30− wordsWithWhitespace "aoeu " `shouldBe` ["aoeu "]
31− it "splitWordsAtDisplayWidth" $ do
32− fmap fst (splitSentenceAtDisplayWidth 5 "123456") `shouldBe` ["12345","6"]
33− fmap fst (splitSentenceAtDisplayWidth 5 "12345 6") `shouldBe` ["12345","6"]
34− fmap fst (splitSentenceAtDisplayWidth 5 "1234 56") `shouldBe` ["1234","56"]
35− fmap fst (splitSentenceAtDisplayWidth 5 "12345678912345") `shouldBe` ["12345","67891","2345"]
36− fmap fst (splitSentenceAtDisplayWidth 5 "1234 56") `shouldBe` ["1234 "," 56"]
37− fmap fst (splitSentenceAtDisplayWidth 8 "1 2 3 4 5 6 7 8 9 1") `shouldBe` ["1 2 3 4","5 6 7 8", "9 1"]
38− it "wrapWithOffsetAndAlignment" $ do
39− wrapWithOffsetAndAlignment TextAlignment_Left 5 0 someSentence `shouldBe` [(WrappedLine "12345" True 0), (WrappedLine "1234" True 0), (WrappedLine "12" False 0)]
40− wrapWithOffsetAndAlignment TextAlignment_Right 5 0 someSentence `shouldBe` [(WrappedLine "12345" True 0), (WrappedLine "1234" True 1), (WrappedLine "12" False 3)]
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)]
43− it "eolSpacesToLogicalLines" $ do
44− eolSpacesToLogicalLines
45− [
46− [ (WrappedLine "😱" True 1), (WrappedLine "😱" False 2), (WrappedLine "😱" False 3) ]
47− , [ (WrappedLine "aa" True 1), (WrappedLine "aa" True 2), (WrappedLine "aa" False 3) ]
48− ]
49− `shouldBe`
50− [
51− [ ("😱",1) ]
52− , [ ("😱",2), ("😱",3) ]
53− , [ ("aa",1) ]
54− , [ ("aa",2) ]
55− , [ ("aa",3) ]
56− ]
57− it "offsetMapWithAlignmentInternal" $ do
58− offsetMapWithAlignmentInternal
59− [
60− [ (WrappedLine "😱" True 1), (WrappedLine "😱" False 2), (WrappedLine "😱" False 3) ]
61− , [ (WrappedLine "aa" True 1), (WrappedLine "aa" True 2), (WrappedLine "aa" False 3) ]
62− ]
63− `shouldBe`
64− Map.fromList
65− [ (0, (1,0))
66− , (1, (2,2)) -- jump by 1 for char and 1 for space
67− , (2, (3,3)) -- jump by 1 for char
68− , (3, (1,5)) -- jump by 1 for char and 1 for newline
69− , (4, (2,8)) -- jump by 2 for char and 1 for space
70− , (5, (3,11)) -- jump by 2 for char and 1 for space
71− ]
72− it "displayLines - cursorPos" $ do
73− let
74− dl0 = displayLinesWithAlignment TextAlignment_Right 10 () () (fromText "")
75− dl1 = displayLinesWithAlignment TextAlignment_Right 10 () () (fromText "aoeu")
76− dl2 = displayLinesWithAlignment TextAlignment_Right 10 () () (fromText "aoeu\n")
77− dl3 = displayLinesWithAlignment TextAlignment_Right 10 () () (fromText "0123456789")
78− dl4 = displayLinesWithAlignment TextAlignment_Right 10 () () (insertChar 'a' $ fromText "aoeu")
79− dl5 = displayLinesWithAlignment TextAlignment_Right 10 () () (left $ insertChar 'a' $ fromText "aoeu")
80− dl6 = displayLinesWithAlignment TextAlignment_Right 10 () () (deleteLeft $ insertChar 'a' $ fromText "aoeu")
81− _displayLines_cursorPos dl0 `shouldBe` (0,0)
82− _displayLines_cursorPos dl1 `shouldBe` (4,0)
83− _displayLines_cursorPos dl2 `shouldBe` (0,1)
84− _displayLines_cursorPos dl3 `shouldBe` (0,1)
85− _displayLines_cursorPos dl4 `shouldBe` (5,0)
86− _displayLines_cursorPos dl5 `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
26+ it "wordsWithWhitespace" $ do
27+ wordsWithWhitespace "" `shouldBe` []
28+ wordsWithWhitespace "😱😱😱" `shouldBe` ["😱😱😱"]
29+ wordsWithWhitespace "abcd efgf f" `shouldBe` ["abcd ","efgf ", "f"]
30+ wordsWithWhitespace "aoeu " `shouldBe` ["aoeu "]
31+ it "splitWordsAtDisplayWidth" $ do
32+ fmap fst (splitSentenceAtDisplayWidth 5 "123456") `shouldBe` ["12345","6"]
33+ fmap fst (splitSentenceAtDisplayWidth 5 "12345 6") `shouldBe` ["12345","6"]
34+ fmap fst (splitSentenceAtDisplayWidth 5 "1234 56") `shouldBe` ["1234","56"]
35+ fmap fst (splitSentenceAtDisplayWidth 5 "12345678912345") `shouldBe` ["12345","67891","2345"]
36+ fmap fst (splitSentenceAtDisplayWidth 5 "1234 56") `shouldBe` ["1234 "," 56"]
37+ fmap fst (splitSentenceAtDisplayWidth 8 "1 2 3 4 5 6 7 8 9 1") `shouldBe` ["1 2 3 4","5 6 7 8", "9 1"]
38+ it "wrapWithOffsetAndAlignment" $ do
39+ wrapWithOffsetAndAlignment TextAlignment_Left 5 0 someSentence `shouldBe` [(WrappedLine "12345" True 0), (WrappedLine "1234" True 0), (WrappedLine "12" False 0)]
40+ wrapWithOffsetAndAlignment TextAlignment_Right 5 0 someSentence `shouldBe` [(WrappedLine "12345" True 0), (WrappedLine "1234" True 1), (WrappedLine "12" False 3)]
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)]
43+ it "eolSpacesToLogicalLines" $ do
44+ eolSpacesToLogicalLines
45+ [
46+ [ (WrappedLine "😱" True 1), (WrappedLine "😱" False 2), (WrappedLine "😱" False 3) ]
47+ , [ (WrappedLine "aa" True 1), (WrappedLine "aa" True 2), (WrappedLine "aa" False 3) ]
48+ ]
49+ `shouldBe`
50+ [
51+ [ ("😱",1) ]
52+ , [ ("😱",2), ("😱",3) ]
53+ , [ ("aa",1) ]
54+ , [ ("aa",2) ]
55+ , [ ("aa",3) ]
56+ ]
57+ it "offsetMapWithAlignmentInternal" $ do
58+ offsetMapWithAlignmentInternal
59+ [
60+ [ (WrappedLine "😱" True 1), (WrappedLine "😱" False 2), (WrappedLine "😱" False 3) ]
61+ , [ (WrappedLine "aa" True 1), (WrappedLine "aa" True 2), (WrappedLine "aa" False 3) ]
62+ ]
63+ `shouldBe`
64+ Map.fromList
65+ [ (0, (1,0))
66+ , (1, (2,2)) -- jump by 1 for char and 1 for space
67+ , (2, (3,3)) -- jump by 1 for char
68+ , (3, (1,5)) -- jump by 1 for char and 1 for newline
69+ , (4, (2,8)) -- jump by 2 for char and 1 for space
70+ , (5, (3,11)) -- jump by 2 for char and 1 for space
71+ ]
72+ it "displayLines - cursorPos" $ do
73+ let
74+ dl0 = displayLinesWithAlignment TextAlignment_Right 10 () () (fromText "")
75+ dl1 = displayLinesWithAlignment TextAlignment_Right 10 () () (fromText "aoeu")
76+ dl2 = displayLinesWithAlignment TextAlignment_Right 10 () () (fromText "aoeu\n")
77+ dl3 = displayLinesWithAlignment TextAlignment_Right 10 () () (fromText "0123456789")
78+ dl4 = displayLinesWithAlignment TextAlignment_Right 10 () () (insertChar 'a' $ fromText "aoeu")
79+ dl5 = displayLinesWithAlignment TextAlignment_Right 10 () () (left $ insertChar 'a' $ fromText "aoeu")
80+ dl6 = displayLinesWithAlignment TextAlignment_Right 10 () () (deleteLeft $ insertChar 'a' $ fromText "aoeu")
81+ _displayLines_cursorPos dl0 `shouldBe` (0,0)
82+ _displayLines_cursorPos dl1 `shouldBe` (4,0)
83+ _displayLines_cursorPos dl2 `shouldBe` (0,1)
84+ _displayLines_cursorPos dl3 `shouldBe` (0,1)
85+ _displayLines_cursorPos dl4 `shouldBe` (5,0)
86+ _displayLines_cursorPos dl5 `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+ let t = rightN x $ someText
95+ length (_displayLines_spans $ (displayLinesWithAlignment ta 5 () () t)) `shouldBe` 4
96+ length (_displayLines_spans $ (displayLinesWithAlignment ta 10 () () t)) `shouldBe` 2