checks: String add length, is(Not)Empty, startsWith, endsWith
diff --git a/pkgs/checks/lib/src/extensions/core.dart b/pkgs/checks/lib/src/extensions/core.dart
index 8c6955d..2fe29a2 100644
--- a/pkgs/checks/lib/src/extensions/core.dart
+++ b/pkgs/checks/lib/src/extensions/core.dart
@@ -118,4 +118,46 @@
actual: literal(actual), which: ['Does not contain $pattern']);
});
}
+
+ Check<int> get length => has((m) => m.length, 'length');
+
+ void isEmpty() {
+ context.expect(() => const ['is empty'], (actual) {
+ if (actual.isEmpty) return null;
+ return Rejection(actual: literal(actual), which: ['is not empty']);
+ });
+ }
+
+ void isNotEmpty() {
+ context.expect(() => const ['is not empty'], (actual) {
+ if (actual.isNotEmpty) return null;
+ return Rejection(actual: literal(actual), which: ['is empty']);
+ });
+ }
+
+ void startsWith(String other) {
+ context.expect(
+ () => ['starts with ${literal(other)}'],
+ (actual) {
+ if (actual.startsWith(other)) return null;
+ return Rejection(
+ actual: literal(actual),
+ which: ['does not start with ${literal(other)}'],
+ );
+ },
+ );
+ }
+
+ void endsWith(String other) {
+ context.expect(
+ () => ['ends with ${literal(other)}'],
+ (actual) {
+ if (actual.endsWith(other)) return null;
+ return Rejection(
+ actual: literal(actual),
+ which: ['does not end with ${literal(other)}'],
+ );
+ },
+ );
+ }
}