1 | 'use strict';
|
2 |
|
3 | var grunt = require('../../lib/grunt');
|
4 |
|
5 | exports['config'] = {
|
6 | setUp: function(done) {
|
7 | this.origData = grunt.config.data;
|
8 | grunt.config.init({
|
9 | meta: grunt.file.readJSON('test/fixtures/test.json'),
|
10 | foo: '<%= meta.foo %>',
|
11 | foo2: '<%= foo %>',
|
12 | obj: {
|
13 | foo: '<%= meta.foo %>',
|
14 | foo2: '<%= obj.foo %>',
|
15 | Arr: ['foo', '<%= obj.foo2 %>'],
|
16 | arr2: ['<%= arr %>', '<%= obj.Arr %>'],
|
17 | },
|
18 | bar: 'bar',
|
19 | arr: ['foo', '<%= obj.foo2 %>'],
|
20 | arr2: ['<%= arr %>', '<%= obj.Arr %>'],
|
21 | });
|
22 | done();
|
23 | },
|
24 | tearDown: function(done) {
|
25 | grunt.config.data = this.origData;
|
26 | done();
|
27 | },
|
28 | 'config.escape': function(test) {
|
29 | test.expect(2);
|
30 | test.equal(grunt.config.escape('foo'), 'foo', 'Should do nothing if no . chars.');
|
31 | test.equal(grunt.config.escape('foo.bar.baz'), 'foo\\.bar\\.baz', 'Should escape all . chars.');
|
32 | test.done();
|
33 | },
|
34 | 'config.getPropString': function(test) {
|
35 | test.expect(4);
|
36 | test.equal(grunt.config.getPropString('foo'), 'foo', 'Should do nothing if already a string.');
|
37 | test.equal(grunt.config.getPropString('foo.bar.baz'), 'foo.bar.baz', 'Should do nothing if already a string.');
|
38 | test.equal(grunt.config.getPropString(['foo', 'bar']), 'foo.bar', 'Should join parts into a dot-delimited string.');
|
39 | test.equal(grunt.config.getPropString(['foo.bar', 'baz.qux.zip']), 'foo\\.bar.baz\\.qux\\.zip', 'Should join parts into a dot-delimited string, escaping . chars in parts.');
|
40 | test.done();
|
41 | },
|
42 | 'config.getRaw': function(test) {
|
43 | test.expect(4);
|
44 | test.equal(grunt.config.getRaw('foo'), '<%= meta.foo %>', 'Should not process templates.');
|
45 | test.equal(grunt.config.getRaw('obj.foo2'), '<%= obj.foo %>', 'Should not process templates.');
|
46 | test.equal(grunt.config.getRaw(['obj', 'foo2']), '<%= obj.foo %>', 'Should not process templates.');
|
47 | test.deepEqual(grunt.config.getRaw('arr'), ['foo', '<%= obj.foo2 %>'], 'Should not process templates.');
|
48 | test.done();
|
49 | },
|
50 | 'config.process': function(test) {
|
51 | test.expect(5);
|
52 | test.equal(grunt.config.process('<%= meta.foo %>'), 'bar', 'Should process templates.');
|
53 | test.equal(grunt.config.process('<%= foo %>'), 'bar', 'Should process templates recursively.');
|
54 | test.equal(grunt.config.process('<%= obj.foo %>'), 'bar', 'Should process deeply nested templates recursively.');
|
55 | test.deepEqual(grunt.config.process(['foo', '<%= obj.foo2 %>']), ['foo', 'bar'], 'Should process templates in arrays.');
|
56 | test.deepEqual(grunt.config.process(['<%= arr %>', '<%= obj.Arr %>']), [['foo', 'bar'], ['foo', 'bar']], 'Should expand <%= arr %> and <%= obj.Arr %> values as objects if possible.');
|
57 | test.done();
|
58 | },
|
59 | 'config.get': function(test) {
|
60 | test.expect(8);
|
61 | test.equal(grunt.config.get('foo'), 'bar', 'Should process templates.');
|
62 | test.equal(grunt.config.get('foo2'), 'bar', 'Should process templates recursively.');
|
63 | test.equal(grunt.config.get('obj.foo2'), 'bar', 'Should process deeply nested templates recursively.');
|
64 | test.equal(grunt.config.get(['obj', 'foo2']), 'bar', 'Should process deeply nested templates recursively.');
|
65 | test.deepEqual(grunt.config.get('arr'), ['foo', 'bar'], 'Should process templates in arrays.');
|
66 | test.deepEqual(grunt.config.get('obj.Arr'), ['foo', 'bar'], 'Should process templates in arrays.');
|
67 | test.deepEqual(grunt.config.get('arr2'), [['foo', 'bar'], ['foo', 'bar']], 'Should expand <%= arr %> and <%= obj.Arr %> values as objects if possible.');
|
68 | test.deepEqual(grunt.config.get(['obj', 'arr2']), [['foo', 'bar'], ['foo', 'bar']], 'Should expand <%= arr %> and <%= obj.Arr %> values as objects if possible.');
|
69 | test.done();
|
70 | },
|
71 | 'config.set': function(test) {
|
72 | test.expect(6);
|
73 | test.equal(grunt.config.set('foo3', '<%= foo2 %>'), '<%= foo2 %>', 'Should set values.');
|
74 | test.equal(grunt.config.getRaw('foo3'), '<%= foo2 %>', 'Should have set the value.');
|
75 | test.equal(grunt.config.data.foo3, '<%= foo2 %>', 'Should have set the value.');
|
76 | test.equal(grunt.config.set('a.b.c', '<%= foo2 %>'), '<%= foo2 %>', 'Should create interim objects.');
|
77 | test.equal(grunt.config.getRaw('a.b.c'), '<%= foo2 %>', 'Should have set the value.');
|
78 | test.equal(grunt.config.data.a.b.c, '<%= foo2 %>', 'Should have set the value.');
|
79 | test.done();
|
80 | },
|
81 | 'config': function(test) {
|
82 | test.expect(10);
|
83 | test.equal(grunt.config('foo'), 'bar', 'Should retrieve processed data.');
|
84 | test.equal(grunt.config('obj.foo2'), 'bar', 'Should retrieve processed data.');
|
85 | test.equal(grunt.config(['obj', 'foo2']), 'bar', 'Should retrieve processed data.');
|
86 | test.deepEqual(grunt.config('arr'), ['foo', 'bar'], 'Should process templates in arrays.');
|
87 |
|
88 | test.equal(grunt.config('foo3', '<%= foo2 %>'), '<%= foo2 %>', 'Should set values.');
|
89 | test.equal(grunt.config.getRaw('foo3'), '<%= foo2 %>', 'Should have set the value.');
|
90 | test.equal(grunt.config.data.foo3, '<%= foo2 %>', 'Should have set the value.');
|
91 | test.equal(grunt.config('a.b.c', '<%= foo2 %>'), '<%= foo2 %>', 'Should create interim objects.');
|
92 | test.equal(grunt.config.getRaw('a.b.c'), '<%= foo2 %>', 'Should have set the value.');
|
93 | test.equal(grunt.config.data.a.b.c, '<%= foo2 %>', 'Should have set the value.');
|
94 | test.done();
|
95 | },
|
96 | 'config.requires': function(test) {
|
97 | test.expect(8);
|
98 | grunt.log.muted = true;
|
99 | test.doesNotThrow(function() { grunt.config.requires('foo'); }, 'This property exists.');
|
100 | test.doesNotThrow(function() { grunt.config.requires('obj.foo'); }, 'This property exists.');
|
101 | test.doesNotThrow(function() { grunt.config.requires('foo', 'obj.foo', 'obj.foo2'); }, 'These properties exist.');
|
102 | test.doesNotThrow(function() { grunt.config.requires('foo', ['obj', 'foo'], ['obj', 'foo2']); }, 'These properties exist.');
|
103 | test.throws(function() { grunt.config.requires('xyz'); }, 'This property does not exist.');
|
104 | test.throws(function() { grunt.config.requires('obj.xyz'); }, 'This property does not exist.');
|
105 | test.throws(function() { grunt.config.requires('foo', 'obj.foo', 'obj.xyz'); }, 'One property does not exist.');
|
106 | test.throws(function() { grunt.config.requires('foo', ['obj', 'foo'], ['obj', 'xyz']); }, 'One property does not exist.');
|
107 | grunt.log.muted = false;
|
108 | test.done();
|
109 | },
|
110 | };
|