Skip to content

Commit

Permalink
Update Frontmatter formatter tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tech4him1 committed Jan 3, 2018
1 parent bf8b7b3 commit c57858a
Showing 1 changed file with 96 additions and 10 deletions.
106 changes: 96 additions & 10 deletions src/formats/__tests__/frontmatter.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import FrontmatterFormatter from '../frontmatter';
import { FrontmatterInfer, FrontmatterJSON, FrontmatterTOML, FrontmatterYAML } from '../frontmatter';

jest.mock("../../valueObjects/AssetProxy.js");

describe('Frontmatter', () => {
it('should parse YAML with --- delimiters', () => {
expect(
FrontmatterFormatter.fromFile('---\ntitle: YAML\ndescription: Something longer\n---\nContent')
FrontmatterInfer.fromFile('---\ntitle: YAML\ndescription: Something longer\n---\nContent')
).toEqual(
{
title: 'YAML',
Expand All @@ -15,9 +15,21 @@ describe('Frontmatter', () => {
);
});

it('should parse YAML with --- delimiters when it is explicitly set as the format', () => {
expect(
FrontmatterYAML.fromFile('---\ntitle: YAML\ndescription: Something longer\n---\nContent')
).toEqual(
{
title: 'YAML',
description: 'Something longer',
body: 'Content',
}
);
});

it('should parse YAML with ---yaml delimiters', () => {
expect(
FrontmatterFormatter.fromFile('---yaml\ntitle: YAML\ndescription: Something longer\n---\nContent')
FrontmatterInfer.fromFile('---yaml\ntitle: YAML\ndescription: Something longer\n---\nContent')
).toEqual(
{
title: 'YAML',
Expand All @@ -29,7 +41,7 @@ describe('Frontmatter', () => {

it('should overwrite any body param in the front matter', () => {
expect(
FrontmatterFormatter.fromFile('---\ntitle: The Title\nbody: Something longer\n---\nContent')
FrontmatterInfer.fromFile('---\ntitle: The Title\nbody: Something longer\n---\nContent')
).toEqual(
{
title: 'The Title',
Expand All @@ -40,7 +52,7 @@ describe('Frontmatter', () => {

it('should parse TOML with +++ delimiters', () => {
expect(
FrontmatterFormatter.fromFile('+++\ntitle = "TOML"\ndescription = "Front matter"\n+++\nContent')
FrontmatterInfer.fromFile('+++\ntitle = "TOML"\ndescription = "Front matter"\n+++\nContent')
).toEqual(
{
title: 'TOML',
Expand All @@ -50,9 +62,21 @@ describe('Frontmatter', () => {
);
});

it('should parse TOML with +++ delimiters when it is explicitly set as the format', () => {
expect(
FrontmatterTOML.fromFile('+++\ntitle = "TOML"\ndescription = "Front matter"\n+++\nContent')
).toEqual(
{
title: 'TOML',
description: 'Front matter',
body: 'Content',
}
);
});

it('should parse TOML with ---toml delimiters', () => {
expect(
FrontmatterFormatter.fromFile('---toml\ntitle = "TOML"\ndescription = "Something longer"\n---\nContent')
FrontmatterInfer.fromFile('---toml\ntitle = "TOML"\ndescription = "Something longer"\n---\nContent')
).toEqual(
{
title: 'TOML',
Expand All @@ -64,7 +88,7 @@ describe('Frontmatter', () => {

it('should parse JSON with { } delimiters', () => {
expect(
FrontmatterFormatter.fromFile('{\n"title": "The Title",\n"description": "Something longer"\n}\nContent')
FrontmatterInfer.fromFile('{\n"title": "The Title",\n"description": "Something longer"\n}\nContent')
).toEqual(
{
title: 'The Title',
Expand All @@ -74,9 +98,21 @@ describe('Frontmatter', () => {
);
});

it('should parse JSON with { } delimiters when it is explicitly set as the format', () => {
expect(
FrontmatterJSON.fromFile('{\n"title": "The Title",\n"description": "Something longer"\n}\nContent')
).toEqual(
{
title: 'The Title',
description: 'Something longer',
body: 'Content',
}
);
});

it('should parse JSON with ---json delimiters', () => {
expect(
FrontmatterFormatter.fromFile('---json\n{\n"title": "The Title",\n"description": "Something longer"\n}\n---\nContent')
FrontmatterInfer.fromFile('---json\n{\n"title": "The Title",\n"description": "Something longer"\n}\n---\nContent')
).toEqual(
{
title: 'The Title',
Expand All @@ -88,7 +124,7 @@ describe('Frontmatter', () => {

it('should stringify YAML with --- delimiters', () => {
expect(
FrontmatterFormatter.toFile({ body: 'Some content\nOn another line', tags: ['front matter', 'yaml'], title: 'YAML' })
FrontmatterInfer.toFile({ body: 'Some content\nOn another line', tags: ['front matter', 'yaml'], title: 'YAML' })
).toEqual(
[
'---',
Expand All @@ -105,7 +141,7 @@ describe('Frontmatter', () => {

it('should stringify YAML with missing body', () => {
expect(
FrontmatterFormatter.toFile({ tags: ['front matter', 'yaml'], title: 'YAML' })
FrontmatterInfer.toFile({ tags: ['front matter', 'yaml'], title: 'YAML' })
).toEqual(
[
'---',
Expand All @@ -119,4 +155,54 @@ describe('Frontmatter', () => {
].join('\n')
);
});

it('should stringify YAML with --- delimiters when it is explicitly set as the format', () => {
expect(
FrontmatterYAML.toFile({ body: 'Some content\nOn another line', tags: ['front matter', 'yaml'], title: 'YAML' })
).toEqual(
[
'---',
'tags:',
' - front matter',
' - yaml',
'title: YAML',
'---',
'Some content',
'On another line\n',
].join('\n')
);
});

it('should stringify TOML with +++ delimiters when it is explicitly set as the format', () => {
expect(
FrontmatterTOML.toFile({ body: 'Some content\nOn another line', tags: ['front matter', 'toml'], title: 'TOML' })
).toEqual(
[
'+++',
'tags = ["front matter", "toml"]',
'title = "TOML"',
'+++',
'Some content',
'On another line\n',
].join('\n')
);
});

it('should stringify JSON with { } delimiters when it is explicitly set as the format', () => {
expect(
FrontmatterJSON.toFile({ body: 'Some content\nOn another line', tags: ['front matter', 'json'], title: 'JSON' })
).toEqual(
[
'{',
'"tags": [',
' "front matter",',
' "json"',
' ],',
' "title": "JSON"',
'}',
'Some content',
'On another line\n',
].join('\n')
);
});
});

0 comments on commit c57858a

Please sign in to comment.