A unit test for the target parser.

master
vi 2014-08-11 00:38:16 +08:00
parent d86284f09e
commit 809cca61b7
2 changed files with 25 additions and 1 deletions

View File

@ -1,9 +1,13 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Data.HTTPSEverywhere.Rules.Internal.Parser (
parseRuleSets
parseRuleSets,
#ifdef TEST
parseTarget
#endif
) where
import Prelude hiding (head, last, tail, init)

View File

@ -0,0 +1,20 @@
{-# LANGUAGE OverloadedStrings #-}
module Data.HTTPSEverywhere.Rules.Internal.ParserSpec (
spec
) where
import Data.HTTPSEverywhere.Rules.Internal.Types (Target(..))
import Data.HTTPSEverywhere.Rules.Internal.Parser (parseTarget)
import Test.Hspec (Spec, describe, it, shouldBe)
spec :: Spec
spec = do
describe "parseTarget" $ do
let parseTarget' = \target domain -> ($ domain) . getTarget $ parseTarget target
it "*.facebook.com should match s-static.ak.facebook.com" $ do
parseTarget' "*.facebook.com" "s-static.ak.facebook.com" `shouldBe` True
it "google.* should match google.com.id" $ do
parseTarget' "google.*" "google.com.id" `shouldBe` True
it "*.google.* should not match google.com.id" $ do
parseTarget' "*.google.*" "google.com.id" `shouldBe` False