Skip to content

Commit 0c75011

Browse files
committed
unit test coverage for markdown parser
removed the attempted stripping of quotes around frontmatter values.
1 parent 1a7d6d1 commit 0c75011

File tree

6 files changed

+137
-96
lines changed

6 files changed

+137
-96
lines changed

core/lib/markdown_parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var markdown_parser = function () {
2525
var frontmatterKey = frontmatterLineChunks[0].toLowerCase().trim();
2626
var frontmatterValueString = frontmatterLineChunks[1].trim();
2727

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

3131
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## A Simple Include
2+
3+
This pattern contains an include of `test-bar`. It also has this markdown file, which does not have frontmatter.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
status: complete
3+
---
4+
## A Simple Bit of Markup
5+
6+
Foo cannot get simpler than bar, amiright?

test/files/annotations.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
2-
el: "header[role=banner]"
3-
title: "Masthead"
2+
el: header[role=banner]
3+
title: Masthead
44
---
55
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.
66
It's using a linear CSS gradient instead of a background image to give greater design flexibility and reduce HTTP requests.
77
~*~
88
---
9-
selector: ".logo"
10-
title: "Logo"
9+
selector: .logo
10+
title: Logo
1111
---
1212
The _logo image_ is an SVG file.
1313
~*~
1414
---
15-
el: "#nav"
16-
title : "Navigation"
15+
el: #nav
16+
title : Navigation
1717
---
1818
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.

test/markdown_parser_tests.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
3+
var path = require('path');
4+
var fs = require('fs-extra');
5+
var eol = require('os').EOL;
6+
var mp = require('../core/lib/markdown_parser');
7+
var markdown_parser = new mp();
8+
9+
exports['markdown_parser'] = {
10+
'parses pattern description block correctly when frontmatter not present' : function(test){
11+
//arrange
12+
var markdownFileName = path.resolve("./test/files/_patterns/00-test/00-foo.md");
13+
var markdownFileContents = fs.readFileSync(markdownFileName, 'utf8');
14+
15+
//act
16+
var returnObject = markdown_parser.parse(markdownFileContents)
17+
18+
//assert
19+
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');
20+
test.done();
21+
},
22+
'parses pattern description block correctly when frontmatter present' : function(test){
23+
//arrange
24+
var markdownFileName = path.resolve("./test/files/_patterns/00-test/01-bar.md");
25+
var markdownFileContents = fs.readFileSync(markdownFileName, 'utf8');
26+
27+
//act
28+
var returnObject = markdown_parser.parse(markdownFileContents)
29+
30+
//assert
31+
test.equals(returnObject.markdown, '<h2>A Simple Bit of Markup</h2>\n<p>Foo cannot get simpler than bar, amiright?</p>\n');
32+
test.equals(returnObject.status, 'complete');
33+
test.done();
34+
}
35+
};

test/style_modifier_hunter_tests.js

Lines changed: 86 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,86 @@
1-
(function () {
2-
"use strict";
3-
4-
var smh = require('../core/lib/style_modifier_hunter');
5-
6-
exports['consume_style_modifier'] = {
7-
'uses the partial stylemodifer to modify the patterns extendedTemplate' : function(test){
8-
//arrange
9-
var pl = {};
10-
pl.partials = {};
11-
pl.config = {};
12-
pl.config.debug = false;
13-
14-
var pattern = {
15-
extendedTemplate: '<div class="foo {{styleModifier}}"></div>'
16-
};
17-
18-
var style_modifier_hunter = new smh();
19-
20-
//act
21-
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl);
22-
23-
//assert
24-
test.equals(pattern.extendedTemplate, '<div class="foo bar"></div>');
25-
test.done();
26-
},
27-
'replaces style modifiers with spaces in the syntax' : function(test){
28-
//arrange
29-
var pl = {};
30-
pl.partials = {};
31-
pl.config = {};
32-
pl.config.debug = false;
33-
34-
var pattern = {
35-
extendedTemplate: '<div class="foo {{ styleModifier }}"></div>'
36-
};
37-
38-
var style_modifier_hunter = new smh();
39-
40-
//act
41-
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl);
42-
43-
//assert
44-
test.equals(pattern.extendedTemplate, '<div class="foo bar"></div>');
45-
test.done();
46-
},
47-
'replaces multiple style modifiers' : function(test){
48-
//arrange
49-
var pl = {};
50-
pl.partials = {};
51-
pl.config = {};
52-
pl.config.debug = false;
53-
54-
var pattern = {
55-
extendedTemplate: '<div class="foo {{ styleModifier }}"></div>'
56-
};
57-
58-
var style_modifier_hunter = new smh();
59-
60-
//act
61-
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar|baz|dum}}', pl);
62-
63-
//assert
64-
test.equals(pattern.extendedTemplate, '<div class="foo bar baz dum"></div>');
65-
test.done();
66-
},
67-
'does not alter pattern extendedTemplate if styleModifier not found in partial' : function(test){
68-
//arrange
69-
var pl = {};
70-
pl.partials = {};
71-
pl.config = {};
72-
pl.config.debug = false;
73-
74-
var pattern = {
75-
extendedTemplate: '<div class="foo {{styleModifier}}"></div>'
76-
};
77-
78-
var style_modifier_hunter = new smh();
79-
80-
//act
81-
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial}}', pl);
82-
83-
//assert
84-
test.equals(pattern.extendedTemplate, '<div class="foo {{styleModifier}}"></div>');
85-
test.done();
86-
}
87-
};
88-
89-
}());
1+
"use strict";
2+
3+
var smh = require('../core/lib/style_modifier_hunter');
4+
5+
exports['consume_style_modifier'] = {
6+
'uses the partial stylemodifer to modify the patterns extendedTemplate' : function(test){
7+
//arrange
8+
var pl = {};
9+
pl.partials = {};
10+
pl.config = {};
11+
pl.config.debug = false;
12+
13+
var pattern = {
14+
extendedTemplate: '<div class="foo {{styleModifier}}"></div>'
15+
};
16+
17+
var style_modifier_hunter = new smh();
18+
19+
//act
20+
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl);
21+
22+
//assert
23+
test.equals(pattern.extendedTemplate, '<div class="foo bar"></div>');
24+
test.done();
25+
},
26+
'replaces style modifiers with spaces in the syntax' : function(test){
27+
//arrange
28+
var pl = {};
29+
pl.partials = {};
30+
pl.config = {};
31+
pl.config.debug = false;
32+
33+
var pattern = {
34+
extendedTemplate: '<div class="foo {{ styleModifier }}"></div>'
35+
};
36+
37+
var style_modifier_hunter = new smh();
38+
39+
//act
40+
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl);
41+
42+
//assert
43+
test.equals(pattern.extendedTemplate, '<div class="foo bar"></div>');
44+
test.done();
45+
},
46+
'replaces multiple style modifiers' : function(test){
47+
//arrange
48+
var pl = {};
49+
pl.partials = {};
50+
pl.config = {};
51+
pl.config.debug = false;
52+
53+
var pattern = {
54+
extendedTemplate: '<div class="foo {{ styleModifier }}"></div>'
55+
};
56+
57+
var style_modifier_hunter = new smh();
58+
59+
//act
60+
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar|baz|dum}}', pl);
61+
62+
//assert
63+
test.equals(pattern.extendedTemplate, '<div class="foo bar baz dum"></div>');
64+
test.done();
65+
},
66+
'does not alter pattern extendedTemplate if styleModifier not found in partial' : function(test){
67+
//arrange
68+
var pl = {};
69+
pl.partials = {};
70+
pl.config = {};
71+
pl.config.debug = false;
72+
73+
var pattern = {
74+
extendedTemplate: '<div class="foo {{styleModifier}}"></div>'
75+
};
76+
77+
var style_modifier_hunter = new smh();
78+
79+
//act
80+
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial}}', pl);
81+
82+
//assert
83+
test.equals(pattern.extendedTemplate, '<div class="foo {{styleModifier}}"></div>');
84+
test.done();
85+
}
86+
};

0 commit comments

Comments
 (0)