Tests for query
This commit is contained in:
		@@ -84,6 +84,7 @@ test-suite buuka-test
 | 
				
			|||||||
                     , hedgehog
 | 
					                     , hedgehog
 | 
				
			||||||
                     , hedgehog-corpus
 | 
					                     , hedgehog-corpus
 | 
				
			||||||
                     , tasty-hedgehog
 | 
					                     , tasty-hedgehog
 | 
				
			||||||
 | 
					                     , tasty-hunit
 | 
				
			||||||
                     , tasty
 | 
					                     , tasty
 | 
				
			||||||
                     , text
 | 
					                     , text
 | 
				
			||||||
                     , aeson
 | 
					                     , aeson
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
{ mkDerivation, aeson, base, bytestring, containers, exceptions
 | 
					{ mkDerivation, aeson, base, bytestring, containers, exceptions
 | 
				
			||||||
, filepath, hashable, hashids, hedgehog, hedgehog-corpus, lens, mtl
 | 
					, filepath, hashable, hashids, hedgehog, hedgehog-corpus, lens, mtl
 | 
				
			||||||
, optparse-applicative, stdenv, tasty, tasty-hedgehog, text
 | 
					, optparse-applicative, stdenv, tasty, tasty-hedgehog, tasty-hunit
 | 
				
			||||||
, transformers, unliftio, vector, yaml
 | 
					, text, transformers, unliftio, vector, yaml
 | 
				
			||||||
}:
 | 
					}:
 | 
				
			||||||
mkDerivation {
 | 
					mkDerivation {
 | 
				
			||||||
  pname = "buuka";
 | 
					  pname = "buuka";
 | 
				
			||||||
@@ -15,7 +15,8 @@ mkDerivation {
 | 
				
			|||||||
  ];
 | 
					  ];
 | 
				
			||||||
  executableHaskellDepends = [ base optparse-applicative unliftio ];
 | 
					  executableHaskellDepends = [ base optparse-applicative unliftio ];
 | 
				
			||||||
  testHaskellDepends = [
 | 
					  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;
 | 
					  license = stdenv.lib.licenses.bsd3;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,8 +2,11 @@
 | 
				
			|||||||
{-# LANGUAGE LambdaCase #-}
 | 
					{-# LANGUAGE LambdaCase #-}
 | 
				
			||||||
module Data.Query
 | 
					module Data.Query
 | 
				
			||||||
  (
 | 
					  (
 | 
				
			||||||
 | 
					    -- * AST
 | 
				
			||||||
 | 
					    Field(..)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    -- * Combinators
 | 
					    -- * Combinators
 | 
				
			||||||
    startsWith
 | 
					  , startsWith
 | 
				
			||||||
  , endsWith
 | 
					  , endsWith
 | 
				
			||||||
  , (.&&.)
 | 
					  , (.&&.)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,39 @@
 | 
				
			|||||||
module Test.Data.Query where
 | 
					module Test.Data.Query where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Test.Tasty
 | 
					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 :: TestTree
 | 
				
			||||||
tests = testGroup "Data.Query" []
 | 
					tests = testGroup "Data.Query"
 | 
				
			||||||
 | 
					  [ testCase "Queries startsWith" test_startswith
 | 
				
			||||||
 | 
					  , testCase "Queries endsWith" test_endswith
 | 
				
			||||||
 | 
					  , testCase "Queries and" test_and
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user