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