From 077fc9e914f58740e10f73d6f93f299dc37152e2 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 31 Oct 2016 13:11:12 +0100 Subject: [PATCH] Add test cases for @block-partial issue in Handlebars engine https://github.com/geoffp/patternengine-node-handlebars/issues/3 --- test/engine_handlebars_tests.js | 39 +++++++++++++++++++ .../00-global/10-at-partial-block.hbs | 2 + .../00-global/10-call-at-partial-block.hbs | 3 ++ 3 files changed, 44 insertions(+) create mode 100644 test/files/_handlebars-test-patterns/00-atoms/00-global/10-at-partial-block.hbs create mode 100644 test/files/_handlebars-test-patterns/00-molecules/00-global/10-call-at-partial-block.hbs diff --git a/test/engine_handlebars_tests.js b/test/engine_handlebars_tests.js index cf1fa533e..748103582 100644 --- a/test/engine_handlebars_tests.js +++ b/test/engine_handlebars_tests.js @@ -222,3 +222,42 @@ tap.test('hidden handlebars patterns can be called by their nice names', functio test.equals(util.sanitized(testPattern.render()), util.sanitized('Here\'s the hidden atom: [I\'m the hidden atom\n]\n')); test.end(); }); + +tap.test('@partial-block template should render without throwing (@geoffp repo issue #3)', function(test) { + test.plan(1); + + var patternPath = path.join('00-atoms', '00-global', '10-at-partial-block.hbs'); + + // do all the normal processing of the pattern + var patternlab = new fakePatternLab(); + var assembler = new pa(); + var atPartialBlockPattern = assembler.process_pattern_iterative(patternPath, patternlab); + assembler.process_pattern_recursive(patternPath, patternlab); + + var results = '{{> @partial-block }}' + eol + 'It worked!' + eol; + test.equal(atPartialBlockPattern.render(), results); + test.end(); +}) + +tap.test('A template calling a @partial-block template should render correctly', function(test) { + test.plan(1); + + // pattern paths + var pattern1Path = path.join('00-atoms', '00-global', '10-at-partial-block.hbs'); + var pattern2Path = path.join('00-molecules', '00-global', '10-call-at-partial-block.hbs'); + + // set up environment + var patternlab = new fakePatternLab(); // environment + var assembler = new pa(); + + // do all the normal processing of the pattern + assembler.process_pattern_iterative(pattern1Path, patternlab); + var callAtPartialBlockPattern = assembler.process_pattern_iterative(pattern2Path, patternlab); + assembler.process_pattern_recursive(pattern1Path, patternlab); + assembler.process_pattern_recursive(pattern2Path, patternlab); + + // test + var results = 'Hello World!' + eol + 'It worked!' + eol; + test.equals(callAtPartialBlockPattern.render(), results); + test.end(); +}) diff --git a/test/files/_handlebars-test-patterns/00-atoms/00-global/10-at-partial-block.hbs b/test/files/_handlebars-test-patterns/00-atoms/00-global/10-at-partial-block.hbs new file mode 100644 index 000000000..59e0522cd --- /dev/null +++ b/test/files/_handlebars-test-patterns/00-atoms/00-global/10-at-partial-block.hbs @@ -0,0 +1,2 @@ +{{> @partial-block }} +It worked! diff --git a/test/files/_handlebars-test-patterns/00-molecules/00-global/10-call-at-partial-block.hbs b/test/files/_handlebars-test-patterns/00-molecules/00-global/10-call-at-partial-block.hbs new file mode 100644 index 000000000..d653c1196 --- /dev/null +++ b/test/files/_handlebars-test-patterns/00-molecules/00-global/10-call-at-partial-block.hbs @@ -0,0 +1,3 @@ +{{#> atoms-at-partial-block }} +Hello World! +{{/atoms-at-partial-block}}