summaryrefslogtreecommitdiff
path: root/tests/Hakyll/Core/Util/String/Tests.hs
blob: e9c27ae8cddf67daae20a1e204da14c299d55023 (plain)
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
--------------------------------------------------------------------------------
module Hakyll.Core.Util.String.Tests
    ( tests
    ) where


--------------------------------------------------------------------------------
import           Test.Tasty              (TestTree, testGroup)
import           Test.Tasty.HUnit        ((@=?))


--------------------------------------------------------------------------------
import           Hakyll.Core.Util.String
import           TestSuite.Util


--------------------------------------------------------------------------------
tests :: TestTree
tests = testGroup "Hakyll.Core.Util.String.Tests" $ concat
    [ fromAssertions "trim"
        [ "foo" @=? trim " foo\n\t "
        ]

    , fromAssertions "replaceAll"
        [ "32 & 131" @=? replaceAll "0x[0-9]+" (show . readInt) "0x20 & 0x83"
        ]

    , fromAssertions "splitAll"
        [ ["λ", "∀x.x", "hi"] @=? splitAll ", *" "λ, ∀x.x,  hi"
        ]

    , fromAssertions "needlePrefix"
        [ Just "ab" @=? needlePrefix "cd" "abcde"
        , Just "xx" @=? needlePrefix "ab" "xxab"
        , Nothing   @=? needlePrefix "a" "xx"
        , Just "x"  @=? needlePrefix "ab" "xabxab"
        , Just ""   @=? needlePrefix "ab" "abc"
        , Just ""   @=? needlePrefix "ab" "abab"
        , Nothing   @=? needlePrefix "" ""
        ]
    ]

  where
    readInt :: String -> Int
    readInt = read