1 {-# LANGUAGE OverloadedStrings #-}
5 import Control.Exception (evaluate)
8 import Data.Text (Text)
9 import Data.Hastext.Parsers.Occurrences (parse)
11 main = print "hspec $ do
12 describe "Parser for occurrences" $ do
16 it "returns the result of one parsing" $ do
17 parse "internet" "internet" `shouldBe` Right ((txt, 1) :: (Text, Int))
19 -- | Context of Text should be toLower
20 it "returns the result of one parsing not case sensitive" $ do
21 let txtCase = "Internet"
22 parse txtCase "internet" `shouldBe` Right ((txtCase, 1) :: (Text, Int))
24 it "returns the result of one parsing after space" $ do
26 `shouldBe` Right ((txt, 1) :: (Text, Int))
28 it "returns the result of one parsing after chars" $ do
29 parse txt "l'internet"
30 `shouldBe` (Right ((txt, 1) :: (Text, Int)))
32 it "returns the result of multiple parsing" $ do
33 parse txt "internet internet of things"
34 `shouldBe` (Right ((txt, 2) :: (Text, Int)))
36 it "returns the result of multiple parsing separated by text" $ do
37 parse txt "internet in the internet of things"
38 `shouldBe` (Right ((txt, 2) :: (Text, Int)))
40 it "returns the result of multiple parsing separated by punctuation" $ do
41 parse txt "internet. In the internet of things, internet like; internet?"
42 `shouldBe` (Right ((txt, 4) :: (Text, Int)))