Skip to content

Commit

Permalink
unit test coverage for markdown parser
Browse files Browse the repository at this point in the history
removed the attempted stripping of quotes around frontmatter values.
  • Loading branch information
bmuenzenmeyer committed Jul 6, 2016
1 parent 1a7d6d1 commit 0c75011
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 96 deletions.
2 changes: 1 addition & 1 deletion core/lib/markdown_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var markdown_parser = function () {
var frontmatterKey = frontmatterLineChunks[0].toLowerCase().trim();
var frontmatterValueString = frontmatterLineChunks[1].trim();

returnObject[frontmatterKey] = frontmatterValueString.substring(1, frontmatterValueString.length - 1);
returnObject[frontmatterKey] = frontmatterValueString;
}

}
Expand Down
3 changes: 3 additions & 0 deletions test/files/_patterns/00-test/00-foo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## A Simple Include

This pattern contains an include of `test-bar`. It also has this markdown file, which does not have frontmatter.
6 changes: 6 additions & 0 deletions test/files/_patterns/00-test/01-bar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
status: complete
---
## A Simple Bit of Markup

Foo cannot get simpler than bar, amiright?
12 changes: 6 additions & 6 deletions test/files/annotations.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
el: "header[role=banner]"
title: "Masthead"
el: header[role=banner]
title: Masthead
---
The main header of the site doesn't take up *too much screen real estate* in order to keep the focus on the core content.
It's using a linear CSS gradient instead of a background image to give greater design flexibility and reduce HTTP requests.
~*~
---
selector: ".logo"
title: "Logo"
selector: .logo
title: Logo
---
The _logo image_ is an SVG file.
~*~
---
el: "#nav"
title : "Navigation"
el: #nav
title : Navigation
---
Navigation for adaptive web experiences can be tricky. Refer to [these repsonsive patterns](https://bradfrost.github.io/this-is-responsive/patterns.html#navigation) when evaluating solutions.
35 changes: 35 additions & 0 deletions test/markdown_parser_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";

var path = require('path');
var fs = require('fs-extra');
var eol = require('os').EOL;
var mp = require('../core/lib/markdown_parser');
var markdown_parser = new mp();

exports['markdown_parser'] = {
'parses pattern description block correctly when frontmatter not present' : function(test){
//arrange
var markdownFileName = path.resolve("./test/files/_patterns/00-test/00-foo.md");
var markdownFileContents = fs.readFileSync(markdownFileName, 'utf8');

//act
var returnObject = markdown_parser.parse(markdownFileContents)

//assert
test.equals(returnObject.markdown, '<h2>A Simple Include</h2>\n<p>This pattern contains an include of <code>test-bar</code>. It also has this markdown file, which does not have frontmatter.</p>\n');
test.done();
},
'parses pattern description block correctly when frontmatter present' : function(test){
//arrange
var markdownFileName = path.resolve("./test/files/_patterns/00-test/01-bar.md");
var markdownFileContents = fs.readFileSync(markdownFileName, 'utf8');

//act
var returnObject = markdown_parser.parse(markdownFileContents)

//assert
test.equals(returnObject.markdown, '<h2>A Simple Bit of Markup</h2>\n<p>Foo cannot get simpler than bar, amiright?</p>\n');
test.equals(returnObject.status, 'complete');
test.done();
}
};
175 changes: 86 additions & 89 deletions test/style_modifier_hunter_tests.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,86 @@
(function () {
"use strict";

var smh = require('../core/lib/style_modifier_hunter');

exports['consume_style_modifier'] = {
'uses the partial stylemodifer to modify the patterns extendedTemplate' : function(test){
//arrange
var pl = {};
pl.partials = {};
pl.config = {};
pl.config.debug = false;

var pattern = {
extendedTemplate: '<div class="foo {{styleModifier}}"></div>'
};

var style_modifier_hunter = new smh();

//act
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl);

//assert
test.equals(pattern.extendedTemplate, '<div class="foo bar"></div>');
test.done();
},
'replaces style modifiers with spaces in the syntax' : function(test){
//arrange
var pl = {};
pl.partials = {};
pl.config = {};
pl.config.debug = false;

var pattern = {
extendedTemplate: '<div class="foo {{ styleModifier }}"></div>'
};

var style_modifier_hunter = new smh();

//act
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl);

//assert
test.equals(pattern.extendedTemplate, '<div class="foo bar"></div>');
test.done();
},
'replaces multiple style modifiers' : function(test){
//arrange
var pl = {};
pl.partials = {};
pl.config = {};
pl.config.debug = false;

var pattern = {
extendedTemplate: '<div class="foo {{ styleModifier }}"></div>'
};

var style_modifier_hunter = new smh();

//act
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar|baz|dum}}', pl);

//assert
test.equals(pattern.extendedTemplate, '<div class="foo bar baz dum"></div>');
test.done();
},
'does not alter pattern extendedTemplate if styleModifier not found in partial' : function(test){
//arrange
var pl = {};
pl.partials = {};
pl.config = {};
pl.config.debug = false;

var pattern = {
extendedTemplate: '<div class="foo {{styleModifier}}"></div>'
};

var style_modifier_hunter = new smh();

//act
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial}}', pl);

//assert
test.equals(pattern.extendedTemplate, '<div class="foo {{styleModifier}}"></div>');
test.done();
}
};

}());
"use strict";

var smh = require('../core/lib/style_modifier_hunter');

exports['consume_style_modifier'] = {
'uses the partial stylemodifer to modify the patterns extendedTemplate' : function(test){
//arrange
var pl = {};
pl.partials = {};
pl.config = {};
pl.config.debug = false;

var pattern = {
extendedTemplate: '<div class="foo {{styleModifier}}"></div>'
};

var style_modifier_hunter = new smh();

//act
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl);

//assert
test.equals(pattern.extendedTemplate, '<div class="foo bar"></div>');
test.done();
},
'replaces style modifiers with spaces in the syntax' : function(test){
//arrange
var pl = {};
pl.partials = {};
pl.config = {};
pl.config.debug = false;

var pattern = {
extendedTemplate: '<div class="foo {{ styleModifier }}"></div>'
};

var style_modifier_hunter = new smh();

//act
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl);

//assert
test.equals(pattern.extendedTemplate, '<div class="foo bar"></div>');
test.done();
},
'replaces multiple style modifiers' : function(test){
//arrange
var pl = {};
pl.partials = {};
pl.config = {};
pl.config.debug = false;

var pattern = {
extendedTemplate: '<div class="foo {{ styleModifier }}"></div>'
};

var style_modifier_hunter = new smh();

//act
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar|baz|dum}}', pl);

//assert
test.equals(pattern.extendedTemplate, '<div class="foo bar baz dum"></div>');
test.done();
},
'does not alter pattern extendedTemplate if styleModifier not found in partial' : function(test){
//arrange
var pl = {};
pl.partials = {};
pl.config = {};
pl.config.debug = false;

var pattern = {
extendedTemplate: '<div class="foo {{styleModifier}}"></div>'
};

var style_modifier_hunter = new smh();

//act
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial}}', pl);

//assert
test.equals(pattern.extendedTemplate, '<div class="foo {{styleModifier}}"></div>');
test.done();
}
};

0 comments on commit 0c75011

Please sign in to comment.