A
B
C
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Text.HTML.Scalpel.Core
import Control.Applicative
import Control.Monad (guard)
import Data.List (isInfixOf)
import System.Exit (ExitCode(..), exitSuccess, exitWith)
import Test.HUnit (Test(..), (@=?), (~:), runTestTT, failures)
import qualified Text.HTML.TagSoup as TagSoup
import qualified Text.Regex.TDFA
main :: IO ()
main = do
n <- runTestTT (TestList [scrapeTests])
exit $ failures n
exit :: Int -> IO ()
exit 0 = exitSuccess
exit n = exitWith $ ExitFailure n
re :: String -> Text.Regex.TDFA.Regex
re = Text.Regex.TDFA.makeRegex
scrapeTests = "scrapeTests" ~: TestList [
scrapeTest
"htmls should extract matching tag"
"foo"
(Just ["foo"])
(htmls ("a" @: []))
, scrapeTest
"htmls should ignore non-matching tag"
"foobar"
(Just ["foo", "bar"])
(htmls ("a" @: []))
, scrapeTest
"htmls should extract matching tag when it is nested"
"foo"
(Just ["foo"])
(htmls ("a" @: []))
, scrapeTest
"htmls should extract each matching tag even if it is nested"
"foo"
(Just ["foo", "foo"])
(htmls ("a" @: []))
, scrapeTest
"htmls with no matching nodes should result in an empty list"
"foo"
(Just [])
(htmls ("b" @: []))
, scrapeTest
"unclosed tags should be treated as immediately closed"
"foo"
(Just [""])
(htmls ("a" @: []))
, scrapeTest
"scraping should obey attribute predicates"
"foobar"
(Just ["bar"])
(htmls ("a" @: ["key" @= "value"]))
, scrapeTest
"selectors using // should match the deepest node"
"
A
B
C
A
B
C
p1
p2
p3
p4
" (Just ["p1", "p2", "p3", "p4"]) (texts "p") , scrapeTest "DFS regression test for #59 (2)" "123" (Just ["1","2","3"]) (texts "a") , scrapeTest "DFS regression test for #59 (3)" "123" (Just ["1","2","3"]) (texts $ "a" // "b") , scrapeTest "DFS regression test for #59 (4)" "123" (Just ["1","2","3"]) (texts "b") , scrapeTest "atDepth 1 should select immediate children" "1Here
Other stuff that matters
" (Just "Other stuff that matters") (inSerial $ do seekNext $ matches $ "p" @: [hasClass "something"] stepNext $ text "p") , scrapeTest "Issue #45 regression test" (unlines [ "" , "text 1
" , "text 2
" , "text 3
" , "