From a8542fdbf648ee5bfd0df0955c6a914fdc0f2fd8 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Wed, 5 Oct 2016 13:30:28 -0500 Subject: [PATCH 1/9] add test cases --- test/files/_patterns/00-test/00-hidden-pattern.mustache | 1 + test/files/_patterns/00-test/15-hidden-pattern-tester.mustache | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 test/files/_patterns/00-test/00-hidden-pattern.mustache create mode 100644 test/files/_patterns/00-test/15-hidden-pattern-tester.mustache diff --git a/test/files/_patterns/00-test/00-hidden-pattern.mustache b/test/files/_patterns/00-test/00-hidden-pattern.mustache new file mode 100644 index 000000000..0f5831922 --- /dev/null +++ b/test/files/_patterns/00-test/00-hidden-pattern.mustache @@ -0,0 +1 @@ +This is the hidden atom \ No newline at end of file diff --git a/test/files/_patterns/00-test/15-hidden-pattern-tester.mustache b/test/files/_patterns/00-test/15-hidden-pattern-tester.mustache new file mode 100644 index 000000000..3a7fa43a4 --- /dev/null +++ b/test/files/_patterns/00-test/15-hidden-pattern-tester.mustache @@ -0,0 +1,2 @@ +Hello there! +Here's the hidden atom: [{{> test-_00-hidden-pattern}}] \ No newline at end of file From 98b2b4ba851fef243bc690e45b3c35f400e9b8c9 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Wed, 5 Oct 2016 16:27:25 -0500 Subject: [PATCH 2/9] unit tests to confirm correct functioning of hidden mustache templates; unit test to confirm bug in hbs engine; factor out fakePatternLab() into a new module, test_utils.js --- test/engine_handlebars_tests.js | 25 ++++++++++++++++ .../00-atoms/00-global/_00-hidden.hbs | 1 + .../00-global/00-hidden-pattern-tester.hbs | 1 + .../00-test/15-hidden-pattern-tester.mustache | 2 +- ...n.mustache => _00-hidden-pattern.mustache} | 0 test/pattern_assembler_tests.js | 23 ++++++++++++++- test/util/test_utils.js | 29 +++++++++++++++++++ 7 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 test/files/_handlebars-test-patterns/00-atoms/00-global/_00-hidden.hbs create mode 100644 test/files/_handlebars-test-patterns/00-molecules/00-global/00-hidden-pattern-tester.hbs rename test/files/_patterns/00-test/{00-hidden-pattern.mustache => _00-hidden-pattern.mustache} (100%) create mode 100644 test/util/test_utils.js diff --git a/test/engine_handlebars_tests.js b/test/engine_handlebars_tests.js index 3521ee362..c52548bc5 100644 --- a/test/engine_handlebars_tests.js +++ b/test/engine_handlebars_tests.js @@ -181,6 +181,31 @@ exports['engine_handlebars'] = { testFindPartials(test, [ '{{#> myPartial }}' ]); + }, + 'hidden handlebars patterns can be called by their nice names' : function(test){ + const util = require('./util/test_utils.js'); + + //arrange + const testPatternsPath = path.resolve(__dirname, 'files', '_handlebars-test-patterns'); + const pl = util.fakePatternLab(testPatternsPath); + var pattern_assembler = new pa(); + + var hiddenPatternPath = path.join('00-atoms', '00-global', '_00-hidden.hbs'); + var hiddenPattern = pattern_assembler.process_pattern_iterative(hiddenPatternPath, pl); + pattern_assembler.process_pattern_recursive(hiddenPatternPath, pl); + + var testPatternPath = path.join('00-molecules', '00-global', '00-hidden-pattern-tester.hbs'); + var testPattern = pattern_assembler.process_pattern_iterative(testPatternPath, pl); + pattern_assembler.process_pattern_recursive(testPatternPath, pl); + + //act + test.equals(testPattern.render(), 'Hello there!\nHere\'s the hidden atom: [This is the hidden atom]\n'); + + //assert + // test.equals(patternlab.patterns.length, 1); + // test.equals(patternlab.partials['test-bar'] != undefined, true); + // test.equals(patternlab.partials['test-bar'], 'bar'); + test.done(); } }; diff --git a/test/files/_handlebars-test-patterns/00-atoms/00-global/_00-hidden.hbs b/test/files/_handlebars-test-patterns/00-atoms/00-global/_00-hidden.hbs new file mode 100644 index 000000000..b2c93a13e --- /dev/null +++ b/test/files/_handlebars-test-patterns/00-atoms/00-global/_00-hidden.hbs @@ -0,0 +1 @@ +I'm the hidden atom diff --git a/test/files/_handlebars-test-patterns/00-molecules/00-global/00-hidden-pattern-tester.hbs b/test/files/_handlebars-test-patterns/00-molecules/00-global/00-hidden-pattern-tester.hbs new file mode 100644 index 000000000..ce4a0c864 --- /dev/null +++ b/test/files/_handlebars-test-patterns/00-molecules/00-global/00-hidden-pattern-tester.hbs @@ -0,0 +1 @@ +Here's the hidden atom: [{{> atoms-hidden}}] diff --git a/test/files/_patterns/00-test/15-hidden-pattern-tester.mustache b/test/files/_patterns/00-test/15-hidden-pattern-tester.mustache index 3a7fa43a4..5598f783f 100644 --- a/test/files/_patterns/00-test/15-hidden-pattern-tester.mustache +++ b/test/files/_patterns/00-test/15-hidden-pattern-tester.mustache @@ -1,2 +1,2 @@ Hello there! -Here's the hidden atom: [{{> test-_00-hidden-pattern}}] \ No newline at end of file +Here's the hidden atom: [{{> test-hidden-pattern}}] diff --git a/test/files/_patterns/00-test/00-hidden-pattern.mustache b/test/files/_patterns/00-test/_00-hidden-pattern.mustache similarity index 100% rename from test/files/_patterns/00-test/00-hidden-pattern.mustache rename to test/files/_patterns/00-test/_00-hidden-pattern.mustache diff --git a/test/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index 33c3898d1..401d31955 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -636,6 +636,27 @@ test.equals(patternlab.partials['test-bar'] != undefined, true); test.equals(patternlab.partials['test-bar'], 'bar'); test.done(); - } + }, + 'hidden patterns can be called by their nice names' : function(test){ + const util = require('./util/test_utils.js'); + + //arrange + const testPatternsPath = path.resolve(__dirname, 'files', '_patterns'); + const pl = util.fakePatternLab(testPatternsPath); + var pattern_assembler = new pa(); + + //act + var hiddenPatternPath = path.join('00-test', '_00-hidden-pattern.mustache'); + var hiddenPattern = pattern_assembler.process_pattern_iterative(hiddenPatternPath, pl); + pattern_assembler.process_pattern_recursive(hiddenPatternPath, pl); + + var testPatternPath = path.join('00-test', '15-hidden-pattern-tester.mustache'); + var testPattern = pattern_assembler.process_pattern_iterative(testPatternPath, pl); + pattern_assembler.process_pattern_recursive(testPatternPath, pl); + + //assert + test.equals(testPattern.render(), 'Hello there!\nHere\'s the hidden atom: [This is the hidden atom]\n'); + test.done(); + } }; })(); diff --git a/test/util/test_utils.js b/test/util/test_utils.js new file mode 100644 index 000000000..97e79c569 --- /dev/null +++ b/test/util/test_utils.js @@ -0,0 +1,29 @@ +"use strict"; + +module.exports = { + + // fake pattern lab constructor: + // sets up a fake patternlab object, which is needed by the pattern processing + // apparatus. + fakePatternLab: (testPatternsPath) => { + var fpl = { + partials: {}, + patterns: [], + footer: '', + header: '', + listitems: {}, + listItemArray: [], + data: { + link: {} + }, + config: require('../../patternlab-config.json'), + package: {} + }; + + // patch the pattern source so the pattern assembler can correctly determine + // the "subdir" + fpl.config.paths.source.patterns = testPatternsPath; + + return fpl; + } +}; From 0398e4277ea64b6e00e0e81bba79e70a183d2968 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Thu, 6 Oct 2016 12:42:19 -0500 Subject: [PATCH 3/9] It works! We factor out the pattern prefix regex and make it tolerant of more cases. --- core/lib/object_factory.js | 14 +++++++++++--- test/engine_handlebars_tests.js | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/lib/object_factory.js b/core/lib/object_factory.js index a03e2b400..ff68a9e5b 100644 --- a/core/lib/object_factory.js +++ b/core/lib/object_factory.js @@ -3,6 +3,10 @@ var patternEngines = require('./pattern_engines'); var path = require('path'); var extend = require('util')._extend; +// patternPrefixMatcher is intended to match the leading maybe-underscore, +// zero or more digits, and maybe-dash at the beginning of a pattern file name we can hack them +// off and get at the good part. +var patternPrefixMatcher = /^_?(\d+-)?/; // Pattern properties @@ -22,7 +26,7 @@ var Pattern = function (relPath, data, patternlab) { this.jsonFileData = data || {}; // strip leading "00-" from the file name and flip tildes to dashes - this.patternBaseName = this.fileName.replace(/^\d*\-/, '').replace('~', '-'); // 'colors' + this.patternBaseName = this.fileName.replace(patternPrefixMatcher, '').replace('~', '-'); // 'colors' // Fancy name. No idea how this works. 'Colors' this.patternName = this.patternBaseName.split('-').reduce(function (val, working) { @@ -30,13 +34,13 @@ var Pattern = function (relPath, data, patternlab) { }, '').trim(); //this is the display name for the ui. strip numeric + hyphen prefixes // the top-level pattern group this pattern belongs to. 'atoms' - this.patternGroup = this.subdir.split(path.sep)[0].replace(/^\d*-/, ''); + this.patternGroup = this.subdir.split(path.sep)[0].replace(patternPrefixMatcher, ''); //00-atoms if needed this.patternType = this.subdir.split(path.sep)[0]; // the sub-group this pattern belongs to. - this.patternSubGroup = path.basename(this.subdir).replace(/^\d*-/, ''); // 'global' + this.patternSubGroup = path.basename(this.subdir).replace(patternPrefixMatcher, ''); // 'global' //00-colors if needed this.patternSubType = path.basename(this.subdir); @@ -52,6 +56,10 @@ var Pattern = function (relPath, data, patternlab) { // name of the pattern. UPDATE: this.key is now known as this.patternPartial this.patternPartial = this.patternGroup + '-' + this.patternBaseName; + // Let's calculate the verbose name ahead of time! We don't use path.sep here + // on purpose. This isn't a file name! + this.verbosePartial = this.subdir + '/' + this.fileName; + this.isPattern = true; this.isFlatPattern = this.patternGroup === this.patternSubGroup; this.patternState = ''; diff --git a/test/engine_handlebars_tests.js b/test/engine_handlebars_tests.js index c52548bc5..fb7be779b 100644 --- a/test/engine_handlebars_tests.js +++ b/test/engine_handlebars_tests.js @@ -199,7 +199,7 @@ exports['engine_handlebars'] = { pattern_assembler.process_pattern_recursive(testPatternPath, pl); //act - test.equals(testPattern.render(), 'Hello there!\nHere\'s the hidden atom: [This is the hidden atom]\n'); + test.equals(testPattern.render(), 'Here\'s the hidden atom: [I\'m the hidden atom\n]\n'); //assert // test.equals(patternlab.patterns.length, 1); From 74900ef4edfb948a23bdeabaf874bf4cd5faad3f Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Thu, 6 Oct 2016 13:05:17 -0500 Subject: [PATCH 4/9] more cleanup in hbs test --- test/engine_handlebars_tests.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/engine_handlebars_tests.js b/test/engine_handlebars_tests.js index fb7be779b..7d8872564 100644 --- a/test/engine_handlebars_tests.js +++ b/test/engine_handlebars_tests.js @@ -200,11 +200,6 @@ exports['engine_handlebars'] = { //act test.equals(testPattern.render(), 'Here\'s the hidden atom: [I\'m the hidden atom\n]\n'); - - //assert - // test.equals(patternlab.patterns.length, 1); - // test.equals(patternlab.partials['test-bar'] != undefined, true); - // test.equals(patternlab.partials['test-bar'], 'bar'); test.done(); } }; From cdeab805ef412ff48d1e2c45b1ff6fff95a70ca1 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Thu, 6 Oct 2016 13:05:27 -0500 Subject: [PATCH 5/9] add matching underscore test --- test/engine_underscore_tests.js | 20 +++++++++++++++++++ .../00-atoms/00-global/_00-hidden.html | 1 + .../00-global/00-hidden-pattern-tester.html | 1 + 3 files changed, 22 insertions(+) create mode 100644 test/files/_underscore-test-patterns/00-atoms/00-global/_00-hidden.html create mode 100644 test/files/_underscore-test-patterns/00-molecules/00-global/00-hidden-pattern-tester.html diff --git a/test/engine_underscore_tests.js b/test/engine_underscore_tests.js index 06583de00..9f3f7fdb4 100644 --- a/test/engine_underscore_tests.js +++ b/test/engine_underscore_tests.js @@ -83,6 +83,26 @@ exports['engine_underscore'] = { // test test.equals(underscoreEngine.findPartial("<%= _.renderNamedPartial('molecules-details', obj) %>"), 'molecules-details'); test.done(); + }, + 'hidden underscore patterns can be called by their nice names' : function(test){ + const util = require('./util/test_utils.js'); + + //arrange + const testPatternsPath = path.resolve(__dirname, 'files', '_underscore-test-patterns'); + const pl = util.fakePatternLab(testPatternsPath); + var pattern_assembler = new pa(); + + var hiddenPatternPath = path.join('00-atoms', '00-global', '_00-hidden.html'); + var hiddenPattern = pattern_assembler.process_pattern_iterative(hiddenPatternPath, pl); + pattern_assembler.process_pattern_recursive(hiddenPatternPath, pl); + + var testPatternPath = path.join('00-molecules', '00-global', '00-hidden-pattern-tester.html'); + var testPattern = pattern_assembler.process_pattern_iterative(testPatternPath, pl); + pattern_assembler.process_pattern_recursive(testPatternPath, pl); + + //act + test.equals(testPattern.render(), 'Here\'s the hidden atom: [I\'m the hidden atom\n]\n'); + test.done(); } }; diff --git a/test/files/_underscore-test-patterns/00-atoms/00-global/_00-hidden.html b/test/files/_underscore-test-patterns/00-atoms/00-global/_00-hidden.html new file mode 100644 index 000000000..b2c93a13e --- /dev/null +++ b/test/files/_underscore-test-patterns/00-atoms/00-global/_00-hidden.html @@ -0,0 +1 @@ +I'm the hidden atom diff --git a/test/files/_underscore-test-patterns/00-molecules/00-global/00-hidden-pattern-tester.html b/test/files/_underscore-test-patterns/00-molecules/00-global/00-hidden-pattern-tester.html new file mode 100644 index 000000000..fe3beef68 --- /dev/null +++ b/test/files/_underscore-test-patterns/00-molecules/00-global/00-hidden-pattern-tester.html @@ -0,0 +1 @@ +Here's the hidden atom: [<%=_.renderNamedPartial('atoms-hidden', obj)%>] From 21728159a469b924e13af9ecf2132727bea51f4f Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Sat, 8 Oct 2016 06:35:36 -0500 Subject: [PATCH 6/9] finish merge with dev --- Gruntfile.js | 2 +- test/parameter_hunter_tests.js | 541 ++++++++++++++-------------- test/pattern_engines_tests.js | 308 ++++++++-------- test/patternlab_tests.js | 24 +- test/pseudopattern_hunter_tests.js | 112 +++--- test/style_modifier_hunter_tests.js | 167 ++++----- 6 files changed, 576 insertions(+), 578 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 63561c9ca..88c30ea75 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -21,7 +21,7 @@ module.exports = function (grunt) { }, tape: { options: { - pretty: true, + pretty: false, output: 'console' }, files: ['test/*_tests.js'] diff --git a/test/parameter_hunter_tests.js b/test/parameter_hunter_tests.js index 7db9ec85d..092f44428 100644 --- a/test/parameter_hunter_tests.js +++ b/test/parameter_hunter_tests.js @@ -1,350 +1,345 @@ -(function () { - "use strict"; - - var ph = require('../core/lib/parameter_hunter'); - - //setup current pattern from what we would have during execution - function currentPatternClosure() { - return { - "relPath": "02-organisms/02-comments/01-sticky-comment.mustache", - "fileName": "01-sticky-comment", - "subdir": "02-organisms/02-comments", - "name": "02-organisms-02-comments-01-sticky-comment", - "patternBaseName": "sticky-comment", - "patternLink": "02-organisms-02-comments-01-sticky-comment/02-organisms-02-comments-01-sticky-comment.html", - "patternGroup": "organisms", - "patternSubGroup": "comments", - "flatPatternPath": "02-organisms-02-comments", - "patternPartial": "organisms-sticky-comment", - "template": "{{> molecules-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}", - "extendedTemplate": "{{> molecules-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}", - "parameteredPartials": [ - "{{> molecules-single-comment(description: 'We are all in the gutter, but some of us are looking at the stars.') }}", - "{{> molecules-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}" - ] - }; - } - - function patternlabClosure() { - return { - patterns: [ - { - "relPath": "01-molecules/06-components/02-single-comment.mustache", - "fileName": "02-single-comment", - "subdir": "01-molecules/06-components", - "name": "01-molecules-06-components-02-single-comment", - "patternBaseName": "single-comment", - "patternLink": "01-molecules-06-components-02-single-comment/01-molecules-06-components-02-single-comment.html", - "patternGroup": "molecules", - "patternSubGroup": "components", - "flatPatternPath": "01-molecules-06-components", - "patternPartial": "molecules-single-comment", - "template": "

{{description}}

", - "extendedTemplate": "

{{description}}

" - } - ], - config: { - debug: false - }, - data: { - description: 'Not a quote from a smart man' - }, - partials: {} - } +"use strict"; + +var tap = require('tap'); + +var ph = require('../core/lib/parameter_hunter'); + +//setup current pattern from what we would have during execution +function currentPatternClosure() { + return { + "relPath": "02-organisms/02-comments/01-sticky-comment.mustache", + "fileName": "01-sticky-comment", + "subdir": "02-organisms/02-comments", + "name": "02-organisms-02-comments-01-sticky-comment", + "patternBaseName": "sticky-comment", + "patternLink": "02-organisms-02-comments-01-sticky-comment/02-organisms-02-comments-01-sticky-comment.html", + "patternGroup": "organisms", + "patternSubGroup": "comments", + "flatPatternPath": "02-organisms-02-comments", + "patternPartial": "organisms-sticky-comment", + "template": "{{> molecules-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}", + "extendedTemplate": "{{> molecules-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}", + "parameteredPartials": [ + "{{> molecules-single-comment(description: 'We are all in the gutter, but some of us are looking at the stars.') }}", + "{{> molecules-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}" + ] }; - - exports['parameter_hunter'] = { - 'parameter hunter finds and extends templates' : function(test){ - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); - - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

A life is like a garden. Perfect moments can be had, but not preserved, except in memory.

'); - - test.done(); +} + +function patternlabClosure() { + return { + patterns: [ + { + "relPath": "01-molecules/06-components/02-single-comment.mustache", + "fileName": "02-single-comment", + "subdir": "01-molecules/06-components", + "name": "01-molecules-06-components-02-single-comment", + "patternBaseName": "single-comment", + "patternLink": "01-molecules-06-components-02-single-comment/01-molecules-06-components-02-single-comment.html", + "patternGroup": "molecules", + "patternSubGroup": "components", + "flatPatternPath": "01-molecules-06-components", + "patternPartial": "molecules-single-comment", + "template": "

{{description}}

", + "extendedTemplate": "

{{description}}

" + } + ], + config: { + debug: false + }, + data: { + description: 'Not a quote from a smart man' }, + partials: {} + } +}; - 'parameter hunter finds and extends templates with mixed parameter and global data' : function(test){ - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); +tap.test('parameter hunter finds and extends templates', function(test) { + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - patternlab.patterns[0].template = "

{{foo}}

{{description}}

"; - patternlab.patterns[0].extendedTemplate = patternlab.patterns[0].template; - patternlab.data.foo = 'Bar'; - patternlab.data.description = 'Baz'; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

A life is like a garden. Perfect moments can be had, but not preserved, except in memory.

'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

Bar

A life is like a garden. Perfect moments can be had, but not preserved, except in memory.

'); + test.end(); +}); - test.done(); - }, +tap.test('parameter hunter finds and extends templates with mixed parameter and global data', function(test) { + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - 'parameter hunter finds and extends templates with verbose partials' : function(test){ - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + patternlab.patterns[0].template = "

{{foo}}

{{description}}

"; + patternlab.patterns[0].extendedTemplate = patternlab.patterns[0].template; + patternlab.data.foo = 'Bar'; + patternlab.data.description = 'Baz'; - currentPattern.template = "{{> 01-molecules/06-components/02-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = "{{> 01-molecules/06-components/02-single-comment(description: 'We are all in the gutter, but some of us are looking at the stars.') }}"; - currentPattern.parameteredPartials[1] = currentPattern.template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

Bar

A life is like a garden. Perfect moments can be had, but not preserved, except in memory.

'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

A life is like a garden. Perfect moments can be had, but not preserved, except in memory.

'); + test.end(); +}); - test.done(); - }, +tap.test('parameter hunter finds and extends templates with verbose partials', function(test) { + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - 'parameter hunter finds and extends templates with fully-pathed partials' : function(test){ - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> 01-molecules/06-components/02-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = "{{> 01-molecules/06-components/02-single-comment(description: 'We are all in the gutter, but some of us are looking at the stars.') }}"; + currentPattern.parameteredPartials[1] = currentPattern.template; - currentPattern.template = "{{> 01-molecules/06-components/02-single-comment.mustache(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = "{{> 01-molecules/06-components/02-single-comment.mustache(description: 'We are all in the gutter, but some of us are looking at the stars.') }}"; - currentPattern.parameteredPartials[1] = currentPattern.template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

A life is like a garden. Perfect moments can be had, but not preserved, except in memory.

'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

A life is like a garden. Perfect moments can be had, but not preserved, except in memory.

'); + test.end(); +}); - test.done(); - }, +tap.test('parameter hunter finds and extends templates with fully-pathed partials', function(test) { + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - //previous tests were for unquoted parameter keys and single-quoted values. - //test other quoting options. - 'parameter hunter parses parameters with unquoted keys and unquoted values' : function(test){ - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> 01-molecules/06-components/02-single-comment.mustache(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = "{{> 01-molecules/06-components/02-single-comment.mustache(description: 'We are all in the gutter, but some of us are looking at the stars.') }}"; + currentPattern.parameteredPartials[1] = currentPattern.template; - currentPattern.template = "{{> molecules-single-comment(description: true) }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

A life is like a garden. Perfect moments can be had, but not preserved, except in memory.

'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true

'); + test.end(); +}); - test.done(); - }, +//previous tests were for unquoted parameter keys and single-quoted values. +//test other quoting options. +tap.test('parameter hunter parses parameters with unquoted keys and unquoted values', function(test) { + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - 'parameter hunter parses parameters with unquoted keys and double-quoted values' : function(test){ - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> molecules-single-comment(description: true) }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - currentPattern.template = "{{> molecules-single-comment(description: \"true\") }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

true

'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true

'); + test.end(); +}); - test.done(); - }, +tap.test('parameter hunter parses parameters with unquoted keys and double-quoted values', function(test) { + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - 'parameter hunter parses parameters with single-quoted keys and unquoted values' : function(test){ - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> molecules-single-comment(description: \"true\") }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - currentPattern.template = "{{> molecules-single-comment('description': true) }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

true

'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true

'); + test.end(); +}); - test.done(); - }, +tap.test('parameter hunter parses parameters with single-quoted keys and unquoted values', function(test) { + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - 'parameter hunter parses parameters with single-quoted keys and single-quoted values wrapping internal escaped single-quotes' : function(test){ - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> molecules-single-comment('description': true) }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - currentPattern.template = "{{> molecules-single-comment('description': 'true not,\\'true\\'') }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

true

'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true not,'true'

'); + test.end(); +}); - test.done(); - }, +tap.test('parameter hunter parses parameters with single-quoted keys and single-quoted values wrapping internal escaped single-quotes', function(test) { + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - 'parameter hunter parses parameters with single-quoted keys and double-quoted values wrapping internal single-quotes' : function(test){ - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> molecules-single-comment('description': 'true not,\\'true\\'') }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - currentPattern.template = "{{> molecules-single-comment('description': \"true not:'true'\") }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

true not,'true'

'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true not:'true'

'); + test.end(); +}); - test.done(); - }, +tap.test('parameter hunter parses parameters with single-quoted keys and double-quoted values wrapping internal single-quotes', function(test) { + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - 'parameter hunter parses parameters with double-unquoted keys and unquoted values' : function(test){ - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> molecules-single-comment('description': \"true not:'true'\") }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - currentPattern.template = "{{> molecules-single-comment(\"description\": true) }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

true not:'true'

'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true

'); + test.end(); +}); - test.done(); - }, +tap.test('parameter hunter parses parameters with double-unquoted keys and unquoted values', function(test) { + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - 'parameter hunter parses parameters with double-quoted keys and single-quoted values wrapping internal double-quotes' : function(test){ - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> molecules-single-comment(\"description\": true) }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - currentPattern.template = "{{> molecules-single-comment(\"description\": 'true not{\"true\"') }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

true

'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true not{"true"

'); + test.end(); +}); - test.done(); - }, +tap.test('parameter hunter parses parameters with double-quoted keys and single-quoted values wrapping internal double-quotes', function(test) { + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - 'parameter hunter parses parameters with double-quoted keys and double-quoted values wrapping internal escaped double-quotes' : function(test){ - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> molecules-single-comment(\"description\": 'true not{\"true\"') }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - currentPattern.template = "{{> molecules-single-comment(\"description\": \"true not}\\\"true\\\"\") }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

true not{"true"

'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true not}"true"

'); + test.end(); +}); - test.done(); - }, +tap.test('parameter hunter parses parameters with double-quoted keys and double-quoted values wrapping internal escaped double-quotes', function(test) { + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - 'parameter hunter parses parameters with combination of quoting schemes for keys and values' : function(test){ - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> molecules-single-comment(\"description\": \"true not}\\\"true\\\"\") }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - currentPattern.template = "{{> molecules-single-comment(description: true, 'foo': false, \"bar\": false, 'single': true, 'singlesingle': 'true', 'singledouble': \"true\", \"double\": true, \"doublesingle\": 'true', \"doubledouble\": \"true\") }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

true not}"true"

'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true

'); + test.end(); +}); - test.done(); - }, +tap.test('parameter hunter parses parameters with combination of quoting schemes for keys and values', function(test) { + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - 'parameter hunter parses parameters with values containing a closing parenthesis' : function(test){ - // From issue #291 https://github.com/pattern-lab/patternlab-node/issues/291 - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> molecules-single-comment(description: true, 'foo': false, \"bar\": false, 'single': true, 'singlesingle': 'true', 'singledouble': \"true\", \"double\": true, \"doublesingle\": 'true', \"doubledouble\": \"true\") }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - currentPattern.template = "{{> molecules-single-comment(description: 'Hello ) World') }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

true

'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

Hello ) World

'); + test.end(); +}); - test.done(); - }, +tap.test('parameter hunter parses parameters with values containing a closing parenthesis', function(test) { + // From issue #291 https://github.com/pattern-lab/patternlab-node/issues/291 + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - 'parameter hunter parses parameters that follow a non-quoted value' : function(test){ - // From issue #291 https://github.com/pattern-lab/patternlab-node/issues/291 - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> molecules-single-comment(description: 'Hello ) World') }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - patternlab.patterns[0].template = "

{{foo}}

{{bar}}

"; - patternlab.patterns[0].extendedTemplate = patternlab.patterns[0].template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

Hello ) World

'); - currentPattern.template = "{{> molecules-single-comment(foo: true, bar: \"Hello World\") }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + test.end(); +}); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true

Hello World

'); +tap.test('parameter hunter parses parameters that follow a non-quoted value', function(test) { + // From issue #291 https://github.com/pattern-lab/patternlab-node/issues/291 + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - test.done(); - }, + patternlab.patterns[0].template = "

{{foo}}

{{bar}}

"; + patternlab.patterns[0].extendedTemplate = patternlab.patterns[0].template; - 'parameter hunter parses parameters whose keys contain escaped quotes' : function(test){ - // From issue #291 https://github.com/pattern-lab/patternlab-node/issues/291 - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> molecules-single-comment(foo: true, bar: \"Hello World\") }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - patternlab.patterns[0].template = "

{{ silly'key }}

{{bar}}

{{ another\"silly-key }}

"; - patternlab.patterns[0].extendedTemplate = patternlab.patterns[0].template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

true

Hello World

'); - currentPattern.template = "{{> molecules-single-comment('silly\\\'key': true, bar: \"Hello World\", \"another\\\"silly-key\": 42 ) }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + test.end(); +}); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true

Hello World

42

'); +tap.test('parameter hunter parses parameters whose keys contain escaped quotes', function(test) { + // From issue #291 https://github.com/pattern-lab/patternlab-node/issues/291 + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - test.done(); - }, + patternlab.patterns[0].template = "

{{ silly'key }}

{{bar}}

{{ another\"silly-key }}

"; + patternlab.patterns[0].extendedTemplate = patternlab.patterns[0].template; - 'parameter hunter skips malformed parameters' : function(test){ - // From issue #291 https://github.com/pattern-lab/patternlab-node/issues/291 - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.template = "{{> molecules-single-comment('silly\\\'key': true, bar: \"Hello World\", \"another\\\"silly-key\": 42 ) }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - patternlab.patterns[0].template = "

{{foo}}

"; - patternlab.patterns[0].extendedTemplate = patternlab.patterns[0].template; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

true

Hello World

42

'); - currentPattern.abspath = __filename; - currentPattern.template = "{{> molecules-single-comment( missing-val: , : missing-key, : , , foo: \"Hello World\") }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + test.end(); +}); - console.log('\nPattern Lab should catch JSON.parse() errors and output useful debugging information...'); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

'); +tap.test('parameter hunter skips malformed parameters', function(test) { + // From issue #291 https://github.com/pattern-lab/patternlab-node/issues/291 + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - test.done(); - }, + patternlab.patterns[0].template = "

{{foo}}

"; + patternlab.patterns[0].extendedTemplate = patternlab.patterns[0].template; - 'parameter hunter parses parameters containing html tags' : function(test){ - // From issue #145 https://github.com/pattern-lab/patternlab-node/issues/145 - var currentPattern = currentPatternClosure(); - var patternlab = patternlabClosure(); - var parameter_hunter = new ph(); + currentPattern.abspath = __filename; + currentPattern.template = "{{> molecules-single-comment( missing-val: , : missing-key, : , , foo: \"Hello World\") }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - patternlab.patterns[0].template = "

{{{ tag1 }}}

{{{ tag2 }}}

{{{ tag3 }}}

"; - patternlab.patterns[0].extendedTemplate = patternlab.patterns[0].template; + console.log('\nPattern Lab should catch JSON.parse() errors and output useful debugging information...'); + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

'); - currentPattern.template = "{{> molecules-single-comment(tag1: 'Single-quoted', tag2: \"Double-quoted\", tag3: 'With attributes') }}"; - currentPattern.extendedTemplate = currentPattern.template; - currentPattern.parameteredPartials[0] = currentPattern.template; + test.end(); +}); - parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

Single-quoted

Double-quoted

With attributes

'); +tap.test('parameter hunter parses parameters containing html tags', function(test){ + // From issue #145 https://github.com/pattern-lab/patternlab-node/issues/145 + var currentPattern = currentPatternClosure(); + var patternlab = patternlabClosure(); + var parameter_hunter = new ph(); - test.done(); - } + patternlab.patterns[0].template = "

{{{ tag1 }}}

{{{ tag2 }}}

{{{ tag3 }}}

"; + patternlab.patterns[0].extendedTemplate = patternlab.patterns[0].template; + currentPattern.template = "{{> molecules-single-comment(tag1: 'Single-quoted', tag2: \"Double-quoted\", tag3: 'With attributes') }}"; + currentPattern.extendedTemplate = currentPattern.template; + currentPattern.parameteredPartials[0] = currentPattern.template; - }; + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, '

Single-quoted

Double-quoted

With attributes

'); -}()); + test.end(); +}); diff --git a/test/pattern_engines_tests.js b/test/pattern_engines_tests.js index fbf97c74c..dc55b6cf0 100644 --- a/test/pattern_engines_tests.js +++ b/test/pattern_engines_tests.js @@ -1,164 +1,164 @@ -(function () { - 'use strict'; - - var patternEngines = require('../core/lib/pattern_engines'); - var Pattern = require('../core/lib/object_factory').Pattern; - - // the mustache test pattern, stolen from object_factory unit tests - var mustacheTestPattern = new Pattern('source/_patterns/00-atoms/00-global/00-colors-alt.mustache', {d: 123}); - var mustacheTestPseudoPatternBasePattern = new Pattern('source/_patterns/04-pages/00-homepage.mustache', {d: 123}); - var mustacheTestPseudoPattern = new Pattern('source/_patterns/04-pages/00-homepage~emergency.json', {d: 123}); - mustacheTestPseudoPattern.isPseudoPattern = true; - mustacheTestPseudoPattern.basePattern = mustacheTestPseudoPatternBasePattern; - var engineNames = Object.keys(patternEngines); - - - exports['patternEngines support functions'] = { - 'getEngineNameForPattern returns "mustache" from test pattern': function (test) { - var engineName = patternEngines.getEngineNameForPattern(mustacheTestPattern); - test.equals(engineName, 'mustache'); - test.done(); - }, - 'getEngineNameForPattern returns "mustache" for a plain string template as a backwards compatibility measure': function (test) { - test.expect(1); - test.equals(patternEngines.getEngineNameForPattern('plain text string'), 'mustache'); - test.done(); - }, - 'getEngineNameForPattern returns "mustache" for an artificial empty template': function (test) { - test.expect(1); - var emptyPattern = Pattern.createEmpty(); - test.equals(patternEngines.getEngineNameForPattern(emptyPattern), 'mustache'); - test.done(); - }, - 'getEngineForPattern returns a reference to the mustache engine from test pattern': function (test) { - var engine = patternEngines.getEngineForPattern(mustacheTestPattern); - test.equals(engine, patternEngines.mustache); - test.done(); - }, - 'getEngineForPattern returns a reference to the mustache engine from test pseudo-pattern': function (test) { - var engine = patternEngines.getEngineForPattern(mustacheTestPseudoPattern); - test.equals(engine, patternEngines.mustache); - test.done(); - }, - 'isPseudoPatternJSON correctly identifies pseudo-pattern JSON filenames': function(test) { - // each test case - var filenames = { - '00-homepage~emergency.json': true, - '~emergency.json': true, - '00-homepage~emergency.js': false, - '00-homepage-emergency.js': false, - '00-homepage.hbs': false, - '00-homepage.json': false, - 'greatpic.jpg': false - }; - // expect one test per test case - test.expect(Object.keys(filenames).length); - - // loop over each test case and test it - Object.keys(filenames).forEach(function (filename) { - var expectedResult = filenames[filename], - actualResult = patternEngines.isPseudoPatternJSON(filename), - testMessage = 'isPseudoPatternJSON should return ' + expectedResult + ' for ' + filename; - test.strictEqual(actualResult, expectedResult, testMessage); - }); - - // done - test.done(); - }, - 'isPatternFile correctly identifies pattern files and rejects non-pattern files': function(test){ - // each test case - var filenames = { - '00-comment-thread.mustache': true, - '00-comment-thread.fakeextthatdoesntexist': false, - '00-comment-thread': false, - '_00-comment-thread.mustache': true, - '.00-comment-thread.mustache': false, - '00-comment-thread.json': false, - '00-homepage~emergency.json': true - }; - // expect one test per test case - test.expect(Object.keys(filenames).length); - - // loop over each test case and test it - Object.keys(filenames).forEach(function (filename) { - var expectedResult = filenames[filename], - actualResult = patternEngines.isPatternFile(filename), - testMessage = 'isPatternFile should return ' + expectedResult + ' for ' + filename; - test.strictEqual(actualResult, expectedResult, testMessage); - }); - - // done - test.done(); - } +'use strict'; + +var tap = require('tap'); + +var patternEngines = require('../core/lib/pattern_engines'); +var Pattern = require('../core/lib/object_factory').Pattern; + +// the mustache test pattern, stolen from object_factory unit tests +var mustacheTestPattern = new Pattern('source/_patterns/00-atoms/00-global/00-colors-alt.mustache', {d: 123}); +var mustacheTestPseudoPatternBasePattern = new Pattern('source/_patterns/04-pages/00-homepage.mustache', {d: 123}); +var mustacheTestPseudoPattern = new Pattern('source/_patterns/04-pages/00-homepage~emergency.json', {d: 123}); +mustacheTestPseudoPattern.isPseudoPattern = true; +mustacheTestPseudoPattern.basePattern = mustacheTestPseudoPatternBasePattern; +var engineNames = Object.keys(patternEngines); + +tap.test('getEngineNameForPattern returns "mustache" from test pattern', function (test) { + var engineName = patternEngines.getEngineNameForPattern(mustacheTestPattern); + test.equals(engineName, 'mustache'); + test.end(); +}); + +tap.test('getEngineNameForPattern returns "mustache" for a plain string template as a backwards compatibility measure', function (test) { + test.plan(1); + test.equals(patternEngines.getEngineNameForPattern('plain text string'), 'mustache'); + test.end(); +}); + +tap.test('getEngineNameForPattern returns "mustache" for an artificial empty template', function (test) { + test.plan(1); + var emptyPattern = Pattern.createEmpty(); + test.equals(patternEngines.getEngineNameForPattern(emptyPattern), 'mustache'); + test.end(); +}); + +tap.test('getEngineForPattern returns a reference to the mustache engine from test pattern', function (test) { + var engine = patternEngines.getEngineForPattern(mustacheTestPattern); + test.equals(engine, patternEngines.mustache); + test.end(); +}); + +tap.test('getEngineForPattern returns a reference to the mustache engine from test pseudo-pattern', function (test) { + var engine = patternEngines.getEngineForPattern(mustacheTestPseudoPattern); + test.equals(engine, patternEngines.mustache); + test.end(); +}); + +tap.test('isPseudoPatternJSON correctly identifies pseudo-pattern JSON filenames', function(test) { + // each test case + var filenames = { + '00-homepage~emergency.json': true, + '~emergency.json': true, + '00-homepage~emergency.js': false, + '00-homepage-emergency.js': false, + '00-homepage.hbs': false, + '00-homepage.json': false, + 'greatpic.jpg': false + }; + // expect one test per test case + test.plan(Object.keys(filenames).length); + + // loop over each test case and test it + Object.keys(filenames).forEach(function (filename) { + var expectedResult = filenames[filename], + actualResult = patternEngines.isPseudoPatternJSON(filename), + testMessage = 'isPseudoPatternJSON should return ' + expectedResult + ' for ' + filename; + test.strictEqual(actualResult, expectedResult, testMessage); + }); + + // done + test.end(); +}); + +tap.test('isPatternFile correctly identifies pattern files and rejects non-pattern files', function(test){ + // each test case + var filenames = { + '00-comment-thread.mustache': true, + '00-comment-thread.fakeextthatdoesntexist': false, + '00-comment-thread': false, + '_00-comment-thread.mustache': true, + '.00-comment-thread.mustache': false, + '00-comment-thread.json': false, + '00-homepage~emergency.json': true }; + // expect one test per test case + test.plan(Object.keys(filenames).length); + + // loop over each test case and test it + Object.keys(filenames).forEach(function (filename) { + var expectedResult = filenames[filename], + actualResult = patternEngines.isPatternFile(filename), + testMessage = 'isPatternFile should return ' + expectedResult + ' for ' + filename; + test.strictEqual(actualResult, expectedResult, testMessage); + }); + + // done + test.end(); +}); + +// testProps() utility function: given an object, and a hash of expected +// 'property name':'property type' pairs, verify that the object contains each +// expected property, and that each property is of the expected type. +function testProps(object, propTests, test) { - // testProps() utility function: given an object, and a hash of expected - // 'property name':'property type' pairs, verify that the object contains each - // expected property, and that each property is of the expected type. - function testProps(object, propTests, test) { - - // function to test each expected property is present and the correct type - function testProp(propName, types) { - - var possibleTypes; - - // handle "types" being a string or an array of strings - if (types instanceof Array) { - possibleTypes = types; - } else { - // "types" is just a single string, load it into an array; the rest of - // the code expects it! - possibleTypes = [types]; - } - - var isOneOfTheseTypes = possibleTypes.map(function (type) { - return typeof object[propName] === type; - }).reduce(function(isPrevType, isCurrentType) { - return isPrevType || isCurrentType; - }); - - test.ok(object.hasOwnProperty(propName), '"' + propName + '" prop should be present'); - test.ok(isOneOfTheseTypes, '"' + propName + '" prop should be one of types ' + possibleTypes); + // function to test each expected property is present and the correct type + function testProp(propName, types) { + + var possibleTypes; + + // handle "types" being a string or an array of strings + if (types instanceof Array) { + possibleTypes = types; + } else { + // "types" is just a single string, load it into an array; the rest of + // the code expects it! + possibleTypes = [types]; } - // go over each property test and run it - Object.keys(propTests).forEach(function (propName) { - var propType = propTests[propName]; - testProp(propName, propType); + var isOneOfTheseTypes = possibleTypes.map(function (type) { + return typeof object[propName] === type; + }).reduce(function(isPrevType, isCurrentType) { + return isPrevType || isCurrentType; }); + + test.ok(object.hasOwnProperty(propName), '"' + propName + '" prop should be present'); + test.ok(isOneOfTheseTypes, '"' + propName + '" prop should be one of types ' + possibleTypes); } - exports['patternEngines initialization'] = { - 'patternEngines object contains at least the default mustache engine': function (test) { - test.expect(1); - test.ok(patternEngines.hasOwnProperty('mustache')); - test.done(); - }, - 'patternEngines object reports that it supports the .mustache extension': function (test) { - test.expect(1); - test.ok(patternEngines.isFileExtensionSupported('.mustache')); - test.done(); - } - }; + // go over each property test and run it + Object.keys(propTests).forEach(function (propName) { + var propType = propTests[propName]; + testProp(propName, propType); + }); +} + +tap.test('patternEngines object contains at least the default mustache engine', function (test) { + test.plan(1); + test.ok(patternEngines.hasOwnProperty('mustache')); + test.end(); +}); + +tap.test('patternEngines object reports that it supports the .mustache extension', function (test) { + test.plan(1); + test.ok(patternEngines.isFileExtensionSupported('.mustache')); + test.end(); +}); + +// make one big test group for each pattern engine +engineNames.forEach(function (engineName) { + tap.test('engine ' + engineName + ' contains expected properties and methods', function (test) { + + var propertyTests = { + 'engine': ['object', 'function'], + 'engineName': 'string', + 'engineFileExtension': 'string', + 'renderPattern': 'function', + 'findPartials': 'function' + }; - // make one big test group for each pattern engine - engineNames.forEach(function (engineName) { - exports[engineName + ' patternEngine'] = { - 'engine contains expected properties and methods': function (test) { - - var propertyTests = { - 'engine': ['object', 'function'], - 'engineName': 'string', - 'engineFileExtension': 'string', - 'renderPattern': 'function', - 'findPartials': 'function' - }; - - test.expect(Object.keys(propertyTests).length * 2); - testProps(patternEngines[engineName], propertyTests, test); - test.done(); - } - }; + test.plan(Object.keys(propertyTests).length * 2); + testProps(patternEngines[engineName], propertyTests, test); + test.end(); }); +}); -})(); diff --git a/test/patternlab_tests.js b/test/patternlab_tests.js index b33144772..84eb81d2f 100644 --- a/test/patternlab_tests.js +++ b/test/patternlab_tests.js @@ -1,15 +1,15 @@ 'use strict'; -exports['test nodeunit'] = { - 'buildPatternData - should merge all JSON files in the data folder except listitems' : function(test){ - var fs = require('fs-extra'); - var plMain = require('../core/lib/patternlab'); - var data_dir = './test/files/_data/'; +var tap = require('tap'); - var dataResult = plMain.build_pattern_data(data_dir, fs); - test.equals(dataResult.data, "test"); - test.equals(dataResult.foo, "bar"); - test.equals(dataResult.test_list_item, undefined); - test.done(); - } -}; +tap.test('buildPatternData - should merge all JSON files in the data folder except listitems', function(test){ + var fs = require('fs-extra'); + var plMain = require('../core/lib/patternlab'); + var data_dir = './test/files/_data/'; + + var dataResult = plMain.build_pattern_data(data_dir, fs); + test.equals(dataResult.data, "test"); + test.equals(dataResult.foo, "bar"); + test.equals(dataResult.test_list_item, undefined); + test.end(); +}); diff --git a/test/pseudopattern_hunter_tests.js b/test/pseudopattern_hunter_tests.js index dd9b922ce..80bce5b61 100644 --- a/test/pseudopattern_hunter_tests.js +++ b/test/pseudopattern_hunter_tests.js @@ -1,5 +1,7 @@ "use strict"; +var tap = require('tap'); + var path = require('path'); var pha = require('../core/lib/pseudopattern_hunter'); var pa = require('../core/lib/pattern_assembler'); @@ -30,59 +32,57 @@ function stubPatternlab() { return pl; } -exports['pseudopattern_hunter'] = { - 'pseudpattern found and added as a pattern' : function (test) { - //arrange - var pl = stubPatternlab(); - - var atomPattern = new Pattern('00-test/03-styled-atom.mustache'); - atomPattern.template = fs.readFileSync(patterns_dir + '00-test/03-styled-atom.mustache', 'utf8'); - atomPattern.extendedTemplate = atomPattern.template; - atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); - - pattern_assembler.addPattern(atomPattern, pl); - - //act - var patternCountBefore = pl.patterns.length; - pseudopattern_hunter.find_pseudopatterns(atomPattern, pl); - - //assert - test.equals(patternCountBefore + 1, pl.patterns.length); - test.equals(pl.patterns[1].patternPartial, 'test-styled-atom-alt'); - test.equals(pl.patterns[1].extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), ' {{message}} '); - test.equals(JSON.stringify(pl.patterns[1].jsonFileData), JSON.stringify({"message": "alternateMessage"})); - test.equals(pl.patterns[1].patternLink, '00-test-03-styled-atom-alt' + path.sep + '00-test-03-styled-atom-alt.html'); - - test.done(); - }, - - 'pseudpattern variant includes stylePartials and parameteredPartials' : function (test) { - //arrange - var pl = stubPatternlab(); - - var atomPattern = new Pattern('00-test/03-styled-atom.mustache'); - atomPattern.template = fs.readFileSync(patterns_dir + '00-test/03-styled-atom.mustache', 'utf8'); - atomPattern.extendedTemplate = atomPattern.template; - atomPattern.stylePartials = atomPattern.findPartialsWithStyleModifiers(atomPattern); - atomPattern.parameteredPartials = atomPattern.findPartialsWithPatternParameters(atomPattern); - - var pseudoPattern = new Pattern('00-test/474-pseudomodifier.mustache'); - pseudoPattern.template = fs.readFileSync(patterns_dir + '00-test/474-pseudomodifier.mustache', 'utf8'); - pseudoPattern.extendedTemplate = atomPattern.template; - pseudoPattern.stylePartials = pseudoPattern.findPartialsWithStyleModifiers(pseudoPattern); - pseudoPattern.parameteredPartials = pseudoPattern.findPartialsWithPatternParameters(pseudoPattern); - - pattern_assembler.addPattern(atomPattern, pl); - pattern_assembler.addPattern(pseudoPattern, pl); - - //act - pseudopattern_hunter.find_pseudopatterns(pseudoPattern, pl); - - //assert - test.equals(pl.patterns[2].patternPartial, 'test-pseudomodifier-test'); - test.equals(pl.patterns[2].stylePartials, pseudoPattern.stylePartials); - test.equals(pl.patterns[2].parameteredPartials, pseudoPattern.parameteredPartials); - - test.done(); - } -}; +tap.test('pseudpattern found and added as a pattern', function (test) { + //arrange + var pl = stubPatternlab(); + + var atomPattern = new Pattern('00-test/03-styled-atom.mustache'); + atomPattern.template = fs.readFileSync(patterns_dir + '00-test/03-styled-atom.mustache', 'utf8'); + atomPattern.extendedTemplate = atomPattern.template; + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); + + pattern_assembler.addPattern(atomPattern, pl); + + //act + var patternCountBefore = pl.patterns.length; + pseudopattern_hunter.find_pseudopatterns(atomPattern, pl); + + //assert + test.equals(patternCountBefore + 1, pl.patterns.length); + test.equals(pl.patterns[1].patternPartial, 'test-styled-atom-alt'); + test.equals(pl.patterns[1].extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), ' {{message}} '); + test.equals(JSON.stringify(pl.patterns[1].jsonFileData), JSON.stringify({"message": "alternateMessage"})); + test.equals(pl.patterns[1].patternLink, '00-test-03-styled-atom-alt' + path.sep + '00-test-03-styled-atom-alt.html'); + + test.end(); +}); + +tap.test('pseudpattern variant includes stylePartials and parameteredPartials', function (test) { + //arrange + var pl = stubPatternlab(); + + var atomPattern = new Pattern('00-test/03-styled-atom.mustache'); + atomPattern.template = fs.readFileSync(patterns_dir + '00-test/03-styled-atom.mustache', 'utf8'); + atomPattern.extendedTemplate = atomPattern.template; + atomPattern.stylePartials = atomPattern.findPartialsWithStyleModifiers(atomPattern); + atomPattern.parameteredPartials = atomPattern.findPartialsWithPatternParameters(atomPattern); + + var pseudoPattern = new Pattern('00-test/474-pseudomodifier.mustache'); + pseudoPattern.template = fs.readFileSync(patterns_dir + '00-test/474-pseudomodifier.mustache', 'utf8'); + pseudoPattern.extendedTemplate = atomPattern.template; + pseudoPattern.stylePartials = pseudoPattern.findPartialsWithStyleModifiers(pseudoPattern); + pseudoPattern.parameteredPartials = pseudoPattern.findPartialsWithPatternParameters(pseudoPattern); + + pattern_assembler.addPattern(atomPattern, pl); + pattern_assembler.addPattern(pseudoPattern, pl); + + //act + pseudopattern_hunter.find_pseudopatterns(pseudoPattern, pl); + + //assert + test.equals(pl.patterns[2].patternPartial, 'test-pseudomodifier-test'); + test.equals(pl.patterns[2].stylePartials, pseudoPattern.stylePartials); + test.equals(pl.patterns[2].parameteredPartials, pseudoPattern.parameteredPartials); + + test.end(); +}); diff --git a/test/style_modifier_hunter_tests.js b/test/style_modifier_hunter_tests.js index 4e0d7ddf3..e1a999a8b 100644 --- a/test/style_modifier_hunter_tests.js +++ b/test/style_modifier_hunter_tests.js @@ -1,86 +1,89 @@ "use strict"; +var tap = require('tap'); + 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: '
' - }; - - var style_modifier_hunter = new smh(); - - //act - style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl); - - //assert - test.equals(pattern.extendedTemplate, '
'); - 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: '
' - }; - - var style_modifier_hunter = new smh(); - - //act - style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl); - - //assert - test.equals(pattern.extendedTemplate, '
'); - test.done(); - }, - 'replaces multiple style modifiers' : function(test){ - //arrange - var pl = {}; - pl.partials = {}; - pl.config = {}; - pl.config.debug = false; - - var pattern = { - extendedTemplate: '
' - }; - - var style_modifier_hunter = new smh(); - - //act - style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar|baz|dum}}', pl); - - //assert - test.equals(pattern.extendedTemplate, '
'); - 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: '
' - }; - - var style_modifier_hunter = new smh(); - - //act - style_modifier_hunter.consume_style_modifier(pattern, '{{> partial}}', pl); - - //assert - test.equals(pattern.extendedTemplate, '
'); - test.done(); - } -}; +tap.test('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: '
' + }; + + var style_modifier_hunter = new smh(); + + //act + style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl); + + //assert + test.equals(pattern.extendedTemplate, '
'); + test.end(); +}); + +tap.test('replaces style modifiers with spaces in the syntax', function(test){ + //arrange + var pl = {}; + pl.partials = {}; + pl.config = {}; + pl.config.debug = false; + + var pattern = { + extendedTemplate: '
' + }; + + var style_modifier_hunter = new smh(); + + //act + style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl); + + //assert + test.equals(pattern.extendedTemplate, '
'); + test.end(); +}); + +tap.test('replaces multiple style modifiers', function(test){ + //arrange + var pl = {}; + pl.partials = {}; + pl.config = {}; + pl.config.debug = false; + + var pattern = { + extendedTemplate: '
' + }; + + var style_modifier_hunter = new smh(); + + //act + style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar|baz|dum}}', pl); + + //assert + test.equals(pattern.extendedTemplate, '
'); + test.end(); +}); + +tap.test('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: '
' + }; + + var style_modifier_hunter = new smh(); + + //act + style_modifier_hunter.consume_style_modifier(pattern, '{{> partial}}', pl); + + //assert + test.equals(pattern.extendedTemplate, '
'); + test.end(); +}); From a84292f81f363f4bf0c27e54598ac740644c2a3c Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Tue, 11 Oct 2016 07:46:53 -0500 Subject: [PATCH 7/9] removing nodeunit! --- Gruntfile.js | 8 ++------ package.json | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 88c30ea75..be14760e5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -16,9 +16,6 @@ module.exports = function (grunt) { dest: './core/lib/patternlab.js' } }, - nodeunit: { - all: ['test/*_tests.js'] - }, tape: { options: { pretty: false, @@ -37,13 +34,12 @@ module.exports = function (grunt) { // load all grunt tasks grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-eslint'); - grunt.loadNpmTasks('grunt-contrib-nodeunit'); grunt.loadNpmTasks('grunt-tape'); //travis CI task - grunt.registerTask('travis', ['nodeunit', 'tape', 'eslint']); + grunt.registerTask('travis', ['tape', 'eslint']); //to be run prior to releasing a version - grunt.registerTask('build', ['nodeunit', 'tape', 'eslint', 'concat']); + grunt.registerTask('build', ['tape', 'eslint', 'concat']); }; diff --git a/package.json b/package.json index f8c226666..de331975f 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ "devDependencies": { "grunt": "~1.0.1", "grunt-contrib-concat": "^1.0.1", - "grunt-contrib-nodeunit": "^1.0.0", "grunt-eslint": "^18.0.0", "grunt-tape": "^0.1.0", "tap": "^7.1.2" From d182f7da76d1757e90cf79f835342ed89a328c36 Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Tue, 11 Oct 2016 07:51:42 -0500 Subject: [PATCH 8/9] breaking a test to make sure travis picks it up now that nodeunit is outta the picture --- test/ui_builder_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ui_builder_tests.js b/test/ui_builder_tests.js index 3a111ffd8..12af775ef 100644 --- a/test/ui_builder_tests.js +++ b/test/ui_builder_tests.js @@ -242,7 +242,7 @@ tap.test('resetUIBuilderState - reset global objects', function (test) { //assert test.equals(patternlab.patternPaths.foo, undefined); test.equals(patternlab.viewAllPaths.bar, undefined); - test.equals(patternlab.patternTypes.length, 0); + test.equals(patternlab.patternTypes.length, 1); test.end(); }); From a7aa23b6a0132bb2affece4b93e1262e85767df2 Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Tue, 11 Oct 2016 07:58:35 -0500 Subject: [PATCH 9/9] reverting failure --- test/ui_builder_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ui_builder_tests.js b/test/ui_builder_tests.js index 12af775ef..3a111ffd8 100644 --- a/test/ui_builder_tests.js +++ b/test/ui_builder_tests.js @@ -242,7 +242,7 @@ tap.test('resetUIBuilderState - reset global objects', function (test) { //assert test.equals(patternlab.patternPaths.foo, undefined); test.equals(patternlab.viewAllPaths.bar, undefined); - test.equals(patternlab.patternTypes.length, 1); + test.equals(patternlab.patternTypes.length, 0); test.end(); });