Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add versions of 'htmlAnyContain', 'htmlAllContain', 'htmlNoneContain' which match strings verbatim #1786

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

eahlberg
Copy link
Contributor

@eahlberg eahlberg commented Oct 11, 2022

Fixes #1784

Before submitting your PR, check that you've:

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

@@ -204,6 +204,9 @@ module Yesod.Test
, htmlAllContain
, htmlAnyContain
, htmlNoneContain
, htmlAllContainPreEscaped
, htmlAnyContainPreEscaped
, htmlNoneContainPreEscaped
Copy link
Contributor Author

@eahlberg eahlberg Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

html*PreEscaped preferable to e.g. html*ContainRaw? PreEscaped was used since that's what it's called in the Blaze docs.

@@ -201,6 +201,9 @@ main = hspec $ do
yit "finding html" $ do
get ("/html" :: Text)
statusIs 200
htmlAnyContainPreEscaped "meta" "content=\"site description\""
htmlAllContainPreEscaped "meta" "content=\"site description"
Copy link
Contributor Author

@eahlberg eahlberg Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice if there are more concise examples than this but I couldn't come up with any

case matches of
[] -> failure $ "Nothing matched css query: " <> query
_ -> liftIO $ HUnit.assertBool ("Not all "++T.unpack query++" contain "++search ++ " matches: " ++ show matches) $
DL.all (DL.isInfixOf search) (map (TL.unpack . decodeUtf8) matches)
Copy link
Contributor Author

@eahlberg eahlberg Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for the escaping, this is the exact same code as htmlAllContain, should we refactor this?

@eahlberg eahlberg force-pushed the html-contain-match-raw-string branch from 03184b6 to 9b44e8c Compare October 12, 2022 08:06
@@ -201,6 +201,9 @@ main = hspec $ do
yit "finding html" $ do
get ("/html" :: Text)
statusIs 200
htmlAnyContainPreEscaped "meta" "content=\"site description\""
htmlAllContainPreEscaped "meta" "content=\"site description"
htmlNoneContainPreEscaped "meta" "foobar"
Copy link
Contributor Author

@eahlberg eahlberg Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks absence in the same was as the test for htmlNoneContain, I think it'd be better with a test case which illustrates the difference between the two functions.

@eahlberg eahlberg marked this pull request as ready for review October 12, 2022 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[yesod-test] bring back support for matching of preescaped strings
1 participant