summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/parser.js12
-rw-r--r--spec/partials.js61
-rw-r--r--spec/tokenizer.js4
-rw-r--r--spec/visitor.js3
4 files changed, 78 insertions, 2 deletions
diff --git a/spec/parser.js b/spec/parser.js
index 82c32d0..5b60f93 100644
--- a/spec/parser.js
+++ b/spec/parser.js
@@ -113,6 +113,18 @@ describe('parser', function() {
equals(astFor('{{> shared/partial?.bar}}'), '{{> PARTIAL:shared/partial?.bar }}\n');
});
+ it('parsers partial blocks', function() {
+ equals(astFor('{{#> foo}}bar{{/foo}}'), '{{> PARTIAL BLOCK:foo PROGRAM:\n CONTENT[ \'bar\' ]\n }}\n');
+ });
+ it('should handle parser block mismatch', function() {
+ shouldThrow(function() {
+ astFor('{{#> goodbyes}}{{/hellos}}');
+ }, Error, (/goodbyes doesn't match hellos/));
+ });
+ it('parsers partial blocks with arguments', function() {
+ equals(astFor('{{#> foo context hash=value}}bar{{/foo}}'), '{{> PARTIAL BLOCK:foo PATH:context HASH{hash=PATH:value} PROGRAM:\n CONTENT[ \'bar\' ]\n }}\n');
+ });
+
it('parses a comment', function() {
equals(astFor('{{! this is a comment }}'), "{{! ' this is a comment ' }}\n");
});
diff --git a/spec/partials.js b/spec/partials.js
index a9cd3dd..314cca2 100644
--- a/spec/partials.js
+++ b/spec/partials.js
@@ -196,6 +196,67 @@ describe('partials', function() {
handlebarsEnv.compile = compile;
});
+ describe('partial blocks', function() {
+ it('should render partial block as default', function() {
+ shouldCompileToWithPartials(
+ '{{#> dude}}success{{/dude}}',
+ [{}, {}, {}],
+ true,
+ 'success');
+ });
+ it('should execute default block with proper context', function() {
+ shouldCompileToWithPartials(
+ '{{#> dude context}}{{value}}{{/dude}}',
+ [{context: {value: 'success'}}, {}, {}],
+ true,
+ 'success');
+ });
+ it('should propagate block parameters to default block', function() {
+ shouldCompileToWithPartials(
+ '{{#with context as |me|}}{{#> dude}}{{me.value}}{{/dude}}{{/with}}',
+ [{context: {value: 'success'}}, {}, {}],
+ true,
+ 'success');
+ });
+
+ it('should not use partial block if partial exists', function() {
+ shouldCompileToWithPartials(
+ '{{#> dude}}fail{{/dude}}',
+ [{}, {}, {dude: 'success'}],
+ true,
+ 'success');
+ });
+
+ it('should render block from partial', function() {
+ shouldCompileToWithPartials(
+ '{{#> dude}}success{{/dude}}',
+ [{}, {}, {dude: '{{> @partial-block }}'}],
+ true,
+ 'success');
+ });
+ it('should render block from partial with context', function() {
+ shouldCompileToWithPartials(
+ '{{#> dude}}{{value}}{{/dude}}',
+ [{context: {value: 'success'}}, {}, {dude: '{{#with context}}{{> @partial-block }}{{/with}}'}],
+ true,
+ 'success');
+ });
+ it('should render block from partial with context', function() {
+ shouldCompileToWithPartials(
+ '{{#> dude}}{{../context/value}}{{/dude}}',
+ [{context: {value: 'success'}}, {}, {dude: '{{#with context}}{{> @partial-block }}{{/with}}'}],
+ true,
+ 'success');
+ });
+ it('should render block from partial with block params', function() {
+ shouldCompileToWithPartials(
+ '{{#with context as |me|}}{{#> dude}}{{me.value}}{{/dude}}{{/with}}',
+ [{context: {value: 'success'}}, {}, {dude: '{{> @partial-block }}'}],
+ true,
+ 'success');
+ });
+ });
+
it('should pass compiler flags', function() {
if (Handlebars.compile) {
var env = Handlebars.create();
diff --git a/spec/tokenizer.js b/spec/tokenizer.js
index a474dfb..f170704 100644
--- a/spec/tokenizer.js
+++ b/spec/tokenizer.js
@@ -214,6 +214,10 @@ describe('Tokenizer', function() {
shouldMatchTokens(result, ['OPEN_PARTIAL', 'ID', 'SEP', 'ID', 'SEP', 'ID', 'CLOSE']);
});
+ it('tokenizes partial block declarations', function() {
+ var result = tokenize('{{#> foo}}');
+ shouldMatchTokens(result, ['OPEN_PARTIAL_BLOCK', 'ID', 'CLOSE']);
+ });
it('tokenizes a comment as "COMMENT"', function() {
var result = tokenize('foo {{! this is a comment }} bar {{ baz }}');
shouldMatchTokens(result, ['CONTENT', 'COMMENT', 'CONTENT', 'OPEN', 'ID', 'CLOSE']);
diff --git a/spec/visitor.js b/spec/visitor.js
index 23113cf..3e2d523 100644
--- a/spec/visitor.js
+++ b/spec/visitor.js
@@ -8,6 +8,7 @@ describe('Visitor', function() {
// stub methods are executed
var visitor = new Handlebars.Visitor();
visitor.accept(Handlebars.parse('{{foo}}{{#foo (bar 1 "1" true undefined null) foo=@data}}{{!comment}}{{> bar }} {{/foo}}'));
+ visitor.accept(Handlebars.parse('{{#> bar }} {{/bar}}'));
});
it('should traverse to stubs', function() {
@@ -40,8 +41,6 @@ describe('Visitor', function() {
visitor.accept(Handlebars.parse('{{#foo.bar (foo.bar 1 "2" true) foo=@foo.bar}}{{!comment}}{{> bar }} {{/foo.bar}}'));
});
- it('should return undefined');
-
describe('mutating', function() {
describe('fields', function() {
it('should replace value', function() {