• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import 'package:collection/collection.dart';
2
3class AssertionException implements Exception {
4  AssertionException(this.check, [this.message]);
5
6  final String check;
7  final String message;
8
9  @override
10  String toString() {
11    if (message == null) return 'AssertionException.${check}';
12    return 'AssertionException.${check}: $message';
13  }
14}
15
16void assertTrue(bool val, [String message]) {
17  if (!val) {
18    throw AssertionException('assertTrue', message);
19  }
20}
21
22void assertFalse(bool val, [String message]) {
23  if (val) {
24    throw AssertionException('assertFalse', message);
25  }
26}
27
28void assertEqual(var v1, var v2, [String message]) {
29  if (v1 != v2) {
30    throw AssertionException('assertEqual', message);
31  }
32}
33
34void assertIdentical(var v1, var v2, [String message]) {
35  if (!identical(v1, v2)) {
36    throw AssertionException('assertIdentical', message);
37  }
38}
39
40void assertNotIdentical(var v1, var v2, [String message]) {
41  if (identical(v1, v2)) {
42    throw AssertionException('assertNotIdentical', message);
43  }
44}
45
46void assertDeepEqual(var v1, var v2, [bool unordered = true, String message]) {
47  final deepEq = unordered
48      ? const DeepCollectionEquality.unordered().equals
49      : const DeepCollectionEquality().equals;
50  if (!deepEq(v1, v2)) {
51    throw AssertionException('assertDeepEquals', message);
52  }
53}
54
55void assertDeepNotEqual(var v1, var v2, [bool unordered = true, String message]) {
56  final deepEq = unordered
57      ? const DeepCollectionEquality.unordered().equals
58      : const DeepCollectionEquality().equals;
59  if (deepEq(v1, v2)) {
60    throw AssertionException('assertNotDeepEquals', message);
61  }
62}
63
64void assertNotEqual(var v1, var v2, [String message]) {
65  if (v1 == v2) {
66    throw AssertionException('assertNotEquals', message);
67  }
68}
69
70void assertNotNull(var v1, [String message]) {
71  if (v1 == null) {
72    throw AssertionException('assertNotNull', message);
73  }
74}
75
76void assertNull(var v1, [String message]) {
77  if (v1 != null) {
78    throw AssertionException('assertNull', message);
79  }
80}
81
82