elm-html-test icon indicating copy to clipboard operation
elm-html-test copied to clipboard

Regex matching for text

Open eeue56 opened this issue 7 years ago • 2 comments

I found myself in the situation where I'd like to be able to match against part of a string within a text field.

For example:

https://github.com/terezka/line-charts/pull/38/files#diff-c75cfaadb0c1fe89dc19f42360af0317R91

In this case, the "10" part of the UI doesn't actually matter: what does matter is the "Age"

eeue56 avatar Feb 17 '18 10:02 eeue56

Makes sense to me! I'm familiar with this use case from Capybara tests.

What about this for an API?

textMatching : (String -> Bool) -> Selector

textContaining : String -> Selector

The former is maximally flexible - you could use regex, or a helper function, or Parser, or anything else.

The latter would be the most common application of that function. (So you wouldn't have to say textMatching (Sting.contains "Age") all the time.)

rtfeldman avatar Feb 18 '18 02:02 rtfeldman

I just realized that my proposed textContaining is actually how text currently works.

This means it's not currently possible to search for (for example) an empty text node, e.g. text "" doesn't do anything useful.

This seems like a useful distinction to make!

rtfeldman avatar Feb 18 '18 19:02 rtfeldman