File: Features.hs

package info (click to toggle)
haskell-text-builder-core 0.1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 96 kB
  • sloc: haskell: 738; makefile: 3
file content (76 lines) | stat: -rw-r--r-- 2,463 bytes parent folder | download
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
module Features (tests) where

import Control.Monad
import Data.Char
import Data.String
import qualified Data.Text as Text
import qualified Data.Text.Lazy as Text.Lazy
import Test.QuickCheck.Instances ()
import Test.Tasty
import Test.Tasty.QuickCheck
import TextBuilderCore
import Util.TestTrees
import Prelude

tests :: [TestTree]
tests =
  [ testGroup "isEmpty" $
      [ testProperty "Is True for empty string" $
          isEmpty (fromString ""),
        testProperty "Is True for mempty" $
          isEmpty (fromString mempty),
        testProperty "Is True for (mempty <> mempty)" $
          isEmpty (fromString (mempty <> mempty)),
        testProperty "Is isomorphic to Text.null" $ \a ->
          isEmpty (text a) === Text.null a
      ],
    testGroup "toText" $
      [ mapsToMonoid toText,
        testProperty "Roundtrips" \textValue ->
          toText (text textValue) === textValue
      ],
    testGroup "string" $
      [ mapsToMonoid string,
        testProperty "Roundtrips" \builder ->
          string (Text.unpack (toText builder)) === builder
      ],
    testGroup "text" $
      [ mapsToMonoid text,
        testProperty "Roundtrips" \builder ->
          text (toText builder) === builder
      ],
    testGroup "lazyText" $
      [ mapsToMonoid lazyText,
        testProperty "Roundtrips" \builder ->
          lazyText (Text.Lazy.fromStrict (toText builder)) === builder
      ],
    testGroup "char" $
      [ mapsToMonoid char,
        testProperty "Is isomorphic to Text.singleton" \a ->
          toText (char a) === Text.singleton a
      ],
    testGroup "unicodeCodepoint" $
      [ mapsToMonoid unicodeCodepoint,
        testProperty "Is isomorphic to Text.singleton" \a ->
          toText (unicodeCodepoint (ord a)) === Text.singleton a
      ],
    testGroup "unsafeSeptets" $
      [ isMonoidWithCustomGen do
          maxGenSize <- getSize
          maxSize <- chooseInt (0, maxGenSize)
          actualSize <- chooseInt (0, maxSize)
          septets <-
            replicateM actualSize $
              fromIntegral <$> chooseInt (0, 127)
          pure (unsafeSeptets maxSize septets)
      ],
    testGroup "unsafeReverseSeptets" $
      [ isMonoidWithCustomGen do
          maxGenSize <- getSize
          maxSize <- chooseInt (0, maxGenSize)
          septets <-
            replicateM maxSize $
              fromIntegral <$> chooseInt (0, 127)
          pure (unsafeReverseSeptets maxSize septets)
      ]
  ]