hcat/test/spec/HCatSpec.hs
Alexander Kobjolke 10057518cb Implement a status line
The status line shows information about the shown file, such as size,
modification time and permissions.
2023-09-10 11:36:35 +02:00

45 lines
1.6 KiB
Haskell

module HCatSpec (spec) where
import HCat.Internal
import HCat.Screen
import Test.Hspec
import Test.Hspec.QuickCheck (prop)
import Test.QuickCheck (Positive (getPositive), getNonPositive)
import Test.QuickCheck.Instances.Text ()
spec :: Spec
spec = do
describe "parseArgs" do
it "returns the filename if given a single argument" do
parseArgs ["foo"] `shouldBe` Right "foo"
parseArgs [] `shouldBe` Left "No filename given!"
parseArgs ["foo", "bar"] `shouldBe` Left "Only a single file is supported"
describe "chunksOf" $ do
prop "each chunk contains at most N items" $ \n xs ->
let chunkLengths = length <$> chunksOf n (xs :: [Int])
in case chunkLengths of
[] -> pure ()
ns -> maximum ns `shouldSatisfy` (<= n)
prop "the sum of all lengths is equal to the length of the input" $ \n xs ->
let chunkLengths = length <$> chunksOf (getPositive n) (xs :: [Int])
in sum chunkLengths `shouldBe` length xs
describe "wordWrap" do
prop "non positive margins result in empty result" $ \margin ->
wordWrap (getNonPositive margin) "abc" `shouldBe` ["abc"]
it "wraps the given text at the given margin" do
wordWrap 4 "abc" `shouldBe` ["abc"]
wordWrap 4 "abcdefg" `shouldBe` ["abcd", "efg"]
prop "concatenating the result equals the input" $ \txt ->
let wrapped = wordWrap 4 txt
in mconcat wrapped `shouldBe` txt
describe "paginate" do
it "wraps the given text at the given margin" do
paginate (ScreenDimensions 3 2) "abcdefghijkl" `shouldBe` ["ab\ncd\nef\n", "gh\nij\nkl\n"]