<commit_before>Feature: Parameter types

  Users can define their own parameter types to be used in Cucumber expressions.
  Custom parameter types can be used to match certain patterns, and optionally to
  transform the matched value into a custom type.

  Background:
    Given a file named "features/particular_steps.feature" with:
      """
      Feature: a feature
        Scenario: a scenario
          Given a particular step
      """
    Given a file named "features/step_definitions/my_steps.js" with:
      """
      import assert from 'assert'
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({Given}) => {
        Given('a {param} step', function(param) {
          assert.equal(param, 'PARTICULAR')
        })
      })
      """

  Scenario: sync transform (success)
    Given a file named "features/support/transforms.js" with:
      """
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({defineParameterType}) => {
        defineParameterType({
          regexp: /particular/,
          transformer: s => s.toUpperCase(),
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then the step "a particular step" has status "passed"

  Scenario: sync transform (success) using deprecated addTransform API
    Given a file named "features/support/transforms.js" with:
      """
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({addTransform}) => {
        addTransform({
          captureGroupRegexps: /particular/,
          transformer: s => s.toUpperCase(),
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then the step "a particular step" has status "passed"

  Scenario: sync transform (error)
    Given a file named "features/support/transforms.js" with:
      """
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({defineParameterType}) => {
        defineParameterType({
          regexp: /particular/,
          transformer: s => {
            throw new Error('transform error')
          },
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then it fails
    And the step "a particular step" failed with:
      """
      transform error
      """

  Scenario: no transform
    Given a file named "features/support/transforms.js" with:
      """
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({defineParameterType}) => {
        defineParameterType({
          regexp: /particular/,
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then it fails
    And the step "a particular step" failed with:
      """
      AssertionError: 'particular' == 'PARTICULAR'
      """

  Scenario: async transform (success)
    Given a file named "features/step_definitions/particular_steps.js" with:
      """
      import {defineSupportCode} from 'cucumber'
      import Promise from 'bluebird'

      defineSupportCode(({defineParameterType}) => {
        defineParameterType({
          regexp: /particular/,
          transformer: s => Promise.resolve(s.toUpperCase()),
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then the step "a particular step" has status "passed"

  Scenario: async transform (error)
    Given a file named "features/step_definitions/particular_steps.js" with:
      """
      import {defineSupportCode} from 'cucumber'
      import Promise from 'bluebird'

      defineSupportCode(({defineParameterType}) => {
        defineParameterType({
          regexp: /particular/,
          transformer: s => Promise.reject(new Error('transform error')),
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then it fails
    And the step "a particular step" failed with:
      """
      transform error
      """<commit_msg>parameter type: duplicate regex (#780)<commit_after>Feature: Parameter types

  Users can define their own parameter types to be used in Cucumber expressions.
  Custom parameter types can be used to match certain patterns, and optionally to
  transform the matched value into a custom type.

  Background:
    Given a file named "features/particular_steps.feature" with:
      """
      Feature: a feature
        Scenario: a scenario
          Given a particular step
      """
    Given a file named "features/step_definitions/my_steps.js" with:
      """
      import assert from 'assert'
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({Given}) => {
        Given('a {param} step', function(param) {
          assert.equal(param, 'PARTICULAR')
        })
      })
      """

  Scenario: sync transform (success)
    Given a file named "features/support/transforms.js" with:
      """
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({defineParameterType}) => {
        defineParameterType({
          regexp: /particular/,
          transformer: s => s.toUpperCase(),
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then the step "a particular step" has status "passed"

  Scenario: sync transform (success) using deprecated addTransform API
    Given a file named "features/support/transforms.js" with:
      """
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({addTransform}) => {
        addTransform({
          captureGroupRegexps: /particular/,
          transformer: s => s.toUpperCase(),
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then the step "a particular step" has status "passed"

  Scenario: sync transform (error)
    Given a file named "features/support/transforms.js" with:
      """
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({defineParameterType}) => {
        defineParameterType({
          regexp: /particular/,
          transformer: s => {
            throw new Error('transform error')
          },
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then it fails
    And the step "a particular step" failed with:
      """
      transform error
      """

  Scenario: no transform
    Given a file named "features/support/transforms.js" with:
      """
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({defineParameterType}) => {
        defineParameterType({
          regexp: /particular/,
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then it fails
    And the step "a particular step" failed with:
      """
      AssertionError: 'particular' == 'PARTICULAR'
      """

  Scenario: async transform (success)
    Given a file named "features/step_definitions/particular_steps.js" with:
      """
      import {defineSupportCode} from 'cucumber'
      import Promise from 'bluebird'

      defineSupportCode(({defineParameterType}) => {
        defineParameterType({
          regexp: /particular/,
          transformer: s => Promise.resolve(s.toUpperCase()),
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then the step "a particular step" has status "passed"

  Scenario: async transform (error)
    Given a file named "features/step_definitions/particular_steps.js" with:
      """
      import {defineSupportCode} from 'cucumber'
      import Promise from 'bluebird'

      defineSupportCode(({defineParameterType}) => {
        defineParameterType({
          regexp: /particular/,
          transformer: s => Promise.reject(new Error('transform error')),
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then it fails
    And the step "a particular step" failed with:
      """
      transform error
      """

  Scenario: duplicate capture group regex
    Given a file named "features/support/my_parameter_types.js" with:
      """
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({defineParameterType, When}) => {
        defineParameterType({
          regexp: /"[^"]+"/,
          transformer: JSON.parse,
          typeName: 'stringInDoubleQuotes2'
        })
      })
      """
    When I run cucumber.js with `-f progress`
    Then the output contains the text:
      """
      There is already a parameter with regexp "[^"]+"
      """
    And it fails
{'fraction_non_alphanumeric': 0.10458214624881292, 'fraction_numerical': 0.0004748338081671415, 'mean_word_length': 2.305217732444096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1188467', 'n_tokens_mistral': 2318, 'n_tokens_neox': 2235, 'n_words': 684}