From ff7d587339044dbf57148424c269d4cee43dd0e5 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 11 Oct 2019 22:03:32 +0200 Subject: [PATCH] Add real-world example for table inheritance to test --- .../test/analyzer/dart/table_parser_test.dart | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/moor_generator/test/analyzer/dart/table_parser_test.dart b/moor_generator/test/analyzer/dart/table_parser_test.dart index 876e21bf..475da1f0 100644 --- a/moor_generator/test/analyzer/dart/table_parser_test.dart +++ b/moor_generator/test/analyzer/dart/table_parser_test.dart @@ -55,6 +55,16 @@ void main() { class Foos extends HasNameTable with IntIdTable { TextColumn get name => text().nullable()(); } + + class Socks extends Table { + TextColumn get name => text()(); + IntColumn get id => integer().autoIncrement()(); + } + + class ArchivedSocks extends Socks { + TextColumn get archivedBy => text()(); + DateTimeColumn get archivedOn => dateTime()(); + } ''' }); }); @@ -156,10 +166,25 @@ void main() { expect(table.columns.any((column) => column.hasAI), isFalse); }); - test('handles inheritance in column definitions', () async { - final table = await parse('Foos'); + group('inheritance', () { + test('from abstract classes or mixins', () async { + final table = await parse('Foos'); - expect(table.columns, hasLength(2)); - expect(table.columns.map((c) => c.name.name), containsAll(['id', 'name'])); + expect(table.columns, hasLength(2)); + expect( + table.columns.map((c) => c.name.name), containsAll(['id', 'name'])); + }); + + test('from regular classes', () async { + final socks = await parse('Socks'); + final archivedSocks = await parse('ArchivedSocks'); + + expect(socks.columns, hasLength(2)); + expect(socks.columns.map((c) => c.name.name), ['name', 'id']); + + expect(archivedSocks.columns, hasLength(4)); + expect(archivedSocks.columns.map((c) => c.name.name), + ['name', 'id', 'archived_by', 'archived_on']); + }); }); }