From 3c1ea67566cc4b0ebaff6d6bed28a2677b868a66 Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Sat, 2 Jan 2021 09:17:29 +0200 Subject: [PATCH] Tests for query --- buuka.cabal | 1 + default.nix | 7 ++++--- src/Data/Query.hs | 5 ++++- test/Test/Data/Query.hs | 35 ++++++++++++++++++++++++++++++++++- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/buuka.cabal b/buuka.cabal index 29280b0..546a572 100644 --- a/buuka.cabal +++ b/buuka.cabal @@ -84,6 +84,7 @@ test-suite buuka-test , hedgehog , hedgehog-corpus , tasty-hedgehog + , tasty-hunit , tasty , text , aeson diff --git a/default.nix b/default.nix index f3e216c..51a4e9b 100644 --- a/default.nix +++ b/default.nix @@ -1,7 +1,7 @@ { mkDerivation, aeson, base, bytestring, containers, exceptions , filepath, hashable, hashids, hedgehog, hedgehog-corpus, lens, mtl -, optparse-applicative, stdenv, tasty, tasty-hedgehog, text -, transformers, unliftio, vector, yaml +, optparse-applicative, stdenv, tasty, tasty-hedgehog, tasty-hunit +, text, transformers, unliftio, vector, yaml }: mkDerivation { pname = "buuka"; @@ -15,7 +15,8 @@ mkDerivation { ]; executableHaskellDepends = [ base optparse-applicative unliftio ]; testHaskellDepends = [ - aeson base hedgehog hedgehog-corpus tasty tasty-hedgehog text + aeson base hedgehog hedgehog-corpus tasty tasty-hedgehog + tasty-hunit text ]; license = stdenv.lib.licenses.bsd3; } diff --git a/src/Data/Query.hs b/src/Data/Query.hs index 47a925f..7d8b2e3 100644 --- a/src/Data/Query.hs +++ b/src/Data/Query.hs @@ -2,8 +2,11 @@ {-# LANGUAGE LambdaCase #-} module Data.Query ( + -- * AST + Field(..) + -- * Combinators - startsWith + , startsWith , endsWith , (.&&.) diff --git a/test/Test/Data/Query.hs b/test/Test/Data/Query.hs index 4f8bd12..8fbb602 100644 --- a/test/Test/Data/Query.hs +++ b/test/Test/Data/Query.hs @@ -1,6 +1,39 @@ module Test.Data.Query where import Test.Tasty +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 tests :: TestTree -tests = testGroup "Data.Query" [] +tests = testGroup "Data.Query" + [ testCase "Queries startsWith" test_startswith + , testCase "Queries endsWith" test_endswith + , testCase "Queries and" test_and + ]