every method

void every(
  1. Condition<T> elementCondition
)

Expects there are no elements in the iterable which fail to satisfy elementCondition.

Empty iterables will pass always pass this expectation.

Implementation

void every(Condition<T> elementCondition) {
  context.expect(() {
    final conditionDescription = describe(elementCondition);
    assert(conditionDescription.isNotEmpty);
    return [
      'only has values that:',
      ...conditionDescription,
    ];
  }, (actual) {
    final iterator = actual.iterator;
    for (var i = 0; iterator.moveNext(); i++) {
      final element = iterator.current;
      final failure = softCheck(element, elementCondition);
      if (failure == null) continue;
      final which = failure.rejection.which;
      return Rejection(which: [
        'has an element at index $i that:',
        ...indent(failure.detail.actual.skip(1)),
        ...indent(prefixFirst('Actual: ', failure.rejection.actual),
            failure.detail.depth + 1),
        if (which != null && which.isNotEmpty)
          ...indent(prefixFirst('Which: ', which), failure.detail.depth + 1),
      ]);
    }
    return null;
  });
}