1 | var grunt = require('../../lib/grunt');
|
2 |
|
3 |
|
4 |
|
5 | if (grunt.task.searchDirs.length === 0) {
|
6 | grunt.task.init([]);
|
7 | grunt.config.init({});
|
8 | }
|
9 |
|
10 | exports['config'] = function(test) {
|
11 | test.expect(2);
|
12 | test.deepEqual(grunt.helper('config'), grunt.config(), 'It should just pass through to config.');
|
13 | test.deepEqual(grunt.helper('config', 'meta'), grunt.config('meta'), 'It should just pass through to config.');
|
14 | test.done();
|
15 | };
|
16 |
|
17 | exports['json'] = function(test) {
|
18 | test.expect(2);
|
19 | var obj = grunt.helper('json', 'test/fixtures/test.json');
|
20 | test.equal(obj.foo, 'bar', 'JSON properties should be available as-defined.');
|
21 | test.deepEqual(obj.baz, [1, 2, 3], 'JSON properties should be available as-defined.');
|
22 | test.done();
|
23 | };
|
24 |
|
25 | exports['strip_banner'] = function(test) {
|
26 | test.expect(7);
|
27 | var src = grunt.file.read('test/fixtures/banner.js');
|
28 | test.equal(grunt.helper('strip_banner', src), '// Comment\n\n/* Comment */\n', 'It should strip the top banner.');
|
29 | test.equal(grunt.helper('strip_banner', src, {block: true}), '// Comment\n\n/* Comment */\n', 'It should strip the top banner.');
|
30 | src = grunt.file.read('test/fixtures/banner2.js');
|
31 | test.equal(grunt.helper('strip_banner', src), '\n/*! SAMPLE\n * BANNER */\n\n// Comment\n\n/* Comment */\n', 'It should not strip the top banner.');
|
32 | test.equal(grunt.helper('strip_banner', src, {block: true}), '// Comment\n\n/* Comment */\n', 'It should strip the top banner.');
|
33 | src = grunt.file.read('test/fixtures/banner3.js');
|
34 | test.equal(grunt.helper('strip_banner', src), '\n// This is\n// A sample\n// Banner\n\n// But this is not\n\n/* And neither\n * is this\n */\n', 'It should not strip the top banner.');
|
35 | test.equal(grunt.helper('strip_banner', src, {block: true}), '\n// This is\n// A sample\n// Banner\n\n// But this is not\n\n/* And neither\n * is this\n */\n', 'It should not strip the top banner.');
|
36 | test.equal(grunt.helper('strip_banner', src, {line: true}), '// But this is not\n\n/* And neither\n * is this\n */\n', 'It should strip the top banner.');
|
37 | test.done();
|
38 | };
|
39 |
|
40 | exports['file_strip_banner'] = function(test) {
|
41 | test.expect(14);
|
42 | var filepath = 'test/fixtures/banner.js';
|
43 | test.equal(grunt.helper('file_strip_banner', filepath), '// Comment\n\n/* Comment */\n', 'It should strip the top banner.');
|
44 | test.equal(grunt.helper('file_strip_banner', filepath, {block: true}), '// Comment\n\n/* Comment */\n', 'It should strip the top banner.');
|
45 | filepath = 'test/fixtures/banner2.js';
|
46 | test.equal(grunt.helper('file_strip_banner', filepath), '\n/*! SAMPLE\n * BANNER */\n\n// Comment\n\n/* Comment */\n', 'It should not strip the top banner.');
|
47 | test.equal(grunt.helper('file_strip_banner', filepath, {block: true}), '// Comment\n\n/* Comment */\n', 'It should strip the top banner.');
|
48 | filepath = 'test/fixtures/banner3.js';
|
49 | test.equal(grunt.helper('file_strip_banner', filepath), '\n// This is\n// A sample\n// Banner\n\n// But this is not\n\n/* And neither\n * is this\n */\n', 'It should not strip the top banner.');
|
50 | test.equal(grunt.helper('file_strip_banner', filepath, {block: true}), '\n// This is\n// A sample\n// Banner\n\n// But this is not\n\n/* And neither\n * is this\n */\n', 'It should not strip the top banner.');
|
51 | test.equal(grunt.helper('file_strip_banner', filepath, {line: true}), '// But this is not\n\n/* And neither\n * is this\n */\n', 'It should strip the top banner.');
|
52 |
|
53 | test.equal(grunt.task.directive('<file_strip_banner:test/fixtures/banner.js>'), '// Comment\n\n/* Comment */\n', 'It should strip the top banner.');
|
54 | test.equal(grunt.task.directive('<file_strip_banner:test/fixtures/banner.js:block>'), '// Comment\n\n/* Comment */\n', 'It should strip the top banner.');
|
55 | test.equal(grunt.task.directive('<file_strip_banner:test/fixtures/banner2.js>'), '\n/*! SAMPLE\n * BANNER */\n\n// Comment\n\n/* Comment */\n', 'It should not strip the top banner.');
|
56 | test.equal(grunt.task.directive('<file_strip_banner:test/fixtures/banner2.js:block>'), '// Comment\n\n/* Comment */\n', 'It should strip the top banner.');
|
57 | test.equal(grunt.task.directive('<file_strip_banner:test/fixtures/banner3.js>'), '\n// This is\n// A sample\n// Banner\n\n// But this is not\n\n/* And neither\n * is this\n */\n', 'It should not strip the top banner.');
|
58 | test.equal(grunt.task.directive('<file_strip_banner:test/fixtures/banner3.js:block>'), '\n// This is\n// A sample\n// Banner\n\n// But this is not\n\n/* And neither\n * is this\n */\n', 'It should not strip the top banner.');
|
59 | test.equal(grunt.task.directive('<file_strip_banner:test/fixtures/banner3.js:line>'), '// But this is not\n\n/* And neither\n * is this\n */\n', 'It should strip the top banner.');
|
60 | test.done();
|
61 | };
|
62 |
|
63 | exports['file_template'] = function(test) {
|
64 | test.expect(2);
|
65 | var expected = 'Version: ' + grunt.version + ', today: ' + grunt.template.today('yyyy-mm-dd') + '.';
|
66 | test.equal(grunt.helper('file_template', 'test/fixtures/template.txt'), expected, 'It should return the parsed template.');
|
67 | test.equal(grunt.task.directive('<file_template:test/fixtures/template.txt>'), expected, 'It should return the parsed template.');
|
68 | test.done();
|
69 | };
|
70 |
|
71 | exports['banner'] = function(test) {
|
72 | test.expect(5);
|
73 | grunt.config('test_config', {a: 'aaaaa', b: 'bbbbb', c: [1, 2, 3], d: [{a: 1}, {a: 2}, {a: 3}]});
|
74 |
|
75 | grunt.config('meta.banner', 'foo\n<%= test_config.a %>\nbar');
|
76 | test.equal(grunt.helper('banner'), grunt.utils.normalizelf('foo\naaaaa\nbar\n'), 'It should use the default banner.');
|
77 |
|
78 | grunt.config('test_config.banner', '<%= test_config.b %>');
|
79 | test.equal(grunt.helper('banner', 'test_config.banner'), grunt.utils.normalizelf('bbbbb\n'), 'It should use the requested banner.');
|
80 |
|
81 | grunt.config('test_config.banner', '<%= test_config.c.join(", ") %>');
|
82 | test.equal(grunt.helper('banner', 'test_config.banner'), grunt.utils.normalizelf('1, 2, 3\n'), 'It should join arrays.');
|
83 |
|
84 | grunt.config('test_config.banner', '<%= _.pluck(test_config.d, "a").join(", ") %>');
|
85 | test.equal(grunt.helper('banner', 'test_config.banner'), grunt.utils.normalizelf('1, 2, 3\n'), 'It should join arrays.');
|
86 |
|
87 | grunt.config('test_config.banner', '<%= grunt.template.today("yyyy-mm-dd") %>');
|
88 | test.equal(grunt.helper('banner', 'test_config.banner'), grunt.utils.normalizelf(grunt.template.today('yyyy-mm-dd') + '\n'), 'It should parse the current date correctly.');
|
89 |
|
90 | test.done();
|
91 | };
|