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

Commit

Permalink
#8. Preparing tests for the entity writer
Browse files Browse the repository at this point in the history
  • Loading branch information
matei-tm committed Mar 14, 2019
1 parent f4948cb commit 0277540
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/test/flutter_sqlite_m8_generator_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:flutter_orm_m8/flutter_orm_m8.dart';
import 'package:flutter_sqlite_m8_generator/generator/core.dart';
import 'package:flutter_sqlite_m8_generator/orm_m8_generator.dart';
import 'package:source_gen/source_gen.dart';
import 'package:test/test.dart';
Expand All @@ -17,5 +19,30 @@ void main() async {
final expected = "/*\nInstance of 'EntityWriter'\n*/";
expect(output, expected);
});

test('Missing test annotation', () async {
expect(
() => getEmittedEntityForAnnotation(
"this_test_annotation_does_not_exists"),
throwsA(const TypeMatcher<StateError>()));
});

test('OK test annotation', () async {
var e = getEmittedEntityForAnnotation("my_health_entries_table");
expect(e.entityName, "my_health_entries_table");
});
});
}

EmittedEntity getEmittedEntityForAnnotation(String testAnnotation) {
var annotatedElement = _library
.annotatedWith(TypeChecker.fromRuntime(DataTable))
.firstWhere((f) =>
f.annotation.objectValue.getField('name').toStringValue() ==
testAnnotation);

var entityName =
annotatedElement.annotation.objectValue.getField('name').toStringValue();

return ModelParser(annotatedElement.element, entityName).getEmittedEntity();
}

0 comments on commit 0277540

Please sign in to comment.