Bug 17254 - Acid3 *-of-type test fails
Summary: Acid3 *-of-type test fails
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Dave Hyatt
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2008-02-09 01:36 PST by Eric Seidel (no email)
Modified: 2008-02-09 15:48 PST (History)
1 user (show)

See Also:


Attachments
Patch to fix the problem. (1.93 KB, patch)
2008-02-09 15:18 PST, Dave Hyatt
mitz: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Seidel (no email) 2008-02-09 01:36:56 PST
Acid3 *-of-type test fails

Test 40: expected: 0, got: 1 - part 9:1

This will need further reduction.

    function () {
      // test 40: :first-of-type, :last-of-type, :only-of-type, :nth-of-type, :nth-last-of-type
      var elements;
      var builder = function(doc) {
        elements = [
          doc.createElement('p'),
          doc.createElement('div'),
          doc.createElement('div'),
          doc.createElement('p'),
          doc.createElement('p'),
          doc.createElement('p'),
          doc.createElement('div'),
          doc.createElement('address'),
          doc.createElement('div'),
          doc.createElement('div'),
          doc.createElement('div'),
          doc.createElement('p'),
          doc.createElement('div'),
          doc.createElement('p')
        ];
        for (var i = 0; i < elements.length; i += 1)
          doc.body.appendChild(elements[i]);
      };
      selectorTest(function (doc, add, expect) {
        builder(doc);
        var match = add(":first-of-type");
        var values = [1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0];
        for (var i = 0; i < elements.length; i += 1)
          expect(elements[i], values[i] ? match : 0, "part 1:" + i);
      });
      selectorTest(function (doc, add, expect) {
        builder(doc);
        var match = add(":last-of-type");
        var values = [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1];
        for (var i = 0; i < elements.length; i += 1)
          expect(elements[i], values[i] ? match : 0, "part 2:" + i);
      });
      selectorTest(function (doc, add, expect) {
        builder(doc);
        var match = add(":only-of-type");
        var values = [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0];
        for (var i = 0; i < elements.length; i += 1)
          expect(elements[i], values[i] ? match : 0, "part 3:" + i);
      });
      selectorTest(function (doc, add, expect) {
        builder(doc);
        var match = add(":nth-of-type(3n-1)");
        var values = [0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0];
        for (var i = 0; i < elements.length; i += 1)
          expect(elements[i], values[i] ? match : 0, "part 4:" + i);
      });
      selectorTest(function (doc, add, expect) {
        builder(doc);
        var match = add(":nth-of-type(3n+1)");
        var values = [1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0];
        for (var i = 0; i < elements.length; i += 1)
          expect(elements[i], values[i] ? match : 0, "part 5:" + i);
      });
      selectorTest(function (doc, add, expect) {
        builder(doc);
        var match = add(":nth-last-of-type(2n)");
        var values = [1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0];
        for (var i = 0; i < elements.length; i += 1)
          expect(elements[i], values[i] ? match : 0, "part 6:" + i);
      });
      selectorTest(function (doc, add, expect) {
        builder(doc);
        var match = add(":nth-last-of-type(-5n+3)");
        var values;
        values = [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0];
        for (var i = 0; i < elements.length; i += 1)
          expect(elements[i], values[i] ? match : 0, "part 7:" + i);
        doc.body.appendChild(doc.createElement('blockquote'));
        values = [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0];
        for (var i = 0; i < elements.length; i += 1)
          expect(elements[i], values[i] ? match : 0, "part 8:" + i);
        doc.body.appendChild(doc.createElement('div'));
        values = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0];
        for (var i = 0; i < elements.length; i += 1)
          expect(elements[i], values[i] ? match : 0, "part 9:" + i);
      });
      return 3;
    },
Comment 1 Dave Hyatt 2008-02-09 14:34:50 PST
The bug is with the parseNth function.  It incorrectly treats negative coefficients of n as positive.

a = nth.substring(0, n).toInt();

The above is the correction. Instead of 1, n-1 it was supposed to be 0, n.

I'll get a patch up once I've landed my other changes to CSSStyleSelector.cpp.

Comment 2 Dave Hyatt 2008-02-09 14:38:17 PST
<rdar://problem/5733886>
Comment 3 Dave Hyatt 2008-02-09 15:09:37 PST
There is more to this.  Even fixing the coefficient to be properly parsed as negative, the matchNth function is also buggy.

Comment 4 Dave Hyatt 2008-02-09 15:18:24 PST
Created attachment 19024 [details]
Patch to fix the problem.
Comment 5 Dave Hyatt 2008-02-09 15:39:10 PST
I was wrong.  matchNth is fine. :)

Comment 6 mitz 2008-02-09 15:40:22 PST
Comment on attachment 19024 [details]
Patch to fix the problem.

Could have just added a "-" there...

r=me
Comment 7 Dave Hyatt 2008-02-09 15:48:00 PST
Fixed in r30116.