]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Adding tests for isValid and moment.utc() 306/head
authorTim Wood <washwithcare@gmail.com>
Thu, 24 May 2012 16:51:09 +0000 (09:51 -0700)
committerTim Wood <washwithcare@gmail.com>
Thu, 24 May 2012 16:51:09 +0000 (09:51 -0700)
test/moment/is_valid.js

index c3bafa0d95593442f58ae01f41bfac6dbfc4978c..2934128eb0af68ecbfa0296e0db5087fde93dbc1 100644 (file)
@@ -1,7 +1,7 @@
 var moment = require("../../moment");
 
 exports.is_valid = {
-    "array bad month" : function(test) {
+    "array bad month" : function (test) {
         test.expect(2);
 
         test.equal(moment([2010, -1]).isValid(), false, 'month -1');
@@ -10,43 +10,53 @@ exports.is_valid = {
         test.done();
     },
 
-    "array good month" : function(test) {
-        test.expect(12);
+    "array good month" : function (test) {
+        test.expect(24);
 
         for (var i = 0; i < 12; i++) {
             test.equal(moment([2010, i]).isValid(), true, 'month ' + i);
+            test.equal(moment.utc([2010, i]).isValid(), true, 'month ' + i);
         }
 
         test.done();
     },
 
-    "array bad date" : function(test) {
-        test.expect(2);
+    "array bad date" : function (test) {
+        test.expect(4);
 
         test.equal(moment([2010, 0, 0]).isValid(), false, 'date 0');
         test.equal(moment([2100, 0, 32]).isValid(), false, 'date 32');
 
+        test.equal(moment.utc([2010, 0, 0]).isValid(), false, 'utc date 0');
+        test.equal(moment.utc([2100, 0, 32]).isValid(), false, 'utc date 32');
+
         test.done();
     },
 
-    "array bad date leap year" : function(test) {
-        test.expect(4);
+    "array bad date leap year" : function (test) {
+        test.expect(8);
 
         test.equal(moment([2010, 1, 29]).isValid(), false, '2010 feb 29');
         test.equal(moment([2100, 1, 29]).isValid(), false, '2100 feb 29');
         test.equal(moment([2008, 1, 30]).isValid(), false, '2008 feb 30');
         test.equal(moment([2000, 1, 30]).isValid(), false, '2000 feb 30');
+
+        test.equal(moment.utc([2010, 1, 29]).isValid(), false, 'utc 2010 feb 29');
+        test.equal(moment.utc([2100, 1, 29]).isValid(), false, 'utc 2100 feb 29');
+        test.equal(moment.utc([2008, 1, 30]).isValid(), false, 'utc 2008 feb 30');
+        test.equal(moment.utc([2000, 1, 30]).isValid(), false, 'utc 2000 feb 30');
+
         test.done();
     },
 
-    "string nonsensical" : function(test) {
+    "string nonsensical" : function (test) {
         test.expect(1);
 
         test.equal(moment('fail').isValid(), false, 'string "fail"');
         test.done();
     },
 
-    "invalid string iso 8601" : function(test) {
+    "invalid string iso 8601" : function (test) {
 
         var tests = [
             '2010-00-00',
@@ -57,15 +67,16 @@ exports.is_valid = {
             '2010-01-01T23:59:60'
         ];
 
-        test.expect(tests.length);
+        test.expect(tests.length * 2);
 
         for (var i = 0; i < tests.length; i++) {
             test.equal(moment(tests[i]).isValid(), false, tests[i] + ' should be invalid');
+            test.equal(moment.utc(tests[i]).isValid(), false, tests[i] + ' should be invalid');
         }
         test.done();
     },
 
-    "invalid string iso 8601 + timezone" : function(test) {
+    "invalid string iso 8601 + timezone" : function (test) {
 
         var tests = [
             '2010-00-00+00:00',
@@ -77,15 +88,16 @@ exports.is_valid = {
             '2010-01-40T23:59:59.9999+00:00'
         ];
 
-        test.expect(tests.length);
+        test.expect(tests.length * 2);
 
         for (var i = 0; i < tests.length; i++) {
             test.equal(moment(tests[i]).isValid(), false, tests[i] + ' should be invalid');
+            test.equal(moment.utc(tests[i]).isValid(), false, tests[i] + ' should be invalid');
         }
         test.done();
     },
 
-    "valid string iso 8601 + timezone" : function(test) {
+    "valid string iso 8601 + timezone" : function (test) {
         var tests = [
             '2010-01-01',
             '2010-01-30',
@@ -95,10 +107,11 @@ exports.is_valid = {
             '2010-01-30T23:59:59.999+00:00'
         ];
 
-        test.expect(tests.length);
+        test.expect(tests.length * 2);
 
         for (var i = 0; i < tests.length; i++) {
             test.equal(moment(tests[i]).isValid(), true, tests[i] + ' should be valid');
+            test.equal(moment.utc(tests[i]).isValid(), true, tests[i] + ' should be valid');
         }
         test.done();
     }