Initial commit
[yaffs-website] / node_modules / node-sass / test / lowlevel.js
1 process.env.NODESASS_COV ? require('../lib-cov') : require('../lib');
2
3 var assert = require('assert'),
4   sass = require('../lib/extensions'),
5   binding = require(sass.getBinaryPath());
6
7 describe('lowlevel', function() {
8   it('fail with options not an object', function(done) {
9     var options =  2;
10     assert.throws(function() {
11       binding.renderSync(options);
12     }, /"result" element is not an object/);
13     done();
14   });
15
16   it('data context with options.data not provided', function(done) {
17     var options =  {
18       /* data: */
19       sourceComments: false,
20       file: null,
21       outFile: null,
22       includePaths: '',
23       precision: 5,
24       sourceMap: null,
25       style: 0,
26       indentWidth: 2,
27       indentType: 0,
28       linefeed: '\n',
29       result: { stats: {} } };
30
31     binding.renderSync(options);
32     assert(/Data context created without a source string/.test(options.result.error),
33           'Should fail with error message "Data context created without a source string"');
34     done();
35   });
36
37   it('data context with both options.data and options.file not provided', function(done) {
38     var options =  {
39       /* data: */
40       sourceComments: false,
41       /* file: null, */
42       outFile: null,
43       includePaths: '',
44       precision: 5,
45       sourceMap: null,
46       style: 0,
47       indentWidth: 2,
48       indentType: 0,
49       linefeed: '\n',
50       result: { stats: {} } };
51
52     binding.renderSync(options);
53     assert(/Data context created without a source string/.test(options.result.error),
54           'Should fail with error message "Data context created without a source string"');
55     done();
56   });
57
58   it('file context with both options.data and options.file not provided', function(done) {
59     var options =  {
60       /* data: */
61       sourceComments: false,
62       /* file: null, */
63       outFile: null,
64       includePaths: '',
65       precision: 5,
66       sourceMap: null,
67       style: 0,
68       indentWidth: 2,
69       indentType: 0,
70       linefeed: '\n',
71       result: { stats: {} } };
72
73     binding.renderFileSync(options);
74     assert(/File context created without an input path/.test(options.result.error),
75           'Should fail with error message "File context created without an input path"');
76     done();
77   });
78
79   it('file context with options.file not provided, options.data given', function(done) {
80     var options =  {
81       data: 'div { width: 10px; } ',
82       sourceComments: false,
83       /* file: null, */
84       outFile: null,
85       includePaths: '',
86       precision: 5,
87       sourceMap: null,
88       style: 0,
89       indentWidth: 2,
90       indentType: 0,
91       linefeed: '\n',
92       result: { stats: {} } };
93
94     binding.renderFileSync(options);
95     assert(/File context created without an input path/.test(options.result.error),
96           'Should fail with error message "File context created without an input path"');
97     done();
98   });
99
100   it('fail with options.result not provided', function(done) {
101     var options =  { data: 'div { width: 10px; } ',
102       sourceComments: false,
103       file: null,
104       outFile: null,
105       includePaths: '',
106       precision: 5,
107       sourceMap: null,
108       style: 0,
109       indentWidth: 2,
110       indentType: 0,
111       linefeed: '\n' };
112
113     assert.throws(function() {
114       binding.renderSync(options);
115     }, /"result" element is not an object/);
116     done();
117   });
118
119
120   it('fail with options.result not an object', function(done) {
121     var options =  { data: 'div { width: 10px; } ',
122       sourceComments: false,
123       file: null,
124       outFile: null,
125       includePaths: '',
126       precision: 5,
127       sourceMap: null,
128       style: 0,
129       indentWidth: 2,
130       indentType: 0,
131       linefeed: '\n',
132       result: 2 };
133
134     assert.throws(function() {
135       binding.renderSync(options);
136     }, /"result" element is not an object/);
137     done();
138   });
139
140
141   it('fail with options.result.stats not provided', function(done) {
142
143     var options =  { data: 'div { width: 10px; } ',
144       sourceComments: false,
145       file: null,
146       outFile: null,
147       includePaths: '',
148       precision: 5,
149       sourceMap: null,
150       style: 0,
151       indentWidth: 2,
152       indentType: 0,
153       linefeed: '\n',
154       result: {} };
155
156     assert.throws(function() {
157       binding.renderSync(options);
158     }, /"result.stats" element is not an object/);
159     done();
160   });
161
162   it('fail with options.result.stats not an object', function(done) {
163
164     var options =  { data: 'div { width: 10px; } ',
165       sourceComments: false,
166       file: null,
167       outFile: null,
168       includePaths: '',
169       precision: 5,
170       sourceMap: null,
171       style: 0,
172       indentWidth: 2,
173       indentType: 0,
174       linefeed: '\n',
175       result: { stats: 2 } };
176
177     assert.throws(function() {
178       binding.renderSync(options);
179     }, /"result.stats" element is not an object/);
180     done();
181   });
182
183   it('options.indentWidth not provided', function(done) {
184     var options =  { data: 'div { width: 10px; }',
185       sourceComments: false,
186       file: null,
187       outFile: null,
188       includePaths: '',
189       precision: 5,
190       sourceMap: null,
191       style: 0,
192       /* indentWidth */
193       indentType: 0,
194       linefeed: '\n',
195       result: { stats: {} } };
196
197     binding.renderSync(options);
198     assert(options.result.css);
199     done();
200   });
201
202   it('empty data string', function(done) {
203     var options =  { data: '',
204       sourceComments: false,
205       file: null,
206       outFile: null,
207       includePaths: '',
208       precision: 5,
209       sourceMap: null,
210       style: 0,
211       /* indentWidth */
212       indentType: 0,
213       linefeed: '\n',
214       result: { stats: {} } };
215
216     binding.renderSync(options);
217     assert(/empty source string/.test(options.result.error),
218           'Should fail with error message "Data context created with empty source string"');
219     done();
220   });
221
222
223   it('empty file string', function(done) {
224     var options =  {
225       sourceComments: false,
226       file: '',
227       outFile: null,
228       includePaths: '',
229       precision: 5,
230       sourceMap: null,
231       style: 0,
232       /* indentWidth */
233       indentType: 0,
234       linefeed: '\n',
235       result: { stats: {} } };
236
237     binding.renderFileSync(options);
238     assert(/empty input path/.test(options.result.error),
239           'Should fail with error message "File context created with empty input path"');
240     done();
241   });
242
243 }); // lowlevel