@@ -121,6 +121,127 @@ public async Task EmptyFirstLineWithoutDelimiterTreatsAsFrontMatter()
121
121
Content2" ) ;
122
122
}
123
123
124
+ [ Test ]
125
+ public async Task DelimiterWithNewLineTreatsAsFrontMatter ( )
126
+ {
127
+ // Given
128
+ TestExecutionContext context = new TestExecutionContext ( ) ;
129
+ TestDocument [ ] inputs =
130
+ {
131
+ new TestDocument ( @"FM1
132
+ FM2
133
+ ---
134
+ " )
135
+ } ;
136
+ string frontMatterContent = null ;
137
+ ExtractFrontMatter frontMatter = new ExtractFrontMatter ( new ExecuteConfig ( Config . FromDocument ( async x =>
138
+ {
139
+ frontMatterContent = await x . GetContentStringAsync ( ) ;
140
+ return new [ ] { x } ;
141
+ } ) ) ) ;
142
+
143
+ // When
144
+ IEnumerable < IDocument > documents = await ExecuteAsync ( inputs , context , frontMatter ) ;
145
+
146
+ // Then
147
+ documents . Count ( ) . ShouldBe ( 1 ) ;
148
+ frontMatterContent . ShouldBe (
149
+ @"FM1
150
+ FM2
151
+ " ) ;
152
+ ( await documents . First ( ) . GetContentStringAsync ( ) ) . ShouldBeEmpty ( ) ;
153
+ }
154
+
155
+ [ Test ]
156
+ public async Task DelimiterOnLastLineTreatsAsFrontMatter ( )
157
+ {
158
+ // Given
159
+ TestExecutionContext context = new TestExecutionContext ( ) ;
160
+ TestDocument [ ] inputs =
161
+ {
162
+ new TestDocument ( @"FM1
163
+ FM2
164
+ ---" )
165
+ } ;
166
+ string frontMatterContent = null ;
167
+ ExtractFrontMatter frontMatter = new ExtractFrontMatter ( new ExecuteConfig ( Config . FromDocument ( async x =>
168
+ {
169
+ frontMatterContent = await x . GetContentStringAsync ( ) ;
170
+ return new [ ] { x } ;
171
+ } ) ) ) ;
172
+
173
+ // When
174
+ IEnumerable < IDocument > documents = await ExecuteAsync ( inputs , context , frontMatter ) ;
175
+
176
+ // Then
177
+ documents . Count ( ) . ShouldBe ( 1 ) ;
178
+ frontMatterContent . ShouldBe (
179
+ @"FM1
180
+ FM2
181
+ " ) ;
182
+ ( await documents . First ( ) . GetContentStringAsync ( ) ) . ShouldBeEmpty ( ) ;
183
+ }
184
+
185
+ [ Test ]
186
+ public async Task DelimiterFollowedByJunkIsNotFrontMatter ( )
187
+ {
188
+ // Given
189
+ TestExecutionContext context = new TestExecutionContext ( ) ;
190
+ TestDocument [ ] inputs =
191
+ {
192
+ new TestDocument ( @"FM1
193
+ FM2
194
+ ---foo" )
195
+ } ;
196
+ string frontMatterContent = null ;
197
+ ExtractFrontMatter frontMatter = new ExtractFrontMatter ( new ExecuteConfig ( Config . FromDocument ( async x =>
198
+ {
199
+ frontMatterContent = await x . GetContentStringAsync ( ) ;
200
+ return new [ ] { x } ;
201
+ } ) ) ) ;
202
+
203
+ // When
204
+ IEnumerable < IDocument > documents = await ExecuteAsync ( inputs , context , frontMatter ) ;
205
+
206
+ // Then
207
+ documents . Count ( ) . ShouldBe ( 1 ) ;
208
+ frontMatterContent . ShouldBeNull ( ) ;
209
+ ( await documents . First ( ) . GetContentStringAsync ( ) ) . ShouldBe (
210
+ @"FM1
211
+ FM2
212
+ ---foo" ) ;
213
+ }
214
+
215
+ [ Test ]
216
+ public async Task DelimiterPrecededByJunkIsNotFrontMatter ( )
217
+ {
218
+ // Given
219
+ TestExecutionContext context = new TestExecutionContext ( ) ;
220
+ TestDocument [ ] inputs =
221
+ {
222
+ new TestDocument ( @"FM1
223
+ FM2
224
+ foo---" )
225
+ } ;
226
+ string frontMatterContent = null ;
227
+ ExtractFrontMatter frontMatter = new ExtractFrontMatter ( new ExecuteConfig ( Config . FromDocument ( async x =>
228
+ {
229
+ frontMatterContent = await x . GetContentStringAsync ( ) ;
230
+ return new [ ] { x } ;
231
+ } ) ) ) ;
232
+
233
+ // When
234
+ IEnumerable < IDocument > documents = await ExecuteAsync ( inputs , context , frontMatter ) ;
235
+
236
+ // Then
237
+ documents . Count ( ) . ShouldBe ( 1 ) ;
238
+ frontMatterContent . ShouldBeNull ( ) ;
239
+ ( await documents . First ( ) . GetContentStringAsync ( ) ) . ShouldBe (
240
+ @"FM1
241
+ FM2
242
+ foo---" ) ;
243
+ }
244
+
124
245
[ Test ]
125
246
public async Task DashStringDoesNotSplitAtNonmatchingDashes ( )
126
247
{
0 commit comments