browser_gcli_date.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. "use strict";
  17. // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT
  18. // PLEASE TALK TO SOMEONE IN DEVELOPER TOOLS BEFORE EDITING IT
  19. const exports = {};
  20. function test() {
  21. helpers.runTestModule(exports, "browser_gcli_date.js");
  22. }
  23. // var assert = require('../testharness/assert');
  24. // var helpers = require('./helpers');
  25. var Status = require("gcli/types/types").Status;
  26. exports.testParse = function (options) {
  27. var date = options.requisition.system.types.createType("date");
  28. return date.parseString("now").then(function (conversion) {
  29. // Date comparison - these 2 dates may not be the same, but how close is
  30. // close enough? If this test takes more than 30secs to run the it will
  31. // probably time out, so we'll assume that these 2 values must be within
  32. // 1 min of each other
  33. var gap = new Date().getTime() - conversion.value.getTime();
  34. assert.ok(gap < 60000, "now is less than a minute away");
  35. assert.is(conversion.getStatus(), Status.VALID, "now parse");
  36. });
  37. };
  38. exports.testMaxMin = function (options) {
  39. var max = new Date();
  40. var min = new Date();
  41. var types = options.requisition.system.types;
  42. var date = types.createType({ name: "date", max: max, min: min });
  43. assert.is(date.getMax(), max, "max setup");
  44. var incremented = date.nudge(min, 1);
  45. assert.is(incremented, max, "incremented");
  46. };
  47. exports.testIncrement = function (options) {
  48. var date = options.requisition.system.types.createType("date");
  49. return date.parseString("now").then(function (conversion) {
  50. var plusOne = date.nudge(conversion.value, 1);
  51. var minusOne = date.nudge(plusOne, -1);
  52. // See comments in testParse
  53. var gap = new Date().getTime() - minusOne.getTime();
  54. assert.ok(gap < 60000, "now is less than a minute away");
  55. });
  56. };
  57. exports.testInput = function (options) {
  58. return helpers.audit(options, [
  59. {
  60. setup: "tsdate 2001-01-01 1980-01-03",
  61. check: {
  62. input: "tsdate 2001-01-01 1980-01-03",
  63. hints: "",
  64. markup: "VVVVVVVVVVVVVVVVVVVVVVVVVVVV",
  65. status: "VALID",
  66. message: "",
  67. args: {
  68. command: { name: "tsdate" },
  69. d1: {
  70. value: function (d1) {
  71. assert.is(d1.getFullYear(), 2001, "d1 year");
  72. assert.is(d1.getMonth(), 0, "d1 month");
  73. assert.is(d1.getDate(), 1, "d1 date");
  74. assert.is(d1.getHours(), 0, "d1 hours");
  75. assert.is(d1.getMinutes(), 0, "d1 minutes");
  76. assert.is(d1.getSeconds(), 0, "d1 seconds");
  77. assert.is(d1.getMilliseconds(), 0, "d1 millis");
  78. },
  79. arg: " 2001-01-01",
  80. status: "VALID",
  81. message: ""
  82. },
  83. d2: {
  84. value: function (d2) {
  85. assert.is(d2.getFullYear(), 1980, "d2 year");
  86. assert.is(d2.getMonth(), 0, "d2 month");
  87. assert.is(d2.getDate(), 3, "d2 date");
  88. assert.is(d2.getHours(), 0, "d2 hours");
  89. assert.is(d2.getMinutes(), 0, "d2 minutes");
  90. assert.is(d2.getSeconds(), 0, "d2 seconds");
  91. assert.is(d2.getMilliseconds(), 0, "d2 millis");
  92. },
  93. arg: " 1980-01-03",
  94. status: "VALID",
  95. message: ""
  96. },
  97. }
  98. },
  99. exec: {
  100. output: [ /^Exec: tsdate/, /2001/, /1980/ ],
  101. type: "testCommandOutput",
  102. error: false
  103. }
  104. },
  105. {
  106. setup: "tsdate 2001/01/01 1980/01/03",
  107. check: {
  108. input: "tsdate 2001/01/01 1980/01/03",
  109. hints: "",
  110. markup: "VVVVVVVVVVVVVVVVVVVVVVVVVVVV",
  111. status: "VALID",
  112. message: "",
  113. args: {
  114. command: { name: "tsdate" },
  115. d1: {
  116. value: function (d1) {
  117. assert.is(d1.getFullYear(), 2001, "d1 year");
  118. assert.is(d1.getMonth(), 0, "d1 month");
  119. assert.is(d1.getDate(), 1, "d1 date");
  120. assert.is(d1.getHours(), 0, "d1 hours");
  121. assert.is(d1.getMinutes(), 0, "d1 minutes");
  122. assert.is(d1.getSeconds(), 0, "d1 seconds");
  123. assert.is(d1.getMilliseconds(), 0, "d1 millis");
  124. },
  125. arg: " 2001/01/01",
  126. status: "VALID",
  127. message: ""
  128. },
  129. d2: {
  130. value: function (d2) {
  131. assert.is(d2.getFullYear(), 1980, "d2 year");
  132. assert.is(d2.getMonth(), 0, "d2 month");
  133. assert.is(d2.getDate(), 3, "d2 date");
  134. assert.is(d2.getHours(), 0, "d2 hours");
  135. assert.is(d2.getMinutes(), 0, "d2 minutes");
  136. assert.is(d2.getSeconds(), 0, "d2 seconds");
  137. assert.is(d2.getMilliseconds(), 0, "d2 millis");
  138. },
  139. arg: " 1980/01/03",
  140. status: "VALID",
  141. message: ""
  142. },
  143. }
  144. },
  145. exec: {
  146. output: [ /^Exec: tsdate/, /2001/, /1980/ ],
  147. type: "testCommandOutput",
  148. error: false
  149. }
  150. },
  151. {
  152. setup: "tsdate now today",
  153. check: {
  154. input: "tsdate now today",
  155. hints: "",
  156. markup: "VVVVVVVVVVVVVVVV",
  157. status: "VALID",
  158. message: "",
  159. args: {
  160. command: { name: "tsdate" },
  161. d1: {
  162. value: function (d1) {
  163. // How long should we allow between d1 and now? Mochitest will
  164. // time out after 30 secs, so that seems like a decent upper
  165. // limit, although 30 ms should probably do it. I don't think
  166. // reducing the limit from 30 secs will find any extra bugs
  167. assert.ok(d1.getTime() - new Date().getTime() < 30 * 1000,
  168. "d1 time");
  169. },
  170. arg: " now",
  171. status: "VALID",
  172. message: ""
  173. },
  174. d2: {
  175. value: function (d2) {
  176. // See comment for d1 above
  177. assert.ok(d2.getTime() - new Date().getTime() < 30 * 1000,
  178. "d2 time");
  179. },
  180. arg: " today",
  181. status: "VALID",
  182. message: ""
  183. },
  184. }
  185. },
  186. exec: {
  187. output: [ /^Exec: tsdate/, new Date().getFullYear() ],
  188. type: "testCommandOutput",
  189. error: false
  190. }
  191. },
  192. {
  193. setup: "tsdate yesterday tomorrow",
  194. check: {
  195. input: "tsdate yesterday tomorrow",
  196. hints: "",
  197. markup: "VVVVVVVVVVVVVVVVVVVVVVVVV",
  198. status: "VALID",
  199. message: "",
  200. args: {
  201. command: { name: "tsdate" },
  202. d1: {
  203. value: function (d1) {
  204. var compare = new Date().getTime() - (24 * 60 * 60 * 1000);
  205. // See comment for d1 in the test for 'tsdate now today'
  206. assert.ok(d1.getTime() - compare < 30 * 1000,
  207. "d1 time");
  208. },
  209. arg: " yesterday",
  210. status: "VALID",
  211. message: ""
  212. },
  213. d2: {
  214. value: function (d2) {
  215. var compare = new Date().getTime() + (24 * 60 * 60 * 1000);
  216. // See comment for d1 in the test for 'tsdate now today'
  217. assert.ok(d2.getTime() - compare < 30 * 1000,
  218. "d2 time");
  219. },
  220. arg: " tomorrow",
  221. status: "VALID",
  222. message: ""
  223. },
  224. }
  225. },
  226. exec: {
  227. output: [ /^Exec: tsdate/, new Date().getFullYear() ],
  228. type: "testCommandOutput",
  229. error: false
  230. }
  231. }
  232. ]);
  233. };
  234. exports.testIncrDecr = function (options) {
  235. return helpers.audit(options, [
  236. {
  237. // createRequisitionAutomator doesn't fake UP/DOWN well enough
  238. skipRemainingIf: options.isNode,
  239. setup: "tsdate 2001-01-01<UP>",
  240. check: {
  241. input: "tsdate 2001-01-02",
  242. hints: " <d2>",
  243. markup: "VVVVVVVVVVVVVVVVV",
  244. status: "ERROR",
  245. message: "",
  246. args: {
  247. command: { name: "tsdate" },
  248. d1: {
  249. value: function (d1) {
  250. assert.is(d1.getFullYear(), 2001, "d1 year");
  251. assert.is(d1.getMonth(), 0, "d1 month");
  252. assert.is(d1.getDate(), 2, "d1 date");
  253. assert.is(d1.getHours(), 0, "d1 hours");
  254. assert.is(d1.getMinutes(), 0, "d1 minutes");
  255. assert.is(d1.getSeconds(), 0, "d1 seconds");
  256. assert.is(d1.getMilliseconds(), 0, "d1 millis");
  257. },
  258. arg: " 2001-01-02",
  259. status: "VALID",
  260. message: ""
  261. },
  262. d2: {
  263. value: undefined,
  264. status: "INCOMPLETE"
  265. },
  266. }
  267. }
  268. },
  269. {
  270. // Check wrapping on decrement
  271. setup: "tsdate 2001-02-01<DOWN>",
  272. check: {
  273. input: "tsdate 2001-01-31",
  274. hints: " <d2>",
  275. markup: "VVVVVVVVVVVVVVVVV",
  276. status: "ERROR",
  277. message: "",
  278. args: {
  279. command: { name: "tsdate" },
  280. d1: {
  281. value: function (d1) {
  282. assert.is(d1.getFullYear(), 2001, "d1 year");
  283. assert.is(d1.getMonth(), 0, "d1 month");
  284. assert.is(d1.getDate(), 31, "d1 date");
  285. assert.is(d1.getHours(), 0, "d1 hours");
  286. assert.is(d1.getMinutes(), 0, "d1 minutes");
  287. assert.is(d1.getSeconds(), 0, "d1 seconds");
  288. assert.is(d1.getMilliseconds(), 0, "d1 millis");
  289. },
  290. arg: " 2001-01-31",
  291. status: "VALID",
  292. message: ""
  293. },
  294. d2: {
  295. value: undefined,
  296. status: "INCOMPLETE"
  297. },
  298. }
  299. }
  300. },
  301. {
  302. // Check 'max' value capping on increment
  303. setup: 'tsdate 2001-02-01 "27 feb 2000"<UP>',
  304. check: {
  305. input: 'tsdate 2001-02-01 "2000-02-28"',
  306. hints: "",
  307. markup: "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",
  308. status: "VALID",
  309. message: "",
  310. args: {
  311. command: { name: "tsdate" },
  312. d1: {
  313. value: function (d1) {
  314. assert.is(d1.getFullYear(), 2001, "d1 year");
  315. assert.is(d1.getMonth(), 1, "d1 month");
  316. assert.is(d1.getDate(), 1, "d1 date");
  317. assert.is(d1.getHours(), 0, "d1 hours");
  318. assert.is(d1.getMinutes(), 0, "d1 minutes");
  319. assert.is(d1.getSeconds(), 0, "d1 seconds");
  320. assert.is(d1.getMilliseconds(), 0, "d1 millis");
  321. },
  322. arg: " 2001-02-01",
  323. status: "VALID",
  324. message: ""
  325. },
  326. d2: {
  327. value: function (d2) {
  328. assert.is(d2.getFullYear(), 2000, "d2 year");
  329. assert.is(d2.getMonth(), 1, "d2 month");
  330. assert.is(d2.getDate(), 28, "d2 date");
  331. assert.is(d2.getHours(), 0, "d2 hours");
  332. assert.is(d2.getMinutes(), 0, "d2 minutes");
  333. assert.is(d2.getSeconds(), 0, "d2 seconds");
  334. assert.is(d2.getMilliseconds(), 0, "d2 millis");
  335. },
  336. arg: ' "2000-02-28"',
  337. status: "VALID",
  338. message: ""
  339. },
  340. }
  341. }
  342. }
  343. ]);
  344. };