|
1 /* |
|
2 * Copyright 2012, Mozilla Foundation and contributors |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 |
|
17 'use strict'; |
|
18 // <INJECTED SOURCE:START> |
|
19 |
|
20 // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT |
|
21 // DO NOT EDIT IT DIRECTLY |
|
22 |
|
23 var exports = {}; |
|
24 |
|
25 var TEST_URI = "data:text/html;charset=utf-8,<p id='gcli-input'>gcli-testDate.js</p>"; |
|
26 |
|
27 function test() { |
|
28 return Task.spawn(function() { |
|
29 let options = yield helpers.openTab(TEST_URI); |
|
30 yield helpers.openToolbar(options); |
|
31 gcli.addItems(mockCommands.items); |
|
32 |
|
33 yield helpers.runTests(options, exports); |
|
34 |
|
35 gcli.removeItems(mockCommands.items); |
|
36 yield helpers.closeToolbar(options); |
|
37 yield helpers.closeTab(options); |
|
38 }).then(finish, helpers.handleError); |
|
39 } |
|
40 |
|
41 // <INJECTED SOURCE:END> |
|
42 |
|
43 // var assert = require('../testharness/assert'); |
|
44 // var helpers = require('./helpers'); |
|
45 |
|
46 var Status = require('gcli/types/types').Status; |
|
47 |
|
48 exports.testParse = function(options) { |
|
49 var date = options.requisition.types.createType('date'); |
|
50 return date.parseString('now').then(function(conversion) { |
|
51 // Date comparison - these 2 dates may not be the same, but how close is |
|
52 // close enough? If this test takes more than 30secs to run the it will |
|
53 // probably time out, so we'll assume that these 2 values must be within |
|
54 // 1 min of each other |
|
55 var gap = new Date().getTime() - conversion.value.getTime(); |
|
56 assert.ok(gap < 60000, 'now is less than a minute away'); |
|
57 |
|
58 assert.is(conversion.getStatus(), Status.VALID, 'now parse'); |
|
59 }); |
|
60 }; |
|
61 |
|
62 exports.testMaxMin = function(options) { |
|
63 var max = new Date(); |
|
64 var min = new Date(); |
|
65 var types = options.requisition.types; |
|
66 var date = types.createType({ name: 'date', max: max, min: min }); |
|
67 assert.is(date.getMax(), max, 'max setup'); |
|
68 |
|
69 var incremented = date.increment(min); |
|
70 assert.is(incremented, max, 'incremented'); |
|
71 }; |
|
72 |
|
73 exports.testIncrement = function(options) { |
|
74 var date = options.requisition.types.createType('date'); |
|
75 return date.parseString('now').then(function(conversion) { |
|
76 var plusOne = date.increment(conversion.value); |
|
77 var minusOne = date.decrement(plusOne); |
|
78 |
|
79 // See comments in testParse |
|
80 var gap = new Date().getTime() - minusOne.getTime(); |
|
81 assert.ok(gap < 60000, 'now is less than a minute away'); |
|
82 }); |
|
83 }; |
|
84 |
|
85 exports.testInput = function(options) { |
|
86 return helpers.audit(options, [ |
|
87 { |
|
88 setup: 'tsdate 2001-01-01 1980-01-03', |
|
89 check: { |
|
90 input: 'tsdate 2001-01-01 1980-01-03', |
|
91 hints: '', |
|
92 markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVV', |
|
93 status: 'VALID', |
|
94 message: '', |
|
95 args: { |
|
96 command: { name: 'tsdate' }, |
|
97 d1: { |
|
98 value: function(d1) { |
|
99 assert.is(d1.getFullYear(), 2001, 'd1 year'); |
|
100 assert.is(d1.getMonth(), 0, 'd1 month'); |
|
101 assert.is(d1.getDate(), 1, 'd1 date'); |
|
102 assert.is(d1.getHours(), 0, 'd1 hours'); |
|
103 assert.is(d1.getMinutes(), 0, 'd1 minutes'); |
|
104 assert.is(d1.getSeconds(), 0, 'd1 seconds'); |
|
105 assert.is(d1.getMilliseconds(), 0, 'd1 millis'); |
|
106 }, |
|
107 arg: ' 2001-01-01', |
|
108 status: 'VALID', |
|
109 message: '' |
|
110 }, |
|
111 d2: { |
|
112 value: function(d2) { |
|
113 assert.is(d2.getFullYear(), 1980, 'd2 year'); |
|
114 assert.is(d2.getMonth(), 0, 'd2 month'); |
|
115 assert.is(d2.getDate(), 3, 'd2 date'); |
|
116 assert.is(d2.getHours(), 0, 'd2 hours'); |
|
117 assert.is(d2.getMinutes(), 0, 'd2 minutes'); |
|
118 assert.is(d2.getSeconds(), 0, 'd2 seconds'); |
|
119 assert.is(d2.getMilliseconds(), 0, 'd2 millis'); |
|
120 }, |
|
121 arg: ' 1980-01-03', |
|
122 status: 'VALID', |
|
123 message: '' |
|
124 }, |
|
125 } |
|
126 }, |
|
127 exec: { |
|
128 output: [ /^Exec: tsdate/, /2001/, /1980/ ], |
|
129 type: 'string', |
|
130 error: false |
|
131 } |
|
132 }, |
|
133 { |
|
134 setup: 'tsdate 2001/01/01 1980/01/03', |
|
135 check: { |
|
136 input: 'tsdate 2001/01/01 1980/01/03', |
|
137 hints: '', |
|
138 markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVV', |
|
139 status: 'VALID', |
|
140 message: '', |
|
141 args: { |
|
142 command: { name: 'tsdate' }, |
|
143 d1: { |
|
144 value: function(d1) { |
|
145 assert.is(d1.getFullYear(), 2001, 'd1 year'); |
|
146 assert.is(d1.getMonth(), 0, 'd1 month'); |
|
147 assert.is(d1.getDate(), 1, 'd1 date'); |
|
148 assert.is(d1.getHours(), 0, 'd1 hours'); |
|
149 assert.is(d1.getMinutes(), 0, 'd1 minutes'); |
|
150 assert.is(d1.getSeconds(), 0, 'd1 seconds'); |
|
151 assert.is(d1.getMilliseconds(), 0, 'd1 millis'); |
|
152 }, |
|
153 arg: ' 2001/01/01', |
|
154 status: 'VALID', |
|
155 message: '' |
|
156 }, |
|
157 d2: { |
|
158 value: function(d2) { |
|
159 assert.is(d2.getFullYear(), 1980, 'd2 year'); |
|
160 assert.is(d2.getMonth(), 0, 'd2 month'); |
|
161 assert.is(d2.getDate(), 3, 'd2 date'); |
|
162 assert.is(d2.getHours(), 0, 'd2 hours'); |
|
163 assert.is(d2.getMinutes(), 0, 'd2 minutes'); |
|
164 assert.is(d2.getSeconds(), 0, 'd2 seconds'); |
|
165 assert.is(d2.getMilliseconds(), 0, 'd2 millis'); |
|
166 }, |
|
167 arg: ' 1980/01/03', |
|
168 status: 'VALID', |
|
169 message: '' |
|
170 }, |
|
171 } |
|
172 }, |
|
173 exec: { |
|
174 output: [ /^Exec: tsdate/, /2001/, /1980/ ], |
|
175 type: 'string', |
|
176 error: false |
|
177 } |
|
178 }, |
|
179 { |
|
180 setup: 'tsdate now today', |
|
181 check: { |
|
182 input: 'tsdate now today', |
|
183 hints: '', |
|
184 markup: 'VVVVVVVVVVVVVVVV', |
|
185 status: 'VALID', |
|
186 message: '', |
|
187 args: { |
|
188 command: { name: 'tsdate' }, |
|
189 d1: { |
|
190 value: function(d1) { |
|
191 // How long should we allow between d1 and now? Mochitest will |
|
192 // time out after 30 secs, so that seems like a decent upper |
|
193 // limit, although 30 ms should probably do it. I don't think |
|
194 // reducing the limit from 30 secs will find any extra bugs |
|
195 assert.ok(d1.getTime() - new Date().getTime() < 30 * 1000, |
|
196 'd1 time'); |
|
197 }, |
|
198 arg: ' now', |
|
199 status: 'VALID', |
|
200 message: '' |
|
201 }, |
|
202 d2: { |
|
203 value: function(d2) { |
|
204 // See comment for d1 above |
|
205 assert.ok(d2.getTime() - new Date().getTime() < 30 * 1000, |
|
206 'd2 time'); |
|
207 }, |
|
208 arg: ' today', |
|
209 status: 'VALID', |
|
210 message: '' |
|
211 }, |
|
212 } |
|
213 }, |
|
214 exec: { |
|
215 output: [ /^Exec: tsdate/, new Date().getFullYear() ], |
|
216 type: 'string', |
|
217 error: false |
|
218 } |
|
219 }, |
|
220 { |
|
221 setup: 'tsdate yesterday tomorrow', |
|
222 check: { |
|
223 input: 'tsdate yesterday tomorrow', |
|
224 hints: '', |
|
225 markup: 'VVVVVVVVVVVVVVVVVVVVVVVVV', |
|
226 status: 'VALID', |
|
227 message: '', |
|
228 args: { |
|
229 command: { name: 'tsdate' }, |
|
230 d1: { |
|
231 value: function(d1) { |
|
232 var compare = new Date().getTime() - (24 * 60 * 60 * 1000); |
|
233 // See comment for d1 in the test for 'tsdate now today' |
|
234 assert.ok(d1.getTime() - compare < 30 * 1000, |
|
235 'd1 time'); |
|
236 }, |
|
237 arg: ' yesterday', |
|
238 status: 'VALID', |
|
239 message: '' |
|
240 }, |
|
241 d2: { |
|
242 value: function(d2) { |
|
243 var compare = new Date().getTime() + (24 * 60 * 60 * 1000); |
|
244 // See comment for d1 in the test for 'tsdate now today' |
|
245 assert.ok(d2.getTime() - compare < 30 * 1000, |
|
246 'd2 time'); |
|
247 }, |
|
248 arg: ' tomorrow', |
|
249 status: 'VALID', |
|
250 message: '' |
|
251 }, |
|
252 } |
|
253 }, |
|
254 exec: { |
|
255 output: [ /^Exec: tsdate/, new Date().getFullYear() ], |
|
256 type: 'string', |
|
257 error: false |
|
258 } |
|
259 } |
|
260 ]); |
|
261 }; |
|
262 |
|
263 exports.testIncrDecr = function(options) { |
|
264 return helpers.audit(options, [ |
|
265 { |
|
266 // createRequisitionAutomator doesn't fake UP/DOWN well enough |
|
267 skipRemainingIf: options.isNoDom, |
|
268 setup: 'tsdate 2001-01-01<UP>', |
|
269 check: { |
|
270 input: 'tsdate 2001-01-02', |
|
271 hints: ' <d2>', |
|
272 markup: 'VVVVVVVVVVVVVVVVV', |
|
273 status: 'ERROR', |
|
274 message: '', |
|
275 args: { |
|
276 command: { name: 'tsdate' }, |
|
277 d1: { |
|
278 value: function(d1) { |
|
279 assert.is(d1.getFullYear(), 2001, 'd1 year'); |
|
280 assert.is(d1.getMonth(), 0, 'd1 month'); |
|
281 assert.is(d1.getDate(), 2, 'd1 date'); |
|
282 assert.is(d1.getHours(), 0, 'd1 hours'); |
|
283 assert.is(d1.getMinutes(), 0, 'd1 minutes'); |
|
284 assert.is(d1.getSeconds(), 0, 'd1 seconds'); |
|
285 assert.is(d1.getMilliseconds(), 0, 'd1 millis'); |
|
286 }, |
|
287 arg: ' 2001-01-02', |
|
288 status: 'VALID', |
|
289 message: '' |
|
290 }, |
|
291 d2: { |
|
292 value: undefined, |
|
293 status: 'INCOMPLETE' |
|
294 }, |
|
295 } |
|
296 } |
|
297 }, |
|
298 { |
|
299 // Check wrapping on decrement |
|
300 setup: 'tsdate 2001-02-01<DOWN>', |
|
301 check: { |
|
302 input: 'tsdate 2001-01-31', |
|
303 hints: ' <d2>', |
|
304 markup: 'VVVVVVVVVVVVVVVVV', |
|
305 status: 'ERROR', |
|
306 message: '', |
|
307 args: { |
|
308 command: { name: 'tsdate' }, |
|
309 d1: { |
|
310 value: function(d1) { |
|
311 assert.is(d1.getFullYear(), 2001, 'd1 year'); |
|
312 assert.is(d1.getMonth(), 0, 'd1 month'); |
|
313 assert.is(d1.getDate(), 31, 'd1 date'); |
|
314 assert.is(d1.getHours(), 0, 'd1 hours'); |
|
315 assert.is(d1.getMinutes(), 0, 'd1 minutes'); |
|
316 assert.is(d1.getSeconds(), 0, 'd1 seconds'); |
|
317 assert.is(d1.getMilliseconds(), 0, 'd1 millis'); |
|
318 }, |
|
319 arg: ' 2001-01-31', |
|
320 status: 'VALID', |
|
321 message: '' |
|
322 }, |
|
323 d2: { |
|
324 value: undefined, |
|
325 status: 'INCOMPLETE' |
|
326 }, |
|
327 } |
|
328 } |
|
329 }, |
|
330 { |
|
331 // Check 'max' value capping on increment |
|
332 setup: 'tsdate 2001-02-01 "27 feb 2000"<UP>', |
|
333 check: { |
|
334 input: 'tsdate 2001-02-01 "2000-02-28"', |
|
335 hints: '', |
|
336 markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV', |
|
337 status: 'VALID', |
|
338 message: '', |
|
339 args: { |
|
340 command: { name: 'tsdate' }, |
|
341 d1: { |
|
342 value: function(d1) { |
|
343 assert.is(d1.getFullYear(), 2001, 'd1 year'); |
|
344 assert.is(d1.getMonth(), 1, 'd1 month'); |
|
345 assert.is(d1.getDate(), 1, 'd1 date'); |
|
346 assert.is(d1.getHours(), 0, 'd1 hours'); |
|
347 assert.is(d1.getMinutes(), 0, 'd1 minutes'); |
|
348 assert.is(d1.getSeconds(), 0, 'd1 seconds'); |
|
349 assert.is(d1.getMilliseconds(), 0, 'd1 millis'); |
|
350 }, |
|
351 arg: ' 2001-02-01', |
|
352 status: 'VALID', |
|
353 message: '' |
|
354 }, |
|
355 d2: { |
|
356 value: function(d2) { |
|
357 assert.is(d2.getFullYear(), 2000, 'd2 year'); |
|
358 assert.is(d2.getMonth(), 1, 'd2 month'); |
|
359 assert.is(d2.getDate(), 28, 'd2 date'); |
|
360 assert.is(d2.getHours(), 0, 'd2 hours'); |
|
361 assert.is(d2.getMinutes(), 0, 'd2 minutes'); |
|
362 assert.is(d2.getSeconds(), 0, 'd2 seconds'); |
|
363 assert.is(d2.getMilliseconds(), 0, 'd2 millis'); |
|
364 }, |
|
365 arg: ' "2000-02-28"', |
|
366 status: 'VALID', |
|
367 message: '' |
|
368 }, |
|
369 } |
|
370 } |
|
371 } |
|
372 ]); |
|
373 }; |