{-# LANGUAGE FlexibleInstances, OverloadedStrings #-} module Main where import Control.Applicative import Test.Framework (defaultMain, testGroup, Test) import Test.Framework.Providers.HUnit import Test.Framework.Providers.QuickCheck2 import Test.HUnit hiding (Test) import Test.QuickCheck import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as S import qualified Data.Conduit as C import qualified Data.Conduit.List as CL import Text.HTML.TagStream main :: IO () main = defaultMain [ testGroup "Property" [ testProperty "Text nodes can't be empty" propTextNotEmpty , testProperty "Parse results can't empty" propResultNotEmpty ] , testGroup "One pass parse" onePassTests , testGroup "Streamline parse" streamlineTests ] propTextNotEmpty :: ByteString -> Bool propTextNotEmpty = either (const False) text_not_empty . decode where text_not_empty = all not_empty not_empty (Text s) = S.length s > 0 not_empty _ = True propResultNotEmpty :: ByteString -> Bool propResultNotEmpty s = either (const False) not_empty . decode $ s where not_empty tokens = (S.null s && null tokens) || (not (S.null s) && not (null tokens)) onePassTests :: [Test] onePassTests = map one testcases where one (str, tokens) = testCase (S.unpack str) $ do result <- combineText <$> assertDecode str assertEqual "one-pass parse result incorrect" tokens result streamlineTests :: [Test] streamlineTests = map one testcases where isIncomplete (Incomplete _) = True isIncomplete _ = False one (str, tokens) = testCase (S.unpack str) $ do -- streamline parse result don't contain the trailing Incomplete token. let tokens' = reverse . dropWhile isIncomplete . reverse $ tokens result <- combineText <$> C.runResourceT ( CL.sourceList (map S.singleton (S.unpack str)) C.$= tokenStream C.$$ CL.consume ) assertEqual "streamline parse result incorrect" tokens' result testcases :: [(ByteString, [Token])] testcases = -- attributes {{{ [ ( "