michael@0: /* michael@0: * Copyright 2012, Mozilla Foundation and contributors michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: 'use strict'; michael@0: // michael@0: michael@0: // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT michael@0: // DO NOT EDIT IT DIRECTLY michael@0: michael@0: var exports = {}; michael@0: michael@0: var TEST_URI = "data:text/html;charset=utf-8,

gcli-testDate.js

"; michael@0: michael@0: function test() { michael@0: return Task.spawn(function() { michael@0: let options = yield helpers.openTab(TEST_URI); michael@0: yield helpers.openToolbar(options); michael@0: gcli.addItems(mockCommands.items); michael@0: michael@0: yield helpers.runTests(options, exports); michael@0: michael@0: gcli.removeItems(mockCommands.items); michael@0: yield helpers.closeToolbar(options); michael@0: yield helpers.closeTab(options); michael@0: }).then(finish, helpers.handleError); michael@0: } michael@0: michael@0: // michael@0: michael@0: // var assert = require('../testharness/assert'); michael@0: // var helpers = require('./helpers'); michael@0: michael@0: var Status = require('gcli/types/types').Status; michael@0: michael@0: exports.testParse = function(options) { michael@0: var date = options.requisition.types.createType('date'); michael@0: return date.parseString('now').then(function(conversion) { michael@0: // Date comparison - these 2 dates may not be the same, but how close is michael@0: // close enough? If this test takes more than 30secs to run the it will michael@0: // probably time out, so we'll assume that these 2 values must be within michael@0: // 1 min of each other michael@0: var gap = new Date().getTime() - conversion.value.getTime(); michael@0: assert.ok(gap < 60000, 'now is less than a minute away'); michael@0: michael@0: assert.is(conversion.getStatus(), Status.VALID, 'now parse'); michael@0: }); michael@0: }; michael@0: michael@0: exports.testMaxMin = function(options) { michael@0: var max = new Date(); michael@0: var min = new Date(); michael@0: var types = options.requisition.types; michael@0: var date = types.createType({ name: 'date', max: max, min: min }); michael@0: assert.is(date.getMax(), max, 'max setup'); michael@0: michael@0: var incremented = date.increment(min); michael@0: assert.is(incremented, max, 'incremented'); michael@0: }; michael@0: michael@0: exports.testIncrement = function(options) { michael@0: var date = options.requisition.types.createType('date'); michael@0: return date.parseString('now').then(function(conversion) { michael@0: var plusOne = date.increment(conversion.value); michael@0: var minusOne = date.decrement(plusOne); michael@0: michael@0: // See comments in testParse michael@0: var gap = new Date().getTime() - minusOne.getTime(); michael@0: assert.ok(gap < 60000, 'now is less than a minute away'); michael@0: }); michael@0: }; michael@0: michael@0: exports.testInput = function(options) { michael@0: return helpers.audit(options, [ michael@0: { michael@0: setup: 'tsdate 2001-01-01 1980-01-03', michael@0: check: { michael@0: input: 'tsdate 2001-01-01 1980-01-03', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID', michael@0: message: '', michael@0: args: { michael@0: command: { name: 'tsdate' }, michael@0: d1: { michael@0: value: function(d1) { michael@0: assert.is(d1.getFullYear(), 2001, 'd1 year'); michael@0: assert.is(d1.getMonth(), 0, 'd1 month'); michael@0: assert.is(d1.getDate(), 1, 'd1 date'); michael@0: assert.is(d1.getHours(), 0, 'd1 hours'); michael@0: assert.is(d1.getMinutes(), 0, 'd1 minutes'); michael@0: assert.is(d1.getSeconds(), 0, 'd1 seconds'); michael@0: assert.is(d1.getMilliseconds(), 0, 'd1 millis'); michael@0: }, michael@0: arg: ' 2001-01-01', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: d2: { michael@0: value: function(d2) { michael@0: assert.is(d2.getFullYear(), 1980, 'd2 year'); michael@0: assert.is(d2.getMonth(), 0, 'd2 month'); michael@0: assert.is(d2.getDate(), 3, 'd2 date'); michael@0: assert.is(d2.getHours(), 0, 'd2 hours'); michael@0: assert.is(d2.getMinutes(), 0, 'd2 minutes'); michael@0: assert.is(d2.getSeconds(), 0, 'd2 seconds'); michael@0: assert.is(d2.getMilliseconds(), 0, 'd2 millis'); michael@0: }, michael@0: arg: ' 1980-01-03', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: } michael@0: }, michael@0: exec: { michael@0: output: [ /^Exec: tsdate/, /2001/, /1980/ ], michael@0: type: 'string', michael@0: error: false michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tsdate 2001/01/01 1980/01/03', michael@0: check: { michael@0: input: 'tsdate 2001/01/01 1980/01/03', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID', michael@0: message: '', michael@0: args: { michael@0: command: { name: 'tsdate' }, michael@0: d1: { michael@0: value: function(d1) { michael@0: assert.is(d1.getFullYear(), 2001, 'd1 year'); michael@0: assert.is(d1.getMonth(), 0, 'd1 month'); michael@0: assert.is(d1.getDate(), 1, 'd1 date'); michael@0: assert.is(d1.getHours(), 0, 'd1 hours'); michael@0: assert.is(d1.getMinutes(), 0, 'd1 minutes'); michael@0: assert.is(d1.getSeconds(), 0, 'd1 seconds'); michael@0: assert.is(d1.getMilliseconds(), 0, 'd1 millis'); michael@0: }, michael@0: arg: ' 2001/01/01', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: d2: { michael@0: value: function(d2) { michael@0: assert.is(d2.getFullYear(), 1980, 'd2 year'); michael@0: assert.is(d2.getMonth(), 0, 'd2 month'); michael@0: assert.is(d2.getDate(), 3, 'd2 date'); michael@0: assert.is(d2.getHours(), 0, 'd2 hours'); michael@0: assert.is(d2.getMinutes(), 0, 'd2 minutes'); michael@0: assert.is(d2.getSeconds(), 0, 'd2 seconds'); michael@0: assert.is(d2.getMilliseconds(), 0, 'd2 millis'); michael@0: }, michael@0: arg: ' 1980/01/03', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: } michael@0: }, michael@0: exec: { michael@0: output: [ /^Exec: tsdate/, /2001/, /1980/ ], michael@0: type: 'string', michael@0: error: false michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tsdate now today', michael@0: check: { michael@0: input: 'tsdate now today', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVVVV', michael@0: status: 'VALID', michael@0: message: '', michael@0: args: { michael@0: command: { name: 'tsdate' }, michael@0: d1: { michael@0: value: function(d1) { michael@0: // How long should we allow between d1 and now? Mochitest will michael@0: // time out after 30 secs, so that seems like a decent upper michael@0: // limit, although 30 ms should probably do it. I don't think michael@0: // reducing the limit from 30 secs will find any extra bugs michael@0: assert.ok(d1.getTime() - new Date().getTime() < 30 * 1000, michael@0: 'd1 time'); michael@0: }, michael@0: arg: ' now', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: d2: { michael@0: value: function(d2) { michael@0: // See comment for d1 above michael@0: assert.ok(d2.getTime() - new Date().getTime() < 30 * 1000, michael@0: 'd2 time'); michael@0: }, michael@0: arg: ' today', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: } michael@0: }, michael@0: exec: { michael@0: output: [ /^Exec: tsdate/, new Date().getFullYear() ], michael@0: type: 'string', michael@0: error: false michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tsdate yesterday tomorrow', michael@0: check: { michael@0: input: 'tsdate yesterday tomorrow', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID', michael@0: message: '', michael@0: args: { michael@0: command: { name: 'tsdate' }, michael@0: d1: { michael@0: value: function(d1) { michael@0: var compare = new Date().getTime() - (24 * 60 * 60 * 1000); michael@0: // See comment for d1 in the test for 'tsdate now today' michael@0: assert.ok(d1.getTime() - compare < 30 * 1000, michael@0: 'd1 time'); michael@0: }, michael@0: arg: ' yesterday', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: d2: { michael@0: value: function(d2) { michael@0: var compare = new Date().getTime() + (24 * 60 * 60 * 1000); michael@0: // See comment for d1 in the test for 'tsdate now today' michael@0: assert.ok(d2.getTime() - compare < 30 * 1000, michael@0: 'd2 time'); michael@0: }, michael@0: arg: ' tomorrow', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: } michael@0: }, michael@0: exec: { michael@0: output: [ /^Exec: tsdate/, new Date().getFullYear() ], michael@0: type: 'string', michael@0: error: false michael@0: } michael@0: } michael@0: ]); michael@0: }; michael@0: michael@0: exports.testIncrDecr = function(options) { michael@0: return helpers.audit(options, [ michael@0: { michael@0: // createRequisitionAutomator doesn't fake UP/DOWN well enough michael@0: skipRemainingIf: options.isNoDom, michael@0: setup: 'tsdate 2001-01-01', michael@0: check: { michael@0: input: 'tsdate 2001-01-02', michael@0: hints: ' ', michael@0: markup: 'VVVVVVVVVVVVVVVVV', michael@0: status: 'ERROR', michael@0: message: '', michael@0: args: { michael@0: command: { name: 'tsdate' }, michael@0: d1: { michael@0: value: function(d1) { michael@0: assert.is(d1.getFullYear(), 2001, 'd1 year'); michael@0: assert.is(d1.getMonth(), 0, 'd1 month'); michael@0: assert.is(d1.getDate(), 2, 'd1 date'); michael@0: assert.is(d1.getHours(), 0, 'd1 hours'); michael@0: assert.is(d1.getMinutes(), 0, 'd1 minutes'); michael@0: assert.is(d1.getSeconds(), 0, 'd1 seconds'); michael@0: assert.is(d1.getMilliseconds(), 0, 'd1 millis'); michael@0: }, michael@0: arg: ' 2001-01-02', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: d2: { michael@0: value: undefined, michael@0: status: 'INCOMPLETE' michael@0: }, michael@0: } michael@0: } michael@0: }, michael@0: { michael@0: // Check wrapping on decrement michael@0: setup: 'tsdate 2001-02-01', michael@0: check: { michael@0: input: 'tsdate 2001-01-31', michael@0: hints: ' ', michael@0: markup: 'VVVVVVVVVVVVVVVVV', michael@0: status: 'ERROR', michael@0: message: '', michael@0: args: { michael@0: command: { name: 'tsdate' }, michael@0: d1: { michael@0: value: function(d1) { michael@0: assert.is(d1.getFullYear(), 2001, 'd1 year'); michael@0: assert.is(d1.getMonth(), 0, 'd1 month'); michael@0: assert.is(d1.getDate(), 31, 'd1 date'); michael@0: assert.is(d1.getHours(), 0, 'd1 hours'); michael@0: assert.is(d1.getMinutes(), 0, 'd1 minutes'); michael@0: assert.is(d1.getSeconds(), 0, 'd1 seconds'); michael@0: assert.is(d1.getMilliseconds(), 0, 'd1 millis'); michael@0: }, michael@0: arg: ' 2001-01-31', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: d2: { michael@0: value: undefined, michael@0: status: 'INCOMPLETE' michael@0: }, michael@0: } michael@0: } michael@0: }, michael@0: { michael@0: // Check 'max' value capping on increment michael@0: setup: 'tsdate 2001-02-01 "27 feb 2000"', michael@0: check: { michael@0: input: 'tsdate 2001-02-01 "2000-02-28"', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV', michael@0: status: 'VALID', michael@0: message: '', michael@0: args: { michael@0: command: { name: 'tsdate' }, michael@0: d1: { michael@0: value: function(d1) { michael@0: assert.is(d1.getFullYear(), 2001, 'd1 year'); michael@0: assert.is(d1.getMonth(), 1, 'd1 month'); michael@0: assert.is(d1.getDate(), 1, 'd1 date'); michael@0: assert.is(d1.getHours(), 0, 'd1 hours'); michael@0: assert.is(d1.getMinutes(), 0, 'd1 minutes'); michael@0: assert.is(d1.getSeconds(), 0, 'd1 seconds'); michael@0: assert.is(d1.getMilliseconds(), 0, 'd1 millis'); michael@0: }, michael@0: arg: ' 2001-02-01', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: d2: { michael@0: value: function(d2) { michael@0: assert.is(d2.getFullYear(), 2000, 'd2 year'); michael@0: assert.is(d2.getMonth(), 1, 'd2 month'); michael@0: assert.is(d2.getDate(), 28, 'd2 date'); michael@0: assert.is(d2.getHours(), 0, 'd2 hours'); michael@0: assert.is(d2.getMinutes(), 0, 'd2 minutes'); michael@0: assert.is(d2.getSeconds(), 0, 'd2 seconds'); michael@0: assert.is(d2.getMilliseconds(), 0, 'd2 millis'); michael@0: }, michael@0: arg: ' "2000-02-28"', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: } michael@0: } michael@0: } michael@0: ]); michael@0: };