Make sure the data- number has at least one number in it before passing to isNaN...
[jquery.git] / test / unit / data.js
index c7307bf..03d38c9 100644 (file)
@@ -158,7 +158,7 @@ test(".data(String) and .data(String, Object)", function() {
 });
 
 test("data-* attributes", function() {
-       expect(19);
+       expect(27);
        var div = jQuery("<div>"),
                child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\"></div>");
                
@@ -183,14 +183,30 @@ test("data-* attributes", function() {
                .attr("data-true", "true")
                .attr("data-false", "false")
                .attr("data-five", "5")
+               .attr("data-point", "5.5")
+               .attr("data-pointe", "5.5E3")
+               .attr("data-pointbad", "5..5")
+               .attr("data-pointbad2", "-.")
+               .attr("data-badjson", "{123}")
+               .attr("data-badjson2", "[abc]")
+               .attr("data-empty", "")
+               .attr("data-space", " ")
                .attr("data-null", "null")
                .attr("data-string", "test");
        
-       equals( child.data('true'), true, "Primitive true read from attribute");
-       equals( child.data('false'), false, "Primitive false read from attribute");
-       equals( child.data('five'), 5, "Primitive number read from attribute");
-       equals( child.data('null'), null, "Primitive null read from attribute");
-       equals( child.data('string'), "test", "Typical string read from attribute");
+       strictEqual( child.data('true'), true, "Primitive true read from attribute");
+       strictEqual( child.data('false'), false, "Primitive false read from attribute");
+       strictEqual( child.data('five'), 5, "Primitive number read from attribute");
+       strictEqual( child.data('point'), 5.5, "Primitive number read from attribute");
+       strictEqual( child.data('pointe'), 5500, "Primitive number read from attribute");
+       strictEqual( child.data('pointbad'), "5..5", "Bad number read from attribute");
+       strictEqual( child.data('pointbad2'), "-.", "Bad number read from attribute");
+       strictEqual( child.data('badjson'), "{123}", "Bad number read from attribute");
+       strictEqual( child.data('badjson2'), "[abc]", "Bad number read from attribute");
+       strictEqual( child.data('empty'), "", "Empty string read from attribute");
+       strictEqual( child.data('space'), " ", "Empty string read from attribute");
+       strictEqual( child.data('null'), null, "Primitive null read from attribute");
+       strictEqual( child.data('string'), "test", "Typical string read from attribute");
 
        child.remove();
        
@@ -207,11 +223,11 @@ test("data-* attributes", function() {
                        break;
                case 2:
                        equals(jQuery(elem).data("zoooo"), "bar", "Check zoooo property");
-                       equals(jQuery(elem).data("bar"), '{"test":"baz"}', "Check bar property");
+                       same(jQuery(elem).data("bar"), {"test":"baz"}, "Check bar property");
                        break;
                case 3:
                        equals(jQuery(elem).data("number"), true, "Check number property");
-                       equals(jQuery(elem).data("stuff"), "[2,8]", "Check stuff property");
+                       same(jQuery(elem).data("stuff"), [2,8], "Check stuff property");
                        break;
                default:
                        ok(false, ["Assertion failed on index ", index, ", with data ", data].join(''));