1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Ignore negative text requirements when extracting strings from regexps

This commit is contained in:
Thomas Walpole 2019-07-24 08:25:48 -07:00
parent 7e2d19bde1
commit f1139a5985
2 changed files with 17 additions and 0 deletions

View file

@ -100,6 +100,8 @@ module Capybara
def extract_strings(process_alternatives) def extract_strings(process_alternatives)
strings = [] strings = []
each do |exp| each do |exp|
next if exp.ignore?
next strings.push(nil) if exp.optional? && !process_alternatives next strings.push(nil) if exp.optional? && !process_alternatives
next strings.push(exp.alternative_strings) if exp.alternation? && process_alternatives next strings.push(exp.alternative_strings) if exp.alternation? && process_alternatives
@ -159,6 +161,11 @@ module Capybara
alts.all?(&:any?) ? Set.new(alts) : nil alts.all?(&:any?) ? Set.new(alts) : nil
end end
def ignore?
[Regexp::Expression::Assertion::NegativeLookahead,
Regexp::Expression::Assertion::NegativeLookbehind].any? { |klass| @exp.is_a? klass }
end
private private
def indeterminate? def indeterminate?

View file

@ -212,6 +212,16 @@ RSpec.describe Capybara::Selector::RegexpDisassembler, :aggregate_failures do
) )
end end
it 'ignores negative lookaheads' do
verify_strings(
/^(?!.*\bContributing Editor\b).*$/ => %w[],
/abc(?!.*def).*/ => %w[abc],
/(?!.*def)abc/ => %w[abc],
/abc(?!.*def.*).*ghi/ => %w[abc ghi],
/abc(?!.*bcd)def/ => %w[abcdef]
)
end
it 'handles anchors' do it 'handles anchors' do
verify_strings( verify_strings(
/^abc/ => %w[abc], /^abc/ => %w[abc],