Permalink
Browse files

Merge pull request #30 from pdokas/missing-tests

Adding tests for separator, processName, processPartialName, partialRegex options
  • Loading branch information...
2 parents 21e4c3c + c54fc83 commit c7a0ed99d12e1e63c0c8fea673bb7e5f9ef98941 @tkellen tkellen committed Feb 21, 2013
View
@@ -113,6 +113,45 @@ module.exports = function(grunt) {
files: {
'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.
@@ -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.";
+ });
@@ -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;
+ });
@@ -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;
+ });
@@ -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.";
+ });
@@ -0,0 +1 @@
+<span>Canada</span>
@@ -0,0 +1 @@
+<span>Canada</span>
View
@@ -100,5 +100,45 @@ exports.handlebars = {
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();
}
};

0 comments on commit c7a0ed9

Please sign in to comment.