diff --git a/drift/lib/src/runtime/data_class.dart b/drift/lib/src/runtime/data_class.dart index 5acff306..fd45ded1 100644 --- a/drift/lib/src/runtime/data_class.dart +++ b/drift/lib/src/runtime/data_class.dart @@ -158,7 +158,7 @@ class Value { const Value.ofNullable(T? value) : assert( value != null || null is! T, - "Value.absentIfNull(null) can't be used for a nullable T, since the " + "Value.ofNullable(null) can't be used for a nullable T, since the " 'null value could be both absent and present.', ), _value = value, diff --git a/sqlparser/lib/src/utils/ast_equality.dart b/sqlparser/lib/src/utils/ast_equality.dart index 284095fa..b341c36b 100644 --- a/sqlparser/lib/src/utils/ast_equality.dart +++ b/sqlparser/lib/src/utils/ast_equality.dart @@ -10,12 +10,17 @@ void enforceEqualIterable(Iterable a, Iterable b) { final childrenA = a.iterator; final childrenB = b.iterator; + var movedA = false; + var movedB = false; + // always move both iterators - while (childrenA.moveNext() & childrenB.moveNext()) { + // need to store the result so it can be compared afterwards + // since it does not get reverted if only one moved + while ((movedA = childrenA.moveNext()) & (movedB = childrenB.moveNext())) { enforceEqual(childrenA.current, childrenB.current); } - if (childrenA.moveNext() || childrenB.moveNext()) { + if (movedA || movedB) { throw ArgumentError("$a and $b don't have an equal amount of children"); } } diff --git a/sqlparser/test/utils/ast_quality_test.dart b/sqlparser/test/utils/ast_quality_test.dart new file mode 100644 index 00000000..07117ebc --- /dev/null +++ b/sqlparser/test/utils/ast_quality_test.dart @@ -0,0 +1,73 @@ +import 'package:sqlparser/sqlparser.dart'; +import 'package:sqlparser/src/utils/ast_equality.dart'; +import 'package:test/expect.dart'; +import 'package:test/scaffolding.dart'; + +void main() { + group(enforceEqualIterable, () { + test('should accept 2 equal iterables', () { + enforceEqualIterable( + [ + NotNull('foo'), + ], + [ + NotNull('foo'), + ], + ); + }); + + test('should throw if only first is empty', () { + expect( + () => enforceEqualIterable( + [], + [ + NotNull('foo'), + ], + ), + throwsA(isA()), + ); + }); + + test('should throw if only second is empty', () { + expect( + () => enforceEqualIterable( + [ + NotNull('foo'), + ], + [], + ), + throwsA(isA()), + ); + }); + + test('should throw if first is shorter', () { + expect( + () => enforceEqualIterable( + [ + NotNull('foo'), + ], + [ + NotNull('foo'), + UniqueColumn('foo', null), + ], + ), + throwsA(isA()), + ); + }); + + test('should throw if second is shorter', () { + expect( + () => enforceEqualIterable( + [ + NotNull('foo'), + UniqueColumn('foo', null), + ], + [ + NotNull('foo'), + ], + ), + throwsA(isA()), + ); + }); + }); +}