Skip to content

Commit

Permalink
Document softCheckHideNull
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy committed Dec 25, 2023
1 parent c35db85 commit ea1d983
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/src/checks/checks_nullability.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ extension HideNullableSubject<T> on Subject<T?> {
}
}

/// Like [softCheck] but ignores isNotNull() errors when the actual value is null
///
/// Workaround allowing to use
/// `hasProp((subject)=> subject.equals(X));`
/// instead of
Expand All @@ -38,15 +40,14 @@ CheckFailure? softCheckHideNull<T>(T value, Condition<T> condition) {
final failure = softCheck(value, condition);
if (failure == null) {
return null;
} else {
final errorParts = describe(condition).map((it) => it.trim()).toList();
final errorMessage = errorParts.join(' ');
if (errorParts.last == 'is null' &&
failure.rejection.actual.firstOrNull == '<null>') {
// property is null and isNull() was called
// not error because null == null
return null;
}
return failure;
}
final errorParts = describe(condition).map((it) => it.trim()).toList();
final errorMessage = errorParts.join(' ');
if (errorParts.last == 'is null' &&
failure.rejection.actual.firstOrNull == '<null>') {
// property is null and isNull() was called
// not error because null == null
return null;
}
return failure;
}

0 comments on commit ea1d983

Please sign in to comment.