qunit tests for regex

a unittest for regex

HTML

<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css">
<script src="http://code.jquery.com/qunit/git/qunit.js"></script>
<h1 id="qunit-header">Unit Tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture"></div>

JavaScript

var matches = [
  ".1", ".11",  "0.11",  "10.", "10.1", "10.12", "00.00", "0.0", 
  "00.00", "123456", "12345", "1234", "123", "12", "1", "0", "0.",
  "123.", "123.55", "123456." 
],
mismatches = ["", ".", "123..", "1234567", "1a", "123.456"],
regex = /^(?!\.?$)\d{0,9}(\.\d{0,2})?$/;

function testMatch(testStrs, matched) {
    $.each(testStrs, function(i, testStr) {
        equal(matched, !!testStr.match(regex), "testing " + testStr);
    });
}

test("test matches", function() {
    testMatch(matches, true);
}); 

test("test mismatches", function() {
    testMatch(mismatches, false);
});