buuka/test/Test/Data/Query.hs

40 lines
1.3 KiB
Haskell
Raw Permalink Normal View History

2021-01-02 09:09:38 +02:00
module Test.Data.Query where
import Test.Tasty
2021-01-02 09:17:29 +02:00
import Test.Tasty.HUnit
import Data.Buuka
(BuukaEntry(..), URL(..))
import Data.Functor.Foldable
(cata)
import Data.Query
test_startswith :: Assertion
test_startswith = do
let entry = BuukaEntry (URL "http://example.com") (Just "foo")
cata evaluate (startsWith Url "http://") entry @?= True
cata evaluate (startsWith Url "https://") entry @?= False
cata evaluate (startsWith Title "foo") entry @?= True
cata evaluate (startsWith Title "bar") entry @?= False
test_endswith :: Assertion
test_endswith = do
let entry = BuukaEntry (URL "http://example.com") (Just "foo")
cata evaluate (endsWith Url "com") entry @?= True
cata evaluate (endsWith Url "fi") entry @?= False
cata evaluate (endsWith Title "foo") entry @?= True
cata evaluate (endsWith Title "bar") entry @?= False
test_and :: Assertion
test_and = do
let entry = BuukaEntry (URL "http://example.com") (Just "foo")
cata evaluate (startsWith Url "http://" .&&. endsWith Url ".com") entry @?= True
cata evaluate (startsWith Url "http://" .&&. endsWith Url ".fi") entry @?= False
2021-01-02 09:09:38 +02:00
tests :: TestTree
2021-01-02 09:17:29 +02:00
tests = testGroup "Data.Query"
[ testCase "Queries startsWith" test_startswith
, testCase "Queries endsWith" test_endswith
, testCase "Queries and" test_and
]