Future<String>
generateForAnnotatedElement(Element element, EmbedTests annotation, BuildStep buildStep)
Source
@override
Future<String> generateForAnnotatedElement(
Element element, EmbedTests annotation, BuildStep buildStep) async {
if (path.isAbsolute(annotation.path)) {
throw new Exception('must be relative path to the source file');
}
final String sourcePathDir = path.dirname(buildStep.input.id.path);
final String filePath = path.join(sourcePathDir, annotation.path);
if (!await FileSystemEntity.isFile(filePath)) {
throw new Exception('Not a file! - $filePath');
}
final Map<String, String> content = _readFile(filePath);
String result =
'final Map<String, String> _\$${element.displayName}Tests = '
'<String, String>{\n';
content.forEach((String k, String v) {
result += "r'''$k''': r'''$v''',\n";
});
result += '};\n';
return result;
}