jonsamwell/dart_gherkin

Custom parameter for type List<int> is causing RangeError exception

josechagas opened this issue · 1 comments

Exception

Shell: RangeError (index): Invalid value: Not in inclusive range 0..4: 5
Shell: RangeError (index): Invalid value: Not in inclusive range 0..4: 5
Shell: RangeError (index): Invalid value: Not in inclusive range 0..4: 5

Custom parameter definition

class ListIntParameter extends CustomParameter<List<int>> {
  ListIntParameter()
      : super('listInt', RegExp(r'(\[(\d+(\,\d)*)*\]){1}', caseSensitive: false), (value) {
          print('1 - aqui:'+value);
          final result = value.replaceAll(RegExp(r'\[|\]'), '').split(',')
              .map(
                (e) => int.tryParse(e),
          )
              .whereNotNull()
              .toList(
            growable: false,
          );
          print(result);
          return result;
        });
}

Step definition

class GivenUserEntersTheInformations extends Given5WithWorld<String, String,
    String, List<int>, String, MyWorld> {
  @override
  Future<void> executeStep(
    String primaryPosition,
    String secondaryPosition,
    String preferredFieldSide,
    List<int> skillsIds,
    String favoriteFoot,
  ) async {
    // TODO: implement executeStep
    throw UnimplementedError();
  }

  @override
  Pattern get pattern => RegExp(
        r'User enters the informations {string}, {string}, {string}, {listInt}, {string}',
      );
}