]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Added more tests
authorIskren Chernev <iskren.chernev@gmail.com>
Mon, 16 Sep 2013 11:09:01 +0000 (04:09 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Tue, 17 Sep 2013 07:21:03 +0000 (00:21 -0700)
test/moment/create.js

index 5d806cedde173281d02df6e472d3b27274aa773e..62c922c8dfb8032ae323bd10b95159203d7e40c4 100644 (file)
@@ -492,11 +492,20 @@ exports.create = {
     },
 
     "strict parsing" : function(test) {
-        test.expect(4);
+        test.expect(10);
         test.equal(moment("2012-05", "YYYY-MM", true).format("YYYY-MM"), "2012-05", "parse correct string");
         test.equal(moment(" 2012-05", "YYYY-MM", true).isValid(), false, "fail on extra whitespace");
         test.equal(moment("foo 2012-05", "[foo] YYYY-MM", true).format('YYYY-MM'), "2012-05", "handle fixed text");
         test.equal(moment("2012 05", "YYYY-MM", true).isValid(), false, "fail on different separator");
+
+        test.equal(moment("05 30 2010", ["DD MM YYYY", "MM DD YYYY"], true).format("MM DD YYYY"), "05 30 2010", "array with bad date");
+        test.equal(moment("05 30 2010", ["", "MM DD YYYY"], true).format("MM DD YYYY"), "05 30 2010", "array with invalid format");
+        test.equal(moment("05 30 2010", [" DD MM YYYY", "MM DD YYYY"], true).format("MM DD YYYY"), "05 30 2010", "array with non-matching format");
+
+        test.equal(moment("2010.*...", "YYYY.*", true).isValid(), false, "invalid format with regex chars");
+        test.equal(moment("2010.*", "YYYY.*", true).year(), 2010, "valid format with regex chars");
+        test.equal(moment(".*2010.*", ".*YYYY.*", true).year(), 2010, "valid format with regex chars on both sides");
+
         test.done();
     },