blob: 411562eea6bbd2eb32d50cd72e96c274e8668fd9 [file] [log] [blame]
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:checks/checks.dart';
import 'package:test/scaffolding.dart';
import '../test_shared.dart';
void main() {
group('TypeChecks', () {
test('isA', () {
checkThat(1).isA<int>();
checkThat(1).isRejectedBy(it()..isA<String>(), which: ['Is a int']);
});
});
group('HasField', () {
test('has', () {
checkThat(1).has((v) => v.isOdd, 'isOdd').isTrue();
checkThat(2).isRejectedBy(
it()..has((v) => throw UnimplementedError(), 'isOdd'),
which: ['threw while trying to read property']);
});
test('which', () {
checkThat(true).which(it()..isTrue());
});
test('not', () {
checkThat(false).not(it()..isTrue());
checkThat(true).isRejectedBy(it()..not(it()..isTrue()), which: [
'is a value that: ',
' is true',
]);
});
group('anyOf', () {
test('succeeds for happy case', () {
checkThat(-10).anyOf([it()..isGreaterThan(1), it()..isLessThan(-1)]);
});
test('rejects values that do not satisfy any condition', () {
checkThat(0).isRejectedBy(
it()..anyOf([it()..isGreaterThan(1), it()..isLessThan(-1)]),
which: ['did not match any condition']);
});
});
});
group('BoolChecks', () {
test('isTrue', () {
checkThat(true).isTrue();
checkThat(false).isRejectedBy(it()..isTrue());
});
test('isFalse', () {
checkThat(false).isFalse();
checkThat(true).isRejectedBy(it()..isFalse());
});
});
group('EqualityChecks', () {
test('equals', () {
checkThat(1).equals(1);
checkThat(1).isRejectedBy(equals(2), which: ['are not equal']);
});
test('identical', () {
checkThat(1).identicalTo(1);
checkThat(1)
.isRejectedBy(it()..identicalTo(2), which: ['is not identical']);
});
});
group('NullabilityChecks', () {
test('isNotNull', () {
checkThat(1).isNotNull();
checkThat(null).isRejectedBy(it()..isNotNull());
});
test('isNull', () {
checkThat(null).isNull();
checkThat(1).isRejectedBy(it()..isNull());
});
});
}