mirror of https://github.com/AMT-Cheif/drift.git
parent
256b91f03f
commit
f0e5ed9a87
|
@ -49,4 +49,16 @@ mixin TableInfo<TableDsl extends Table, D extends DataClass> {
|
|||
D map(Map<String, dynamic> data, {String tablePrefix});
|
||||
|
||||
TableInfo<TableDsl, D> createAlias(String alias);
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
// tables are singleton instances except for aliases
|
||||
if (other is TableInfo) {
|
||||
return other.runtimeType == runtimeType && other.$tableName == $tableName;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => $mrjf($mrjc(runtimeType.hashCode, $tableName.hashCode));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
import 'package:test_api/test_api.dart';
|
||||
|
||||
import 'data/tables/todos.dart';
|
||||
import 'data/utils/mocks.dart';
|
||||
|
||||
void main() {
|
||||
TodoDb db;
|
||||
MockExecutor executor;
|
||||
|
||||
setUp(() {
|
||||
executor = MockExecutor();
|
||||
db = TodoDb(executor);
|
||||
});
|
||||
|
||||
test('aliased tables implement equals correctly', () {
|
||||
final first = db.users;
|
||||
final aliasA = db.alias(db.users, 'a');
|
||||
final anotherA = db.alias(db.categories, 'a');
|
||||
|
||||
expect(first == aliasA, isFalse);
|
||||
// ignore: unrelated_type_equality_checks
|
||||
expect(anotherA == aliasA, isFalse);
|
||||
expect(aliasA == db.alias(db.users, 'a'), isTrue);
|
||||
});
|
||||
|
||||
test('aliased table implement hashCode correctly', () {
|
||||
final first = db.users;
|
||||
final aliasA = db.alias(db.users, 'a');
|
||||
final anotherA = db.alias(db.categories, 'a');
|
||||
|
||||
expect(first.hashCode == aliasA.hashCode, isFalse);
|
||||
expect(anotherA.hashCode == aliasA.hashCode, isFalse);
|
||||
expect(aliasA.hashCode == db.alias(db.users, 'a').hashCode, isTrue);
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue