]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Removed comments and added tests
authorIskren Chernev <iskren.chernev@gmail.com>
Sun, 14 Jul 2013 06:39:33 +0000 (23:39 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Tue, 17 Sep 2013 07:21:03 +0000 (00:21 -0700)
moment.js
test/moment/create.js

index 743258739ff93a4d32a16731e02407254d019a8f..8a06a7b1dde97652eb4ce75c18396845c4586dbe 100644 (file)
--- a/moment.js
+++ b/moment.js
             tokens = config._f.match(formattingTokens),
             match, i, tokenIndex;
 
-        // var s = config._f;
-        // for (var i = 0; i < s.length; ++i) {
-        //     console.log(i + ": " + s[i] + " (" + s.charCodeAt(i) + ")");
-        // }
-
         // We're not interested in the result. Just the tokens and their
         // starting positions.
         config._f.replace(formattingTokens, function (token) {
                 tokenRegexp = getParseRegexForToken(token).toString();
                 // Do not remember groups
                 tokenRegexp = tokenRegexp.replace(/\(/g, '(?:');
-                // this is a real token
 
                 // regexp-escape strings in-between tokens
                 if (offset > non_token_start) {
                 }
                 non_token_start = offset + token.length;
 
-                console.log("adding " + tokenRegexp + "### " + tokenRegexp.substring(1, tokenRegexp.lastIndexOf('/')));
                 // add token regexp
                 regexp += '(' + tokenRegexp.substring(1, tokenRegexp.lastIndexOf('/')) + ')';
-            } else {
-                console.log("not a token " + token);
             }
 
             return token;
         });
         regexp = new RegExp('^' + regexp + '$');
-        console.log(regexp);
         match = config._i.match(regexp);
-        console.log(match);
         if (match === null) {
+            config._isValid = false;
             return null;
         }
 
             }
         }
 
-        console.log(config._a);
         dateFromArray(config);
     }
 
     function unescapeFormat(s) {
-        console.log("unescaping " + s);
         return s.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
-            console.log(matched, p1, p2, p3, p4);
             return p1 || p2 || p3 || p4;
         });
-        // console.log("unescape _" + s + "_");
-        // for (var i = 0; i < s.length; ++i) {
-        //     console.log(i + ": " + s[i] + " (" + s.charCodeAt(i) + ")");
-        // }
-        // console.log(s[0] + "XX" + s[s.length-2]);
-        // var res = s;
-        // if (s[0] == '[' && s[s.length-1] == ']') {
-        //     res = s.substr(1, s.length - 2);
-        //     console.log("intermid " + res);
-        // }
-        // console.log("intermid " + res);
-        // res = res.replace(/\\./, '$&');
-        // console.log("unescape " + s + " ==> " + res);
-        // return res;
     }
 
     // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
     function regexpEscape(s) {
         var res = s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
-        console.log("regexp escape " + s + " ===> " + res);
         return res;
     }
 
index 398a4b46f1d6cb70c30c7c37668afe044c351bcf..5d806cedde173281d02df6e472d3b27274aa773e 100644 (file)
@@ -492,8 +492,11 @@ exports.create = {
     },
 
     "strict parsing" : function(test) {
-        test.equal(moment("ala [ ] bala 2012-05", "[ala] \\[ \\] \b\a\l\a YYYY-MM").format("YYYY-MM"), "2012-05");
-        test.equal(moment("ala [ bala 2012-05", "[ala] \\[ \\] \b\a\l\a YYYY-MM"), null);
+        test.expect(4);
+        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.done();
     },