Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
#83. Adding tests for generator exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
matei-tm committed May 6, 2019
1 parent 614e7e1 commit ec6cace
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/test/exceptions_test.dart
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);
});
});
}
26 changes: 26 additions & 0 deletions src/test/src/model/bad_no_datatable_annotation_probe.dart
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;
}
20 changes: 20 additions & 0 deletions src/test/src/model/bad_nondbentity_probe.dart
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;
}

0 comments on commit ec6cace

Please sign in to comment.