This repository has been archived by the owner on Jan 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#83. Adding tests for generator exceptions
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:f_orm_m8_sqlite/orm_m8_generator.dart'; | ||
import 'package:source_gen/source_gen.dart'; | ||
import 'package:test/test.dart'; | ||
import 'utils/test_file_utils.dart'; | ||
import 'package:source_gen_test/source_gen_test.dart'; | ||
|
||
void main() { | ||
LibraryReader library_1; | ||
LibraryReader library_2; | ||
final path = testFilePath('test', 'src', 'model'); | ||
|
||
setUp(() async { | ||
library_1 = await initializeLibraryReaderForDirectory( | ||
path, "bad_nondbentity_probe.dart"); | ||
library_2 = await initializeLibraryReaderForDirectory( | ||
path, "bad_no_datatable_annotation_probe.dart"); | ||
}); | ||
|
||
group('Exceptions tests', () { | ||
final generator = OrmM8GeneratorForAnnotation(); | ||
|
||
test('Test Database models must implement DbEntity', () async { | ||
String v = await generator.generate(library_1, null); | ||
|
||
expect( | ||
v.contains( | ||
'''/*\nException: Database models must implement `DbEntity` interface!'''), | ||
true); | ||
}); | ||
|
||
test( | ||
'Test the DbEntity implementations must be annotated with `@DataTable`!', | ||
() async { | ||
String v = await generator.generate(library_2, null); | ||
|
||
expect( | ||
v.contains( | ||
'''/*\nException: The DbEntity implementations must be annotated with `@DataTable`!'''), | ||
true); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:f_orm_m8/f_orm_m8.dart'; | ||
|
||
// we do not allow the users to extends the Framework | ||
class DataTableExtension extends DataTable { | ||
const DataTableExtension(); | ||
} | ||
|
||
// exact @DataTable("my_bad_table") requirement is replaced with a user extension | ||
@DataTableExtension() | ||
class BadNonDbEntityProbe implements DbEntity { | ||
@DataColumn("my_id_column", | ||
metadataLevel: ColumnMetadata.primaryKey | | ||
ColumnMetadata.unique | | ||
ColumnMetadata.autoIncrement) | ||
int id; | ||
|
||
@DataColumn("my_description_column", metadataLevel: ColumnMetadata.unique) | ||
String description; | ||
|
||
@DataColumn("my_future_column", | ||
metadataLevel: ColumnMetadata.ignore | ColumnMetadata.unique) | ||
int futureData; | ||
|
||
@DataColumn("my_account_id_column", metadataLevel: ColumnMetadata.notNull) | ||
int accountId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:f_orm_m8/f_orm_m8.dart'; | ||
|
||
@DataTable("my_bad_table") | ||
class BadNonDbEntityProbe { | ||
@DataColumn("my_id_column", | ||
metadataLevel: ColumnMetadata.primaryKey | | ||
ColumnMetadata.unique | | ||
ColumnMetadata.autoIncrement) | ||
int id; | ||
|
||
@DataColumn("my_description_column", metadataLevel: ColumnMetadata.unique) | ||
String description; | ||
|
||
@DataColumn("my_future_column", | ||
metadataLevel: ColumnMetadata.ignore | ColumnMetadata.unique) | ||
int futureData; | ||
|
||
@DataColumn("my_account_id_column", metadataLevel: ColumnMetadata.notNull) | ||
int accountId; | ||
} |