Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 4 commits into from

2 participants

@pdokas

The following options are missing tests:

  • separator
  • processName
  • processPartialName
  • partialRegex

This PR adds a test case for each. No logical changes to the grunt task itself were made.

@tkellen
Owner

Wow Phil! Thank you :)

@tkellen tkellen merged commit c7a0ed9 into gruntjs:master
@pdokas pdokas deleted the pdokas:missing-tests branch
@pdokas

My pleasure :smiley:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
39 Gruntfile.js
@@ -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.
View
8 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.";
+ });
View
27 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;
+ });
View
27 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;
+ });
View
10 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.";
+ });
View
1  test/fixtures/_weird_prefix_partial.hbs
@@ -0,0 +1 @@
+<span>Canada</span>
View
1  test/fixtures/par_partial.hbs
@@ -0,0 +1 @@
+<span>Canada</span>
View
40 test/handlebars_test.js
@@ -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();
}
};
Something went wrong with that request. Please try again.