File: BuilderSpec.hs

package info (click to toggle)
haskell-text-show 3.10.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,148 kB
  • sloc: haskell: 8,817; ansic: 23; makefile: 6
file content (55 lines) | stat: -rw-r--r-- 1,875 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{-|
Module:      Spec.BuilderSpec
Copyright:   (C) 2014-2017 Ryan Scott
License:     BSD-style (see the file LICENSE)
Maintainer:  Ryan Scott
Stability:   Provisional
Portability: GHC

@hspec@ tests for functions that manipulate 'Builder's.
-}
module Spec.BuilderSpec (main, spec) where

import Instances.Data.Text ()

import Test.Hspec (Expectation, Spec, describe, hspec, parallel, shouldBe)
import Test.Hspec.QuickCheck (prop)

import TextShow (Builder, fromString, fromText, lengthB,
                       toString, toText, unlinesB, unwordsB)

main :: IO ()
main = hspec spec

-- | Verifies 'lengthB' and 'length' produce the same output.
prop_lengthB :: String -> Expectation
prop_lengthB s = fromIntegral (lengthB $ fromString s) `shouldBe` length s

-- | Verifies @fromText . toText = id@.
prop_toText :: Builder -> Expectation
prop_toText b = fromText (toText b) `shouldBe` b

-- | Verifies @fromString . toString = id@.
prop_toString :: Builder -> Expectation
prop_toString b = fromString (toString b) `shouldBe` b

-- | Verifies 'unlinesB' and 'unlines' produce the same output.
prop_unlinesB :: [String] -> Expectation
prop_unlinesB strs = unlinesB (map fromString strs) `shouldBe` fromString (unlines strs)

-- | Verifies 'unwordsB' and 'unwords' produce the same output.
prop_unwordsB :: [String] -> Expectation
prop_unwordsB strs = unwordsB (map fromString strs) `shouldBe` fromString (unwords strs)

spec :: Spec
spec = parallel $ do
    describe "lengthB" $
        prop "has the same output as length"  prop_lengthB
    describe "toString" $
        prop "fromString . toString = id"     prop_toString
    describe "toText" $
        prop "fromText . toText = id"         prop_toText
    describe "unlinesB" $
        prop "has the same output as unlines" prop_unlinesB
    describe "unwordsB" $
        prop "has the same output as unwords" prop_unwordsB