scenarioExampleCaseAt function

ScenarioExampleCase scenarioExampleCaseAt(
  1. GherkinScenario scenario, {
  2. required int examplesIndex,
  3. required int rowIndex,
})

Resolves one executable case and validates its indexes.

Implementation

ScenarioExampleCase scenarioExampleCaseAt(
  GherkinScenario scenario, {
  required int examplesIndex,
  required int rowIndex,
}) {
  if (scenario.examples.isEmpty) {
    if (examplesIndex != 0 || rowIndex != 0) {
      throw RangeError(
        'A scenario without Examples only has case indexes 0, 0.',
      );
    }
    return const ScenarioExampleCase(
      examplesIndex: 0,
      rowIndex: 0,
      displayLabel: '',
      values: <String, String>{},
    );
  }

  if (examplesIndex < 0 || examplesIndex >= scenario.examples.length) {
    throw RangeError.index(examplesIndex, scenario.examples, 'examplesIndex');
  }
  final examples = scenario.examples[examplesIndex];
  if (rowIndex < 0 || rowIndex >= examples.rows.length) {
    throw RangeError.index(rowIndex, examples.rows, 'rowIndex');
  }
  return ScenarioExampleCase(
    examplesIndex: examplesIndex,
    rowIndex: rowIndex,
    displayLabel: _exampleDisplayLabel(examples, examplesIndex, rowIndex),
    values: Map.unmodifiable(
      Map<String, String>.fromIterables(
        examples.headers,
        examples.rows[rowIndex],
      ),
    ),
  );
}