diff --git a/src/Data/HTTPSEverywhere/Rules/Internal/Parser.hs b/src/Data/HTTPSEverywhere/Rules/Internal/Parser.hs index debacc7..3a63232 100644 --- a/src/Data/HTTPSEverywhere/Rules/Internal/Parser.hs +++ b/src/Data/HTTPSEverywhere/Rules/Internal/Parser.hs @@ -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) diff --git a/test/Data/HTTPSEverywhere/Rules/Internal/ParserSpec.hs b/test/Data/HTTPSEverywhere/Rules/Internal/ParserSpec.hs new file mode 100644 index 0000000..c143280 --- /dev/null +++ b/test/Data/HTTPSEverywhere/Rules/Internal/ParserSpec.hs @@ -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