2012-09-11 02:12:23 +08:00
|
|
|
var grunt = require('grunt');
|
|
|
|
|
|
|
|
exports['jst'] = {
|
|
|
|
main: function(test) {
|
|
|
|
'use strict';
|
|
|
|
|
2012-09-12 23:34:53 +08:00
|
|
|
var expect, result;
|
2012-09-11 02:12:23 +08:00
|
|
|
|
2013-03-06 21:56:40 +08:00
|
|
|
test.expect(10);
|
2012-09-12 23:34:53 +08:00
|
|
|
|
2012-09-15 07:32:44 +08:00
|
|
|
expect = grunt.file.read("test/expected/jst.js");
|
2012-09-12 23:34:53 +08:00
|
|
|
result = grunt.file.read("tmp/jst.js");
|
2012-09-11 02:12:23 +08:00
|
|
|
test.equal(expect, result, "should compile underscore templates into JST");
|
|
|
|
|
2012-09-15 07:32:44 +08:00
|
|
|
expect = grunt.file.read("test/expected/uglyfile.js");
|
2012-09-12 23:34:53 +08:00
|
|
|
result = grunt.file.read("tmp/uglyfile.js");
|
|
|
|
test.equal(expect, result, "should escape single quotes in filenames");
|
|
|
|
|
2012-09-15 07:32:44 +08:00
|
|
|
expect = grunt.file.read("test/expected/ns_nested.js");
|
|
|
|
result = grunt.file.read("tmp/ns_nested.js");
|
|
|
|
test.equal(expect, result, "should define parts of nested namespaces");
|
2013-11-06 01:03:05 +08:00
|
|
|
|
2012-09-15 07:32:44 +08:00
|
|
|
expect = grunt.file.read("test/expected/ns_nested.js"); // same as previous test
|
|
|
|
result = grunt.file.read("tmp/ns_nested_this.js");
|
|
|
|
test.equal(expect, result, "should define parts of nested namespaces, ignoring this.");
|
2013-11-06 01:03:05 +08:00
|
|
|
|
|
|
|
expect = grunt.file.read("test/expected/pretty.js");
|
2012-11-27 02:02:20 +08:00
|
|
|
result = grunt.file.read("tmp/pretty.js");
|
|
|
|
test.equal(expect, result, "should make the output be 1 line per template, making the output less ugly");
|
2013-11-06 01:03:05 +08:00
|
|
|
|
|
|
|
expect = grunt.file.read("test/expected/format_amd.js");
|
|
|
|
result = grunt.file.read("tmp/format_amd.js");
|
2012-11-27 02:02:20 +08:00
|
|
|
test.equal(expect, result, "should wrap the template with define for AMD pattern");
|
2013-11-06 01:03:05 +08:00
|
|
|
|
|
|
|
expect = grunt.file.read("test/expected/format_amd_with_dep.js");
|
|
|
|
result = grunt.file.read("tmp/format_amd_with_dep.js");
|
|
|
|
test.equal(expect, result, "should wrap the template with define for AMD pattern and load dependencies");
|
|
|
|
|
|
|
|
expect = grunt.file.read("test/expected/format_amd_no_ns.js");
|
|
|
|
result = grunt.file.read("tmp/format_amd_no_ns.js");
|
2013-03-06 21:56:40 +08:00
|
|
|
test.equal(expect, result, "should wrap the template with define for AMD pattern and return the function itself with no namespace");
|
2013-11-06 01:03:05 +08:00
|
|
|
|
2012-12-29 21:18:21 +08:00
|
|
|
expect = grunt.file.read("test/expected/process_content.js");
|
|
|
|
result = grunt.file.read("tmp/process_content.js");
|
|
|
|
test.equal(expect, result, "should convert file content");
|
|
|
|
|
2013-02-16 02:45:54 +08:00
|
|
|
expect = grunt.file.read("test/expected/local_scope.js");
|
|
|
|
result = grunt.file.read("tmp/local_scope.js");
|
|
|
|
test.equal(expect, result, "should add `with` block when templateSettings.variable is undefined");
|
|
|
|
|
2012-09-11 02:12:23 +08:00
|
|
|
test.done();
|
|
|
|
}
|
2012-11-27 02:02:20 +08:00
|
|
|
};
|