| 1 |
-------------------------------------------------------------------------------- |
| 2 |
module Hakyll.Core.Util.String.Tests |
| 3 |
( tests |
| 4 |
) where |
| 5 |
|
| 6 |
|
| 7 |
-------------------------------------------------------------------------------- |
| 8 |
import Test.Tasty (TestTree, testGroup) |
| 9 |
import Test.Tasty.HUnit ((@=?)) |
| 10 |
|
| 11 |
|
| 12 |
-------------------------------------------------------------------------------- |
| 13 |
import Hakyll.Core.Util.String |
| 14 |
import TestSuite.Util |
| 15 |
|
| 16 |
|
| 17 |
-------------------------------------------------------------------------------- |
| 18 |
tests :: TestTree |
| 19 |
tests = testGroup "Hakyll.Core.Util.String.Tests" $ concat |
| 20 |
[ fromAssertions "trim" |
| 21 |
[ "foo" @=? trim " foo\n\t " |
| 22 |
] |
| 23 |
|
| 24 |
, fromAssertions "replaceAll" |
| 25 |
[ "foo-end" @=? replaceAll "begin" (const "foo") "begin-end" |
| 26 |
, "begin-foo" @=? replaceAll "end" (const "foo") "begin-end" |
| 27 |
, "no match" @=? replaceAll "abc" (const "foo") "no match" |
| 28 |
, "foo" @=? replaceAll ".*" (const "foo") "full match" |
| 29 |
, "empty pattern" @=? replaceAll "" (const "foo") "empty pattern" |
| 30 |
, "" @=? replaceAll "empty input" (const "foo") "" |
| 31 |
, "32 & 131" @=? replaceAll "0x[0-9]+" (show . readInt) "0x20 & 0x83" |
| 32 |
] |
| 33 |
|
| 34 |
, fromAssertions "splitAll" |
| 35 |
[ ["a", "b", "c"] @=? splitAll "," "a,,b,,,c,," |
| 36 |
, ["abc", "def"] @=? splitAll "[0-9]+" "abc123def456" |
| 37 |
, ["no match"] @=? splitAll "," "no match" |
| 38 |
, [] @=? splitAll ".*" "full match" |
| 39 |
, ["empty pattern"] @=? splitAll "" "empty pattern" |
| 40 |
, [] @=? splitAll "empty input" "" |
| 41 |
, ["λ", "∀x.x", "hi"] @=? splitAll ", *" "λ, ∀x.x, hi" |
| 42 |
] |
| 43 |
|
| 44 |
, fromAssertions "needlePrefix" |
| 45 |
[ Just "ab" @=? needlePrefix "cd" "abcde" |
| 46 |
, Just "xx" @=? needlePrefix "ab" "xxab" |
| 47 |
, Nothing @=? needlePrefix "a" "xx" |
| 48 |
, Just "x" @=? needlePrefix "ab" "xabxab" |
| 49 |
, Just "" @=? needlePrefix "ab" "abc" |
| 50 |
, Just "" @=? needlePrefix "ab" "abab" |
| 51 |
, Nothing @=? needlePrefix "" "" |
| 52 |
] |
| 53 |
] |
| 54 |
|
| 55 |
where |
| 56 |
readInt :: String -> Int |
| 57 |
readInt = read |