Sha256: f6045156dcca157e2c36d23fa5f260c68090120ede0f67471a07f9dfb61d9548

Contents?: true

Size: 1.87 KB

Versions: 7

Compression:

Stored size: 1.87 KB

Contents

require 'cucumber/tag_expressions/parser'

describe Cucumber::TagExpressions::Parser do
  correct_test_data = [
    ['a and b', '( a and b )'],
    ['a or (b)', '( a or b )'],
    ['not   a', 'not ( a )'],
    ['( a and b ) or ( c and d )', '( ( a and b ) or ( c and d ) )'],
    ['not a or b and not c or not d or e and f',
     '( ( ( not ( a ) or ( b and not ( c ) ) ) or not ( d ) ) or ( e and f ) )'],
    ['not a\\(\\) or b and not c or not d or e and f',
     '( ( ( not ( a\\(\\) ) or ( b and not ( c ) ) ) or not ( d ) ) or ( e and f ) )'],
     ['a\\\\ and b', '( a\\\\ and b )'],
     ['\\a and b\\ and c\\', '( ( a and b ) and c )'],
     ['(a and b\\\\)', '( a and b\\\\ )'],
     ['a\\\\\\( and b\\\\\\)', '( a\\\\\\( and b\\\\\\) )']
  ]

  error_test_data = [
    ['@a @b or', 'Syntax error. Expected operator'],
    ['@a and (@b not)', 'Syntax error. Expected operator'],
    ['@a and (@b @c) or', 'Syntax error. Expected operator'],
    ['@a and or', 'Syntax error. Expected operand'],
    ['or or', 'Syntax error. Expected operand'],
    ['a b', 'Syntax error. Expected operator'],
    ['( a and b ) )', 'Syntax error. Unmatched )'],
    ['( ( a and b )', 'Syntax error. Unmatched ('],
  ]

  context '#parse' do
    context 'with correct test data' do
      correct_test_data.each do |infix_expression, to_string|
        parser = Cucumber::TagExpressions::Parser.new
        it "parses correctly #{infix_expression.inspect}" do
          expect(parser.parse(infix_expression).to_s).to eq(to_string)
        end
      end
    end

    context 'with error test data' do
      error_test_data.each do |infix_expression, message|
        parser = Cucumber::TagExpressions::Parser.new
        it "raises an error parsing #{infix_expression.inspect}" do
          expect { parser.parse(infix_expression) }
            .to raise_error(RuntimeError, message)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 4 rubygems

Version Path
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-tag-expressions-4.1.0/spec/parser_spec.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-tag-expressions-4.1.0/spec/parser_spec.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-tag-expressions-4.1.0/spec/parser_spec.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-tag-expressions-4.1.0/spec/parser_spec.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-tag-expressions-4.1.0/spec/parser_spec.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/cucumber-tag-expressions-4.1.0/spec/parser_spec.rb
cucumber-tag-expressions-4.1.0 spec/parser_spec.rb