summaryrefslogtreecommitdiffstats
path: root/devtools/client/commandline/test/browser_gcli_date.js
blob: 9d50aebcb6a2e0a71c09366ecb27f8d0bdea8f60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/*
 * Copyright 2012, Mozilla Foundation and contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

"use strict";

// THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT
// PLEASE TALK TO SOMEONE IN DEVELOPER TOOLS BEFORE EDITING IT

const exports = {};

function test() {
  helpers.runTestModule(exports, "browser_gcli_date.js");
}

// var assert = require('../testharness/assert');
// var helpers = require('./helpers');

var Status = require("gcli/types/types").Status;

exports.testParse = function (options) {
  var date = options.requisition.system.types.createType("date");
  return date.parseString("now").then(function (conversion) {
    // Date comparison - these 2 dates may not be the same, but how close is
    // close enough? If this test takes more than 30secs to run the it will
    // probably time out, so we'll assume that these 2 values must be within
    // 1 min of each other
    var gap = new Date().getTime() - conversion.value.getTime();
    assert.ok(gap < 60000, "now is less than a minute away");

    assert.is(conversion.getStatus(), Status.VALID, "now parse");
  });
};

exports.testMaxMin = function (options) {
  var max = new Date();
  var min = new Date();
  var types = options.requisition.system.types;
  var date = types.createType({ name: "date", max: max, min: min });
  assert.is(date.getMax(), max, "max setup");

  var incremented = date.nudge(min, 1);
  assert.is(incremented, max, "incremented");
};

exports.testIncrement = function (options) {
  var date = options.requisition.system.types.createType("date");
  return date.parseString("now").then(function (conversion) {
    var plusOne = date.nudge(conversion.value, 1);
    var minusOne = date.nudge(plusOne, -1);

    // See comments in testParse
    var gap = new Date().getTime() - minusOne.getTime();
    assert.ok(gap < 60000, "now is less than a minute away");
  });
};

exports.testInput = function (options) {
  return helpers.audit(options, [
    {
      setup:    "tsdate 2001-01-01 1980-01-03",
      check: {
        input:  "tsdate 2001-01-01 1980-01-03",
        hints:                              "",
        markup: "VVVVVVVVVVVVVVVVVVVVVVVVVVVV",
        status: "VALID",
        message: "",
        args: {
          command: { name: "tsdate" },
          d1: {
            value: function (d1) {
              assert.is(d1.getFullYear(), 2001, "d1 year");
              assert.is(d1.getMonth(), 0, "d1 month");
              assert.is(d1.getDate(), 1, "d1 date");
              assert.is(d1.getHours(), 0, "d1 hours");
              assert.is(d1.getMinutes(), 0, "d1 minutes");
              assert.is(d1.getSeconds(), 0, "d1 seconds");
              assert.is(d1.getMilliseconds(), 0, "d1 millis");
            },
            arg: " 2001-01-01",
            status: "VALID",
            message: ""
          },
          d2: {
            value: function (d2) {
              assert.is(d2.getFullYear(), 1980, "d2 year");
              assert.is(d2.getMonth(), 0, "d2 month");
              assert.is(d2.getDate(), 3, "d2 date");
              assert.is(d2.getHours(), 0, "d2 hours");
              assert.is(d2.getMinutes(), 0, "d2 minutes");
              assert.is(d2.getSeconds(), 0, "d2 seconds");
              assert.is(d2.getMilliseconds(), 0, "d2 millis");
            },
            arg: " 1980-01-03",
            status: "VALID",
            message: ""
          },
        }
      },
      exec: {
        output: [ /^Exec: tsdate/, /2001/, /1980/ ],
        type: "testCommandOutput",
        error: false
      }
    },
    {
      setup:    "tsdate 2001/01/01 1980/01/03",
      check: {
        input:  "tsdate 2001/01/01 1980/01/03",
        hints:                              "",
        markup: "VVVVVVVVVVVVVVVVVVVVVVVVVVVV",
        status: "VALID",
        message: "",
        args: {
          command: { name: "tsdate" },
          d1: {
            value: function (d1) {
              assert.is(d1.getFullYear(), 2001, "d1 year");
              assert.is(d1.getMonth(), 0, "d1 month");
              assert.is(d1.getDate(), 1, "d1 date");
              assert.is(d1.getHours(), 0, "d1 hours");
              assert.is(d1.getMinutes(), 0, "d1 minutes");
              assert.is(d1.getSeconds(), 0, "d1 seconds");
              assert.is(d1.getMilliseconds(), 0, "d1 millis");
            },
            arg: " 2001/01/01",
            status: "VALID",
            message: ""
          },
          d2: {
            value: function (d2) {
              assert.is(d2.getFullYear(), 1980, "d2 year");
              assert.is(d2.getMonth(), 0, "d2 month");
              assert.is(d2.getDate(), 3, "d2 date");
              assert.is(d2.getHours(), 0, "d2 hours");
              assert.is(d2.getMinutes(), 0, "d2 minutes");
              assert.is(d2.getSeconds(), 0, "d2 seconds");
              assert.is(d2.getMilliseconds(), 0, "d2 millis");
            },
            arg: " 1980/01/03",
            status: "VALID",
            message: ""
          },
        }
      },
      exec: {
        output: [ /^Exec: tsdate/, /2001/, /1980/ ],
        type: "testCommandOutput",
        error: false
      }
    },
    {
      setup:    "tsdate now today",
      check: {
        input:  "tsdate now today",
        hints:                  "",
        markup: "VVVVVVVVVVVVVVVV",
        status: "VALID",
        message: "",
        args: {
          command: { name: "tsdate" },
          d1: {
            value: function (d1) {
              // How long should we allow between d1 and now? Mochitest will
              // time out after 30 secs, so that seems like a decent upper
              // limit, although 30 ms should probably do it. I don't think
              // reducing the limit from 30 secs will find any extra bugs
              assert.ok(d1.getTime() - new Date().getTime() < 30 * 1000,
                        "d1 time");
            },
            arg: " now",
            status: "VALID",
            message: ""
          },
          d2: {
            value: function (d2) {
              // See comment for d1 above
              assert.ok(d2.getTime() - new Date().getTime() < 30 * 1000,
                        "d2 time");
            },
            arg: " today",
            status: "VALID",
            message: ""
          },
        }
      },
      exec: {
        output: [ /^Exec: tsdate/, new Date().getFullYear() ],
        type: "testCommandOutput",
        error: false
      }
    },
    {
      setup:    "tsdate yesterday tomorrow",
      check: {
        input:  "tsdate yesterday tomorrow",
        hints:                           "",
        markup: "VVVVVVVVVVVVVVVVVVVVVVVVV",
        status: "VALID",
        message: "",
        args: {
          command: { name: "tsdate" },
          d1: {
            value: function (d1) {
              var compare = new Date().getTime() - (24 * 60 * 60 * 1000);
              // See comment for d1 in the test for 'tsdate now today'
              assert.ok(d1.getTime() - compare < 30 * 1000,
                        "d1 time");
            },
            arg: " yesterday",
            status: "VALID",
            message: ""
          },
          d2: {
            value: function (d2) {
              var compare = new Date().getTime() + (24 * 60 * 60 * 1000);
              // See comment for d1 in the test for 'tsdate now today'
              assert.ok(d2.getTime() - compare < 30 * 1000,
                        "d2 time");
            },
            arg: " tomorrow",
            status: "VALID",
            message: ""
          },
        }
      },
      exec: {
        output: [ /^Exec: tsdate/, new Date().getFullYear() ],
        type: "testCommandOutput",
        error: false
      }
    }
  ]);
};

exports.testIncrDecr = function (options) {
  return helpers.audit(options, [
    {
      // createRequisitionAutomator doesn't fake UP/DOWN well enough
      skipRemainingIf: options.isNode,
      setup:    "tsdate 2001-01-01<UP>",
      check: {
        input:  "tsdate 2001-01-02",
        hints:                    " <d2>",
        markup: "VVVVVVVVVVVVVVVVV",
        status: "ERROR",
        message: "",
        args: {
          command: { name: "tsdate" },
          d1: {
            value: function (d1) {
              assert.is(d1.getFullYear(), 2001, "d1 year");
              assert.is(d1.getMonth(), 0, "d1 month");
              assert.is(d1.getDate(), 2, "d1 date");
              assert.is(d1.getHours(), 0, "d1 hours");
              assert.is(d1.getMinutes(), 0, "d1 minutes");
              assert.is(d1.getSeconds(), 0, "d1 seconds");
              assert.is(d1.getMilliseconds(), 0, "d1 millis");
            },
            arg: " 2001-01-02",
            status: "VALID",
            message: ""
          },
          d2: {
            value: undefined,
            status: "INCOMPLETE"
          },
        }
      }
    },
    {
      // Check wrapping on decrement
      setup:    "tsdate 2001-02-01<DOWN>",
      check: {
        input:  "tsdate 2001-01-31",
        hints:                    " <d2>",
        markup: "VVVVVVVVVVVVVVVVV",
        status: "ERROR",
        message: "",
        args: {
          command: { name: "tsdate" },
          d1: {
            value: function (d1) {
              assert.is(d1.getFullYear(), 2001, "d1 year");
              assert.is(d1.getMonth(), 0, "d1 month");
              assert.is(d1.getDate(), 31, "d1 date");
              assert.is(d1.getHours(), 0, "d1 hours");
              assert.is(d1.getMinutes(), 0, "d1 minutes");
              assert.is(d1.getSeconds(), 0, "d1 seconds");
              assert.is(d1.getMilliseconds(), 0, "d1 millis");
            },
            arg: " 2001-01-31",
            status: "VALID",
            message: ""
          },
          d2: {
            value: undefined,
            status: "INCOMPLETE"
          },
        }
      }
    },
    {
      // Check 'max' value capping on increment
      setup:    'tsdate 2001-02-01 "27 feb 2000"<UP>',
      check: {
        input:  'tsdate 2001-02-01 "2000-02-28"',
        hints:                                "",
        markup: "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",
        status: "VALID",
        message: "",
        args: {
          command: { name: "tsdate" },
          d1: {
            value: function (d1) {
              assert.is(d1.getFullYear(), 2001, "d1 year");
              assert.is(d1.getMonth(), 1, "d1 month");
              assert.is(d1.getDate(), 1, "d1 date");
              assert.is(d1.getHours(), 0, "d1 hours");
              assert.is(d1.getMinutes(), 0, "d1 minutes");
              assert.is(d1.getSeconds(), 0, "d1 seconds");
              assert.is(d1.getMilliseconds(), 0, "d1 millis");
            },
            arg: " 2001-02-01",
            status: "VALID",
            message: ""
          },
          d2: {
            value: function (d2) {
              assert.is(d2.getFullYear(), 2000, "d2 year");
              assert.is(d2.getMonth(), 1, "d2 month");
              assert.is(d2.getDate(), 28, "d2 date");
              assert.is(d2.getHours(), 0, "d2 hours");
              assert.is(d2.getMinutes(), 0, "d2 minutes");
              assert.is(d2.getSeconds(), 0, "d2 seconds");
              assert.is(d2.getMilliseconds(), 0, "d2 millis");
            },
            arg: ' "2000-02-28"',
            status: "VALID",
            message: ""
          },
        }
      }
    }
  ]);
};