-
Notifications
You must be signed in to change notification settings - Fork 3
/
str_embedding_generator_test.dart
120 lines (101 loc) · 2.77 KB
/
str_embedding_generator_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// ignore_for_file: prefer_typing_uninitialized_variables
import 'package:embed/src/str/str_embedding_generator.dart';
import 'package:embed_annotation/embed_annotation.dart';
import 'package:source_gen_test/source_gen_test.dart';
import '../utils/test_annotation.dart';
import '../utils/test_generator_mixin.dart';
Future<void> main() async {
final libraryReader = await initializeLibraryReaderForDirectory(
"test/str",
"str_embedding_generator_test.dart",
);
initializeBuildLogTracking();
testAnnotatedElements(libraryReader, _TestGenerator());
}
class _TestGenerator extends StrEmbeddingGenerator with TestGeneratorMixin {
@override
List<String> get additionalAnnotationFields => const ["raw"];
}
class TestStrLiteral extends ShouldGenerate
implements TestAnnotation, EmbedStr {
const TestStrLiteral({
required this.extension,
required this.content,
required String shouldGenerate,
this.raw = true,
}) : super(shouldGenerate);
@override
final String extension;
@override
final String content;
@override
final bool raw;
@override
String get path => throw UnimplementedError();
}
/* -------------------------------------------------------------------------- */
/* TESTS */
/* -------------------------------------------------------------------------- */
// The content should be embedded as is.
@TestStrLiteral(
extension: "txt",
content: "This is a single line text",
shouldGenerate: r"""
const _$singleLine = r'''
This is a single line text
''';
""",
)
var singleLine;
// The content should be embedded as is, even if it has multiple lines.
@TestStrLiteral(
extension: "txt",
content: r"""
The first line of the multi-line text
The second line of the multi-line text""",
shouldGenerate: r"""
const _$multiLine = r'''
The first line of the multi-line text
The second line of the multi-line text
''';
""",
)
var multiLine;
// // Leanding and trailing blank lines should be preserved.
@TestStrLiteral(
extension: "json",
content: r"""
This file contains a leading blank line
and a trailing blank line.
""",
shouldGenerate: r"""
const _$textWithBlankLines = r'''
This file contains a leading blank line
and a trailing blank line.
''';
""",
)
var textWithBlankLines;
// Content should be able to contain qutation marks.
@TestStrLiteral(
extension: "txt",
content: r"""a "b" c 'd' e \"f\'""",
shouldGenerate: r"""
const _$quotationMarks = r'''
a "b" c 'd' e \"f\'
''';
""",
)
var quotationMarks;
// Content should be embedded as a regular string literal.
@TestStrLiteral(
raw: false,
extension: "txt",
content: "This is a single line text",
shouldGenerate: r"""
const _$regularStringLiteral = '''
This is a single line text
''';
""",
)
var regularStringLiteral;