1
- import { FrontmatterInfer , FrontmatterJSON , FrontmatterTOML , FrontmatterYAML } from '../frontmatter' ;
1
+ import { FrontmatterInfer , frontmatterJSON , frontmatterTOML , frontmatterYAML } from '../frontmatter' ;
2
2
3
3
jest . mock ( "../../valueObjects/AssetProxy.js" ) ;
4
4
@@ -15,9 +15,21 @@ describe('Frontmatter', () => {
15
15
) ;
16
16
} ) ;
17
17
18
- it ( 'should parse YAML with --- delimiters when it is explicitly set as the format' , ( ) => {
18
+ it ( 'should parse YAML with --- delimiters when it is explicitly set as the format without a custom delimiter ' , ( ) => {
19
19
expect (
20
- FrontmatterYAML . fromFile ( '---\ntitle: YAML\ndescription: Something longer\n---\nContent' )
20
+ frontmatterYAML ( ) . fromFile ( '---\ntitle: YAML\ndescription: Something longer\n---\nContent' )
21
+ ) . toEqual (
22
+ {
23
+ title : 'YAML' ,
24
+ description : 'Something longer' ,
25
+ body : 'Content' ,
26
+ }
27
+ ) ;
28
+ } ) ;
29
+
30
+ it ( 'should parse YAML with custom delimiters when it is explicitly set as the format with a custom delimiter' , ( ) => {
31
+ expect (
32
+ frontmatterYAML ( "~~~" ) . fromFile ( '~~~\ntitle: YAML\ndescription: Something longer\n~~~\nContent' )
21
33
) . toEqual (
22
34
{
23
35
title : 'YAML' ,
@@ -62,9 +74,9 @@ describe('Frontmatter', () => {
62
74
) ;
63
75
} ) ;
64
76
65
- it ( 'should parse TOML with +++ delimiters when it is explicitly set as the format' , ( ) => {
77
+ it ( 'should parse TOML with +++ delimiters when it is explicitly set as the format without a custom delimiter ' , ( ) => {
66
78
expect (
67
- FrontmatterTOML . fromFile ( '+++ \ntitle = "TOML"\ndescription = "Front matter"\n+++ \nContent' )
79
+ frontmatterTOML ( "~~~" ) . fromFile ( '~~~ \ntitle = "TOML"\ndescription = "Front matter"\n~~~ \nContent' )
68
80
) . toEqual (
69
81
{
70
82
title : 'TOML' ,
@@ -98,9 +110,21 @@ describe('Frontmatter', () => {
98
110
) ;
99
111
} ) ;
100
112
101
- it ( 'should parse JSON with { } delimiters when it is explicitly set as the format' , ( ) => {
113
+ it ( 'should parse JSON with { } delimiters when it is explicitly set as the format without a custom delimiter ' , ( ) => {
102
114
expect (
103
- FrontmatterJSON . fromFile ( '{\n"title": "The Title",\n"description": "Something longer"\n}\nContent' )
115
+ frontmatterJSON ( ) . fromFile ( '{\n"title": "The Title",\n"description": "Something longer"\n}\nContent' )
116
+ ) . toEqual (
117
+ {
118
+ title : 'The Title' ,
119
+ description : 'Something longer' ,
120
+ body : 'Content' ,
121
+ }
122
+ ) ;
123
+ } ) ;
124
+
125
+ it ( 'should parse JSON with { } delimiters when it is explicitly set as the format with a custom delimiter' , ( ) => {
126
+ expect (
127
+ frontmatterJSON ( "~~~" ) . fromFile ( '~~~\n"title": "The Title",\n"description": "Something longer"\n~~~\nContent' )
104
128
) . toEqual (
105
129
{
106
130
title : 'The Title' ,
@@ -156,9 +180,10 @@ describe('Frontmatter', () => {
156
180
) ;
157
181
} ) ;
158
182
159
- it ( 'should stringify YAML with --- delimiters when it is explicitly set as the format' , ( ) => {
183
+ it ( 'should stringify YAML with --- delimiters when it is explicitly set as the format without a custom delimiter' ,
184
+ ( ) => {
160
185
expect (
161
- FrontmatterYAML . toFile ( { body : 'Some content\nOn another line' , tags : [ 'front matter' , 'yaml' ] , title : 'YAML' } )
186
+ frontmatterYAML ( ) . toFile ( { body : 'Some content\nOn another line' , tags : [ 'front matter' , 'yaml' ] , title : 'YAML' } )
162
187
) . toEqual (
163
188
[
164
189
'---' ,
@@ -173,9 +198,28 @@ describe('Frontmatter', () => {
173
198
) ;
174
199
} ) ;
175
200
176
- it ( 'should stringify TOML with +++ delimiters when it is explicitly set as the format' , ( ) => {
201
+ it ( 'should stringify YAML with --- delimiters when it is explicitly set as the format with a custom delimiter' ,
202
+ ( ) => {
203
+ expect (
204
+ frontmatterYAML ( "~~~" ) . toFile ( { body : 'Some content\nOn another line' , tags : [ 'front matter' , 'yaml' ] , title : 'YAML' } )
205
+ ) . toEqual (
206
+ [
207
+ '~~~' ,
208
+ 'tags:' ,
209
+ ' - front matter' ,
210
+ ' - yaml' ,
211
+ 'title: YAML' ,
212
+ '~~~' ,
213
+ 'Some content' ,
214
+ 'On another line\n' ,
215
+ ] . join ( '\n' )
216
+ ) ;
217
+ } ) ;
218
+
219
+ it ( 'should stringify TOML with +++ delimiters when it is explicitly set as the format without a custom delimiter' ,
220
+ ( ) => {
177
221
expect (
178
- FrontmatterTOML . toFile ( { body : 'Some content\nOn another line' , tags : [ 'front matter' , 'toml' ] , title : 'TOML' } )
222
+ frontmatterTOML ( ) . toFile ( { body : 'Some content\nOn another line' , tags : [ 'front matter' , 'toml' ] , title : 'TOML' } )
179
223
) . toEqual (
180
224
[
181
225
'+++' ,
@@ -188,9 +232,26 @@ describe('Frontmatter', () => {
188
232
) ;
189
233
} ) ;
190
234
191
- it ( 'should stringify JSON with { } delimiters when it is explicitly set as the format' , ( ) => {
235
+ it ( 'should stringify TOML with +++ delimiters when it is explicitly set as the format with a custom delimiter' ,
236
+ ( ) => {
237
+ expect (
238
+ frontmatterTOML ( "~~~" ) . toFile ( { body : 'Some content\nOn another line' , tags : [ 'front matter' , 'toml' ] , title : 'TOML' } )
239
+ ) . toEqual (
240
+ [
241
+ '~~~' ,
242
+ 'tags = ["front matter", "toml"]' ,
243
+ 'title = "TOML"' ,
244
+ '~~~' ,
245
+ 'Some content' ,
246
+ 'On another line\n' ,
247
+ ] . join ( '\n' )
248
+ ) ;
249
+ } ) ;
250
+
251
+ it ( 'should stringify JSON with { } delimiters when it is explicitly set as the format without a custom delimiter' ,
252
+ ( ) => {
192
253
expect (
193
- FrontmatterJSON . toFile ( { body : 'Some content\nOn another line' , tags : [ 'front matter' , 'json' ] , title : 'JSON' } )
254
+ frontmatterJSON ( ) . toFile ( { body : 'Some content\nOn another line' , tags : [ 'front matter' , 'json' ] , title : 'JSON' } )
194
255
) . toEqual (
195
256
[
196
257
'{' ,
@@ -205,4 +266,23 @@ describe('Frontmatter', () => {
205
266
] . join ( '\n' )
206
267
) ;
207
268
} ) ;
269
+
270
+ it ( 'should stringify JSON with { } delimiters when it is explicitly set as the format with a custom delimiter' ,
271
+ ( ) => {
272
+ expect (
273
+ frontmatterJSON ( "~~~" ) . toFile ( { body : 'Some content\nOn another line' , tags : [ 'front matter' , 'json' ] , title : 'JSON' } )
274
+ ) . toEqual (
275
+ [
276
+ '~~~' ,
277
+ '"tags": [' ,
278
+ ' "front matter",' ,
279
+ ' "json"' ,
280
+ ' ],' ,
281
+ ' "title": "JSON"' ,
282
+ '~~~' ,
283
+ 'Some content' ,
284
+ 'On another line\n' ,
285
+ ] . join ( '\n' )
286
+ ) ;
287
+ } ) ;
208
288
} ) ;
0 commit comments