diff --git a/lib/cucumber/core/gherkin/tag_expression.rb b/lib/cucumber/core/gherkin/tag_expression.rb deleted file mode 100644 index aa23cf8e..00000000 --- a/lib/cucumber/core/gherkin/tag_expression.rb +++ /dev/null @@ -1,65 +0,0 @@ -# frozen_string_literal: true -module Cucumber -module Core -module Gherkin - class TagExpression - - attr_reader :limits - - def initialize(tag_expressions) - @ands = [] - @limits = {} - tag_expressions.each do |expr| - add(expr.strip.split(/\s*,\s*/)) - end - end - - def empty? - @ands.empty? - end - - def evaluate(tags) - return true if @ands.flatten.empty? - vars = Hash[*tags.map{|tag| [tag.name, true]}.flatten] - raise "No vars" if vars.nil? # Useless statement to prevent ruby warnings about unused var - !!Kernel.eval(ruby_expression) - end - - private - - def add(tags_with_negation_and_limits) - negatives, positives = tags_with_negation_and_limits.partition{|tag| tag =~ /^~/} - @ands << (store_and_extract_limits(negatives, true) + store_and_extract_limits(positives, false)) - end - - def store_and_extract_limits(tags_with_negation_and_limits, negated) - tags_with_negation = [] - tags_with_negation_and_limits.each do |tag_with_negation_and_limit| - tag_with_negation, limit = tag_with_negation_and_limit.split(':') - tags_with_negation << tag_with_negation - if limit - tag_without_negation = negated ? tag_with_negation[1..-1] : tag_with_negation - if @limits[tag_without_negation] && @limits[tag_without_negation] != limit.to_i - raise "Inconsistent tag limits for #{tag_without_negation}: #{@limits[tag_without_negation]} and #{limit.to_i}" - end - @limits[tag_without_negation] = limit.to_i - end - end - tags_with_negation - end - - def ruby_expression - "(" + @ands.map do |ors| - ors.map do |tag| - if tag =~ /^~(.*)/ - "!vars['#{$1}']" - else - "vars['#{tag}']" - end - end.join("||") - end.join(")&&(") + ")" - end - end -end -end -end diff --git a/lib/cucumber/core/test/case.rb b/lib/cucumber/core/test/case.rb index e6783bb5..e0f75e41 100644 --- a/lib/cucumber/core/test/case.rb +++ b/lib/cucumber/core/test/case.rb @@ -2,7 +2,6 @@ require 'cucumber/core/test/result' require 'cucumber/tag_expressions' -require 'cucumber/core/gherkin/tag_expression' module Cucumber module Core @@ -82,15 +81,7 @@ def compose_around_hooks(visitor, *args, &block) end def match_single_tag_expression?(expression) - if old_style_tag_expression?(expression) - Cucumber::Core::Gherkin::TagExpression.new([expression]).evaluate(tags) - else - Cucumber::TagExpressions::Parser.new.parse(expression).evaluate(tags.map(&:name)) - end - end - - def old_style_tag_expression?(expression) - expression.include?(',') || expression.include?('~') + Cucumber::TagExpressions::Parser.new.parse(expression).evaluate(tags.map(&:name)) end end end diff --git a/spec/cucumber/core/test/case_spec.rb b/spec/cucumber/core/test/case_spec.rb index 403d04d0..867a98e3 100644 --- a/spec/cucumber/core/test/case_spec.rb +++ b/spec/cucumber/core/test/case_spec.rb @@ -83,21 +83,6 @@ module Test end end - describe "matching tags (old style)" do - let(:tags) { ['@a', '@b', '@c'].map { |value| Tag.new(location, value) } } - - it "matches boolean expressions of tags" do - expect( test_case.match_tags?(['@a', '@b']) ).to be_truthy - expect( test_case.match_tags?(['@a, @d']) ).to be_truthy - expect( test_case.match_tags?(['~@d']) ).to be_truthy - expect( test_case.match_tags?(['@a', '@d']) ).to be_falsy - end - - it "handles mixing old and new style expressions" do - expect( test_case.match_tags?(['@a and @b', '~@d']) ).to be_truthy - end - end - describe "matching names" do let(:name) { 'scenario' } it "matches names against regexp" do