Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tests for separator, processName, processPartialName, partialRegex options #30

Merged
merged 4 commits into from Feb 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions Gruntfile.js
Expand Up @@ -113,6 +113,45 @@ module.exports = function(grunt) {
files: { files: {
'tmp/amd_compile_direct.js': ['test/fixtures/amd.html'] 'tmp/amd_compile_direct.js': ['test/fixtures/amd.html']
} }
},
custom_separator: {
options: {
separator: ';;;;;'
},
files: {
'tmp/custom_separator.js': ['test/fixtures/basic.hbs']
}
},
processname: {
options: {
processName: function(filename) {
return filename.toUpperCase();
}
},
files: {
'tmp/processname.js': ['test/fixtures/basic.hbs']
}
},
process_partial_name: {
options: {
processPartialName: function(filepath) {
return filepath.replace('test/fixtures/_weird_prefix_', '').replace('.hbs', '');
}
},
files: {
'tmp/process_partial_name.js': ['test/fixtures/_weird_prefix_partial.hbs', 'test/fixtures/one.hbs']
}
},
partial_regex: {
options: {
partialRegex: /^par_/,
processPartialName: function(filepath) {
return filepath.replace('test/fixtures/par_', '').replace('.hbs', '');
}
},
files: {
'tmp/partial_regex.js': ['test/fixtures/par_partial.hbs', 'test/fixtures/one.hbs']
}
} }
}, },
// Unit tests. // Unit tests.
Expand Down
8 changes: 8 additions & 0 deletions test/expected/custom_separator.js
@@ -0,0 +1,8 @@
this["JST"] = this["JST"] || {};;;;;;this["JST"]["test/fixtures/basic.hbs"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};



return "Basic template that does nothing.";
});
27 changes: 27 additions & 0 deletions test/expected/partial_regex.js
@@ -0,0 +1,27 @@
this["JST"] = this["JST"] || {};

Handlebars.registerPartial("partial", Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};



return "<span>Canada</span>";
}));

this["JST"]["test/fixtures/one.hbs"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; partials = partials || Handlebars.partials; data = data || {};
var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;


buffer += "<p>Hello, my name is ";
if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ ". I live in ";
stack1 = self.invokePartial(partials.partial, 'partial', depth0, helpers, partials, data);
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "</p>";
return buffer;
});
27 changes: 27 additions & 0 deletions test/expected/process_partial_name.js
@@ -0,0 +1,27 @@
this["JST"] = this["JST"] || {};

Handlebars.registerPartial("partial", Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};



return "<span>Canada</span>";
}));

this["JST"]["test/fixtures/one.hbs"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; partials = partials || Handlebars.partials; data = data || {};
var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;


buffer += "<p>Hello, my name is ";
if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ ". I live in ";
stack1 = self.invokePartial(partials.partial, 'partial', depth0, helpers, partials, data);
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "</p>";
return buffer;
});
10 changes: 10 additions & 0 deletions test/expected/processname.js
@@ -0,0 +1,10 @@
this["JST"] = this["JST"] || {};

this["JST"]["TEST/FIXTURES/BASIC.HBS"] = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};



return "Basic template that does nothing.";
});
1 change: 1 addition & 0 deletions test/fixtures/_weird_prefix_partial.hbs
@@ -0,0 +1 @@
<span>Canada</span>
1 change: 1 addition & 0 deletions test/fixtures/par_partial.hbs
@@ -0,0 +1 @@
<span>Canada</span>
40 changes: 40 additions & 0 deletions test/handlebars_test.js
Expand Up @@ -99,6 +99,46 @@ exports.handlebars = {
var expected = grunt.file.read('test/expected/amd_compile_direct.js'); // same as previous test var expected = grunt.file.read('test/expected/amd_compile_direct.js'); // same as previous test
test.equal(actual, expected, 'should wrap everything with an AMD define block and directly return the template.'); test.equal(actual, expected, 'should wrap everything with an AMD define block and directly return the template.');


test.done();
},
custom_separator: function(test) {
'use strict';
test.expect(1);

var actual = grunt.file.read('tmp/custom_separator.js');
var expected = grunt.file.read('test/expected/custom_separator.js');
test.equal(actual, expected, 'should use custom file separators as specified.');

test.done();
},
processname: function(test) {
'use strict';
test.expect(1);

var actual = grunt.file.read('tmp/processname.js');
var expected = grunt.file.read('test/expected/processname.js');
test.equal(actual, expected, 'should convert template name to upper case.');

test.done();
},
process_partial_name: function(test) {
'use strict';
test.expect(1);

var actual = grunt.file.read('tmp/process_partial_name.js');
var expected = grunt.file.read('test/expected/process_partial_name.js');
test.equal(actual, expected, 'should support custom handling of partial naming conventions.');

test.done();
},
partial_regex: function(test) {
'use strict';
test.expect(1);

var actual = grunt.file.read('tmp/partial_regex.js');
var expected = grunt.file.read('test/expected/partial_regex.js');
test.equal(actual, expected, 'should support custom file name identifiers for partials.');

test.done(); test.done();
} }
}; };