Skip to content

Commit

Permalink
Tests: switch from pcre-light to regex-tdfa
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Dec 14, 2024
1 parent 7d61d98 commit 157f42c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
2 changes: 1 addition & 1 deletion quickcheck/tasty-quickcheck.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ test-suite test
test.hs
build-depends:
base >= 4.7 && < 5
, regex-tdfa >= 1.3 && < 1.4
, tasty >= 1.5
, tasty-quickcheck
, tasty-hunit
, pcre-light
, QuickCheck
ghc-options: -Wall
if (!impl(ghc >= 8.0) || os(windows))
Expand Down
16 changes: 3 additions & 13 deletions quickcheck/tests/test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import Test.Tasty.Providers as Tasty
import Test.Tasty.Runners as Tasty
import Test.Tasty.QuickCheck
import Test.Tasty.HUnit
import Data.Maybe
import Test.QuickCheck.Random (QCGen)
import Text.Regex.PCRE.Light.Char8
import Text.Printf
import qualified Text.Regex.TDFA as Regex

(=~), (!~)
:: String -- ^ text
Expand All @@ -21,20 +20,11 @@ text =~ regexStr =
msg = printf "Expected /%s/, got %s" regexStr (show text)
-- NB show above the intentional -- to add quotes around the string and
-- escape newlines etc.
in assertBool msg $ match' text regexStr
in assertBool msg $ text Regex.=~ regexStr
text !~ regexStr =
let
msg = printf "Did not expect /%s/, got %s" regexStr (show text)
in assertBool msg $ not $ match' text regexStr

-- note: the order of arguments is reversed relative to match from
-- pcre-light, but consistent with =~ and !~
match' :: String -> String -> Bool
match' text regexStr =
let
regex = compile regexStr []
in
isJust $ match regex text []
in assertBool msg $ not $ text Regex.=~ regexStr

main :: IO ()
main =
Expand Down

0 comments on commit 157f42c

Please sign in to comment.