Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6367

Show
Ignore:
Timestamp:
03/09/07 04:15:48 (2 years ago)
Author:
sam
Message:

prototype: Detabify test/unit/selector.html

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/prototype/trunk/test/unit/selector.html

    r6366 r6367  
    11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    2                                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     2        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    33<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" 
    44 xmlns:html="http://www.w3.org/1999/xhtml"> 
    55<head> 
    6        <title>Prototype Unit test file</title> 
    7        <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    8        <script src="../../dist/prototype.js" type="text/javascript"></script> 
    9        <script src="../lib/unittest.js" type="text/javascript"></script> 
    10        <link rel="stylesheet" href="../test.css" type="text/css" /> 
    11        <style type="text/css" media="screen"> 
    12        /* <![CDATA[ */ 
    13                #testcss1 { font-size:11px; color: #f00; } 
    14                #testcss2 { font-size:12px; color: #0f0; display: none; } 
    15        /* ]]> */ 
    16        </style> 
     6  <title>Prototype Unit test file</title> 
     7  <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
     8  <script src="../../dist/prototype.js" type="text/javascript"></script> 
     9  <script src="../lib/unittest.js" type="text/javascript"></script> 
     10  <link rel="stylesheet" href="../test.css" type="text/css" /> 
     11  <style type="text/css" media="screen"> 
     12  /* <![CDATA[ */ 
     13    #testcss1 { font-size:11px; color: #f00; } 
     14    #testcss2 { font-size:12px; color: #0f0; display: none; } 
     15  /* ]]> */ 
     16  </style> 
    1717</head> 
    1818<body> 
    1919<h1>Prototype Unit test file</h1> 
    2020<p> 
    21        Test of utility functions in selector.js 
     21  Test of utility functions in selector.js 
    2222</p> 
    2323 
    2424<div id="fixtures" style="display: none"> 
    25        <h1 class="title">Some title <span>here</span></h1> 
    26        <p id="p" class="first summary"> 
    27                <strong id="strong">This</strong> is a short blurb 
    28                <a id="link_1" class="first internal" rel="external nofollow" href="#">with a link</a> or  
    29                <a id="link_2" class="internal highlight" href="#"><em id="em">two</em></a>. 
    30                Or <cite id="with_title" title="hello world!">a citation</cite>. 
    31        </p> 
    32        <ul id="list"> 
    33                <li id="item_1" class="first"><a id="link_3" href="#" class="external"><span id="span">Another link</span></a></li> 
    34                <li id="item_2">Some text</li> 
    35                <li id="item_3" xml:lang="es-us" class="">Otra cosa</li> 
    36        </ul> 
    37  
    38        <!-- this form has a field with the name 'id', 
    39                therefore its ID property won't be 'troubleForm': --> 
    40        <form id="troubleForm"> 
    41                <input type="hidden" name="id" id="hidden" /> 
    42                <input type="text" name="disabled_text_field" id="disabled_text_field" disabled="disabled" /> 
    43                <input type="text" name="enabled_text_field" id="enabled_text_field" /> 
    44                <input type="checkbox" name="checkboxes" id="checked_box" checked="checked" value="Checked" /> 
    45                <input type="checkbox" name="checkboxes" id="unchecked_box" value="Unchecked"/> 
    46                <input type="radio" name="radiobuttons" id="checked_radio" checked="checked" value="Checked" /> 
    47                <input type="radio" name="radiobuttons" id="unchecked_radio" value="Unchecked" /> 
    48        </form> 
    49          
    50        <div id="level1"> 
    51                <span id="level2_1"> 
    52                        <span id="level3_1"></span> 
    53                        <!-- This comment should be ignored by the adjacent selector --> 
    54                        <span id="level3_2"></span> 
    55                </span> 
    56                <span id="level2_2"> 
    57                         <em id="level_only_child">               
    58                        </em> 
    59                </span> 
    60                <div id="level2_3"></div> 
    61        </div> <!-- #level1 --> 
    62  
    63        <div id="dupContainer"> 
    64                <span id="dupL1"> 
    65                        <span id="dupL2"> 
    66                                <span id="dupL3"> 
    67                                        <span id="dupL4"> 
    68                                                <span id="dupL5"></span> 
    69                                        </span> 
    70                                </span> 
    71                        </span> 
    72                </span> 
    73        </div> <!-- #dupContainer --> 
    74  
    75         <div id="grandfather"> grandfather               
    76                <div id="father" class="brothers men"> father                     
    77                        <div id="son"> son </div> 
    78                </div> 
    79                <div id="uncle" class="brothers men"> uncle </div> 
    80         </div>   
    81  
    82        <form id="commaParent" title="commas,are,good"> 
    83                <input type="hidden" id="commaChild" name="foo" value="#commaOne,#commaTwo" /> 
    84                <input type="hidden" id="commaTwo" name="foo2" value="oops" /> 
    85        </form> 
    86          
     25  <h1 class="title">Some title <span>here</span></h1> 
     26  <p id="p" class="first summary"> 
     27    <strong id="strong">This</strong> is a short blurb 
     28    <a id="link_1" class="first internal" rel="external nofollow" href="#">with a link</a> or  
     29    <a id="link_2" class="internal highlight" href="#"><em id="em">two</em></a>. 
     30    Or <cite id="with_title" title="hello world!">a citation</cite>. 
     31  </p> 
     32  <ul id="list"> 
     33    <li id="item_1" class="first"><a id="link_3" href="#" class="external"><span id="span">Another link</span></a></li> 
     34    <li id="item_2">Some text</li> 
     35    <li id="item_3" xml:lang="es-us" class="">Otra cosa</li> 
     36  </ul> 
     37 
     38  <!-- this form has a field with the name 'id', 
     39    therefore its ID property won't be 'troubleForm': --> 
     40  <form id="troubleForm"> 
     41    <input type="hidden" name="id" id="hidden" /> 
     42    <input type="text" name="disabled_text_field" id="disabled_text_field" disabled="disabled" /> 
     43    <input type="text" name="enabled_text_field" id="enabled_text_field" /> 
     44    <input type="checkbox" name="checkboxes" id="checked_box" checked="checked" value="Checked" /> 
     45    <input type="checkbox" name="checkboxes" id="unchecked_box" value="Unchecked"/> 
     46    <input type="radio" name="radiobuttons" id="checked_radio" checked="checked" value="Checked" /> 
     47    <input type="radio" name="radiobuttons" id="unchecked_radio" value="Unchecked" /> 
     48  </form> 
     49   
     50  <div id="level1"> 
     51    <span id="level2_1"> 
     52      <span id="level3_1"></span> 
     53      <!-- This comment should be ignored by the adjacent selector --> 
     54      <span id="level3_2"></span> 
     55    </span> 
     56    <span id="level2_2"> 
     57      <em id="level_only_child">     
     58      </em> 
     59    </span> 
     60    <div id="level2_3"></div> 
     61  </div> <!-- #level1 --> 
     62 
     63  <div id="dupContainer"> 
     64    <span id="dupL1"> 
     65      <span id="dupL2"> 
     66        <span id="dupL3"> 
     67          <span id="dupL4"> 
     68            <span id="dupL5"></span> 
     69          </span> 
     70        </span> 
     71      </span> 
     72    </span> 
     73  </div> <!-- #dupContainer --> 
     74 
     75  <div id="grandfather"> grandfather     
     76    <div id="father" class="brothers men"> father       
     77      <div id="son"> son </div> 
     78    </div> 
     79    <div id="uncle" class="brothers men"> uncle </div> 
     80  </div>   
     81 
     82  <form id="commaParent" title="commas,are,good"> 
     83    <input type="hidden" id="commaChild" name="foo" value="#commaOne,#commaTwo" /> 
     84    <input type="hidden" id="commaTwo" name="foo2" value="oops" /> 
     85  </form> 
     86   
    8787</div> <!-- #fixtures --> 
    8888 
     
    9494// <![CDATA[ 
    9595 
    96        // Added by TDD - 2007.02.20 
    97        $RunBenchmarks = false; 
    98  
    99        new Test.Unit.Runner({ 
    100                  
    101                testSelectorWithTagName: function() {with(this) { 
    102                        assertEnumEqual($A(document.getElementsByTagName('li')), $$('li')); 
    103                        assertEnumEqual([$('strong')], $$('strong')); 
    104                        assertEnumEqual([], $$('nonexistent')); 
    105                        assertEnumEqual($A(document.getElementsByTagName('*')), $$('*')); 
    106                }}, 
    107                  
    108                testSelectorWithId: function() {with(this) { 
    109                        assertEnumEqual([$('fixtures')], $$('#fixtures')); 
    110                        assertEnumEqual([], $$('#nonexistent')); 
    111                        assertEnumEqual([$('troubleForm')], $$('#troubleForm')); 
    112                }}, 
    113                  
    114                testSelectorWithClassName: function() {with(this) { 
    115                        assertEnumEqual($('p', 'link_1', 'item_1'), $$('.first')); 
    116                        assertEnumEqual([], $$('.second')); 
    117                }}, 
    118                  
    119                testSelectorWithTagNameAndId: function() {with(this) { 
    120                        assertEnumEqual([$('strong')], $$('strong#strong')); 
    121                        assertEnumEqual([], $$('p#strong')); 
    122                }}, 
    123                  
    124                testSelectorWithTagNameAndClassName: function() {with(this) { 
    125                        assertEnumEqual($('link_1', 'link_2'), $$('a.internal')); 
    126                        assertEnumEqual([$('link_2')], $$('a.internal.highlight')); 
    127                        assertEnumEqual([$('link_2')], $$('a.highlight.internal')); 
    128                        assertEnumEqual([], $$('a.highlight.internal.nonexistent')); 
    129                }}, 
    130                  
    131                testSelectorWithIdAndClassName: function() {with(this) { 
    132                        assertEnumEqual([$('link_2')], $$('#link_2.internal')); 
    133                        assertEnumEqual([$('link_2')], $$('.internal#link_2')); 
    134                        assertEnumEqual([$('link_2')], $$('#link_2.internal.highlight')); 
    135                        assertEnumEqual([], $$('#link_2.internal.nonexistent')); 
    136                }}, 
    137                  
    138                testSelectorWithTagNameAndIdAndClassName: function() {with(this) { 
    139                        assertEnumEqual([$('link_2')], $$('a#link_2.internal')); 
    140                        assertEnumEqual([$('link_2')], $$('a.internal#link_2')); 
    141                        assertEnumEqual([$('item_1')], $$('li#item_1.first')); 
    142                        assertEnumEqual([], $$('li#item_1.nonexistent')); 
    143                        assertEnumEqual([], $$('li#item_1.first.nonexistent')); 
    144                }}, 
    145                  
    146                test$$MatchesAncestryWithTokensSeparatedByWhitespace: function() {with(this) { 
    147                        assertEnumEqual($('em', 'span'), $$('#fixtures a *')); 
    148                        assertEnumEqual([$('p')], $$('div#fixtures p')); 
    149                }}, 
    150                  
    151                test$$CombinesResultsWhenMultipleExpressionsArePassed: function() {with(this) { 
    152                        assertEnumEqual($('link_1', 'link_2', 'item_1', 'item_2', 'item_3'), $$('#p a', ' ul#list li ')); 
    153                }}, 
    154  
    155                testSelectorWithTagNameAndAttributeExistence: function() {with(this) { 
    156                        assertEnumEqual($$('#fixtures h1'), $$('h1[class]')); 
    157                        assertEnumEqual($$('#fixtures h1'), $$('h1[CLASS]')); 
    158                        assertEnumEqual([$('item_3')], $$('li#item_3[class]')); 
    159                }}, 
    160                  
    161                testSelectorWithTagNameAndSpecificAttributeValue: function() {with(this) { 
    162                        assertEnumEqual($('link_1', 'link_2', 'link_3'), $$('a[href="#"]')); 
    163                        assertEnumEqual($('link_1', 'link_2', 'link_3'), $$('a[href=#]')); 
    164                }}, 
    165                  
    166                testSelectorWithTagNameAndWhitespaceTokenizedAttributeValue: function() {with(this) { 
    167                        assertEnumEqual($('link_1', 'link_2'), $$('a[class~="internal"]')); 
    168                        assertEnumEqual($('link_1', 'link_2'), $$('a[class~=internal]')); 
    169                }}, 
    170                  
    171                testSelectorWithUniversalAndHyphenTokenizedAttributeValue: function() {with(this) { 
    172                        assertEnumEqual([$('item_3')], $$('*[xml:lang|="es"]')); 
    173                        assertEnumEqual([$('item_3')], $$('*[xml:lang|="ES"]')); 
    174                }}, 
    175                  
    176                testSelectorWithTagNameAndNegatedAttributeValue: function() {with(this) { 
    177                        assertEnumEqual([], $$('a[href!=#]')); 
    178                }}, 
    179                  
    180                test$$WithNestedAttributeSelectors: function() {with(this) { 
    181                        assertEnumEqual([$('strong')], $$('div[style] p[id] strong')); 
    182                }}, 
    183                  
    184                testSelectorWithMultipleConditions: function() {with(this) { 
    185                        assertEnumEqual([$('link_3')], $$('a[class~=external][href="#"]')); 
    186                        assertEnumEqual([], $$('a[class~=external][href!="#"]')); 
    187                }}, 
    188                  
    189                testSelectorMatchElements: function() {with(this) { 
    190                        assertElementsMatch(Selector.matchElements($('list').descendants(), 'li'), '#item_1', '#item_2', '#item_3'); 
    191                        assertElementsMatch(Selector.matchElements($('fixtures').descendants(), 'a.internal'), '#link_1', '#link_2'); 
    192                        assertEnumEqual([], Selector.matchElements($('fixtures').descendants(), 'p.last')); 
    193                }}, 
    194                  
    195                testSelectorFindElement: function() {with(this) { 
    196                        assertElementMatches(Selector.findElement($('list').descendants(), 'li'), 'li#item_1.first'); 
    197                        assertElementMatches(Selector.findElement($('list').descendants(), 'li', 1), 'li#item_2'); 
    198                        assertElementMatches(Selector.findElement($('list').descendants(), 'li#item_3'), 'li'); 
    199                        assertEqual(undefined, Selector.findElement($('list').descendants(), 'em')); 
    200                }}, 
    201  
    202                testSelectorWithSpaceInAttributeValue: function() {with(this) { 
    203                        assertEnumEqual([$('with_title')], $$('cite[title="hello world!"]')); 
    204                }}, 
    205                  
    206                // AND NOW COME THOSE NEW TESTS AFTER ANDREW'S REWRITE! 
    207  
    208                testSelectorWithNamespacedAttributes: function() { with(this) { 
    209                        if (Prototype.BrowserFeatures.XPath) { 
    210                                assertUndefined(new Selector('html[xml:lang]').xpath); 
    211                                assertUndefined(new Selector('body p[xml:lang]').xpath); 
    212                        } else 
    213                                info("Could not test XPath bypass: no XPath to begin with!"); 
    214                }}, 
    215  
    216                testSelectorWithChild: function() { with(this) { 
    217                        assertEnumEqual($('link_1', 'link_2'), $$('p.first > a')); 
    218                        assertEnumEqual($('father', 'uncle'), $$('div#grandfather > div')); 
    219                        assertEnumEqual($('level2_1', 'level2_2'), $$('#level1>span')); 
    220                        assertEnumEqual($('level2_1', 'level2_2'), $$('#level1 > span')); 
    221                        assertEnumEqual($('level3_1', 'level3_2'), $$('#level2_1 > *')); 
    222                        $RunBenchmarks && wait(500, function() { 
    223                                benchmark(function() { $$('#level1 > span') }, 1000); 
    224                        }); 
    225                }}, 
    226  
    227                testSelectorWithAdjacence: function() { with(this) { 
    228                        assertEnumEqual([$('uncle')], $$('div.brothers + div.brothers')); 
    229                         assertEnumEqual([$('uncle')], $$('div.brothers + div'));                         
    230                        assertEqual($('level2_2'), $$('#level2_1+span').reduce()); 
    231                        assertEqual($('level2_2'), $$('#level2_1 + span').reduce()); 
    232                        assertEqual($('level2_2'), $$('#level2_1 + *').reduce()); 
    233                        assertEnumEqual([], $$('#level2_2 + span')); 
    234                        assertEqual($('level3_2'), $$('#level3_1 + span').reduce()); 
    235                        assertEqual($('level3_2'), $$('#level3_1 + *').reduce()); 
    236                        assertEnumEqual([], $$('#level3_2 + *')); 
    237                        assertEnumEqual([], $$('#level3_1 + em')); 
    238                        $RunBenchmarks && wait(500, function() { 
    239                                benchmark(function() { $$('#level3_1 + span') }, 1000); 
    240                        }); 
    241                }}, 
    242  
    243                testSelectorWithLaterSibling: function() { with(this) { 
    244                        assertEnumEqual([$('list')], $$('h1 ~ ul')); 
    245                        assertEqual($('level2_2'), $$('#level2_1 ~ span').reduce()); 
    246                        assertEnumEqual($('level2_2', 'level2_3'), $$('#level2_1 ~ *').reduce()); 
    247                        assertEnumEqual([], $$('#level2_2 ~ span')); 
    248                        assertEnumEqual([], $$('#level3_2 ~ *')); 
    249                        assertEnumEqual([], $$('#level3_1 ~ em')); 
    250                        assertEnumEqual([$('level3_2')], $$('#level3_1 ~ #level3_2')); 
    251                        assertEnumEqual([$('level3_2')], $$('span ~ #level3_2')); 
    252                        assertEnumEqual([], $$('div ~ #level3_2')); 
    253                        assertEnumEqual([], $$('div ~ #level2_3')); 
    254                        $RunBenchmarks && wait(500, function() { 
    255                                benchmark(function() { $$('#level2_1 ~ span') }, 1000); 
    256                        }); 
    257                }}, 
    258  
    259                testSelectorWithNewAttributeOperators: function() { with(this) { 
    260                        assertEnumEqual($('father', 'uncle'), $$('div[class^=bro]'), 'matching beginning of string'); 
    261                        assertEnumEqual($('father', 'uncle'), $$('div[class$=men]'), 'matching end of string'); 
    262                        assertEnumEqual($('father', 'uncle'), $$('div[class*="ers m"]'), 'matching substring') 
    263                        assertEnumEqual($('level2_1', 'level2_2', 'level2_3'), $$('#level1 *[id^="level2_"]')); 
    264                        assertEnumEqual($('level2_1', 'level2_2', 'level2_3'), $$('#level1 *[id^=level2_]')); 
    265                        assertEnumEqual($('level2_1', 'level3_1'), $$('#level1 *[id$="_1"]')); 
    266                        assertEnumEqual($('level2_1', 'level3_1'), $$('#level1 *[id$=_1]')); 
    267                        assertEnumEqual($('level2_1', 'level3_2', 'level2_2', 'level2_3'), $$('#level1 *[id*="2"]')); 
    268                        assertEnumEqual($('level2_1', 'level3_2', 'level2_2', 'level2_3'), $$('#level1 *[id*=2]')); 
    269                        $RunBenchmarks && wait(500, function() { 
    270                                benchmark(function() { $$('#level1 *[id^=level2_]') }, 1000, '[^=]'); 
    271                                benchmark(function() { $$('#level1 *[id$=_1]') }, 1000, '[$=]'); 
    272                                benchmark(function() { $$('#level1 *[id*=_2]') }, 1000, '[*=]'); 
    273                        }); 
    274                }}, 
    275  
    276                testSelectorWithDuplicates: function() { with(this) { 
    277                        assertEnumEqual($$('div div'), $$('div div').uniq()); 
    278                        assertEnumEqual($('dupL2', 'dupL3', 'dupL4', 'dupL5'), $$('#dupContainer span span')); 
    279                        $RunBenchmarks && wait(500, function() { 
    280                                benchmark(function() { $$('#dupContainer span span') }, 1000); 
    281                        }); 
    282                }}, 
    283  
    284                testSelectorWithFirstLastOnlyNthNthLastChild: function() { with(this) { 
    285                        assertEnumEqual([$('level2_1')], $$('#level1>*:first-child')); 
    286                        assertEnumEqual($('level2_1', 'level3_1', 'level_only_child'), $$('#level1 *:first-child')); 
    287                        assertEnumEqual([$('level2_3')], $$('#level1>*:last-child')); 
    288                        assertEnumEqual($('level3_2', 'level_only_child', 'level2_3'), $$('#level1 *:last-child')); 
    289                        assertEnumEqual([$('level2_3')], $$('#level1>div:last-child')); 
    290                        assertEnumEqual([$('level2_3')], $$('#level1 div:last-child')); 
    291                        assertEnumEqual([], $$('#level1>div:first-child')); 
    292                        assertEnumEqual([], $$('#level1>span:last-child')); 
    293                        assertEnumEqual($('level2_1', 'level3_1'), $$('#level1 span:first-child')); 
    294                        assertEnumEqual([], $$('#level1:first-child')); 
    295                        assertEnumEqual([], $$('#level1>*:only-child')); 
    296                        assertEnumEqual([$('level_only_child')], $$('#level1 *:only-child')); 
    297                        assertEnumEqual([], $$('#level1:only-child')); 
    298                        assertEnumEqual([$('link_2')], $$('#p *:nth-last-child(2)'), 'nth-last-child'); 
    299                        assertEnumEqual([$('link_2')], $$('#p *:nth-child(3)'), 'nth-child'); 
    300                        assertEnumEqual([$('link_2')], $$('#p a:nth-child(3)'), 'nth-child'); 
    301                        $RunBenchmarks && wait(500, function() { 
    302                                benchmark(function() { $$('#level1 *:first-child') }, 1000, ':first-child'); 
    303                                benchmark(function() { $$('#level1 *:last-child') }, 1000, ':last-child'); 
    304                                benchmark(function() { $$('#level1 *:only-child') }, 1000, ':only-child'); 
    305                        }); 
    306                }}, 
    307                  
    308                testSelectorWithFirstLastNthNthLastOfType: function() {with(this) { 
    309                        assertEnumEqual([$('link_2')], $$('#p a:nth-of-type(2)'), 'nth-of-type'); 
    310                        assertEnumEqual([$('link_1')], $$('#p a:nth-of-type(1)'), 'nth-of-type'); 
    311                        assertEnumEqual([$('link_2')], $$('#p a:nth-last-of-type(1)'), 'nth-last-of-type'); 
    312                        assertEnumEqual([$('link_1')], $$('#p a:first-of-type'), 'first-of-type'); 
    313                        assertEnumEqual([$('link_2')], $$('#p a:last-of-type'), 'last-of-type'); 
    314                }}, 
    315                  
    316                testSelectorWithNot: function() {with(this) { 
    317                        assertEnumEqual([$('link_2')], $$('#p a:not(:first-of-type)')); 
    318                        assertEnumEqual([$('link_1')], $$('#p a:not(:last-of-type)')); 
    319                        assertEnumEqual([$('link_2')], $$('#p a:not(:nth-of-type(1))')); 
    320                        assertEnumEqual([$('link_1')], $$('#p a:not(:nth-last-of-type(1))')); 
    321                        assertEnumEqual([$('link_2')], $$('#p a:not([rel~=nofollow])')); 
    322                        assertEnumEqual([$('link_2')], $$('#p a:not([rel^=external])')); 
    323                        assertEnumEqual([$('link_2')], $$('#p a:not([rel$=nofollow])')); 
    324                }}, 
    325                  
    326                testSelectorWithEnabledDisabledChecked: function() {with(this) { 
    327                        assertEnumEqual([$('disabled_text_field')], $$('#troubleForm > *:disabled')); 
    328                        assertEnumEqual($('troubleForm').getInputs().without($('disabled_text_field')), $$('#troubleForm > *:enabled')); 
    329                        assertEnumEqual($('checked_box', 'checked_radio'), $$('#troubleForm *:checked')); 
    330                }}, 
    331                  
    332                testSelectorWithEmpty: function() {with(this) { 
    333                        assertEnumEqual($('level3_1', 'level3_2', 'level_only_child', 'level2_3'), $$('#level1 *:empty')); 
    334                        assertEnumEqual([$('level_only_child')], $$('#level_only_child:empty')); 
    335                }},               
    336                  
    337                testIdenticalResultsFromEquivalentSelectors: function() {with(this) { 
    338                        assertEnumEqual($$('div.brothers'), $$('div[class~=brothers]')); 
    339                        assertEnumEqual($$('div.brothers'), $$('div[class~=brothers].brothers')); 
    340                        assertEnumEqual($$('div:not(.brothers)'), $$('div:not([class~=brothers])')); 
    341                        assertEnumEqual($$('li ~ li'), $$('li:not(:first-child)')); 
    342                        assertEnumEqual($$('ul > li'), $$('ul > li:nth-child(n)')); 
    343                        assertEnumEqual($$('ul > li:nth-child(even)'), $$('ul > li:nth-child(2n)')); 
    344                        assertEnumEqual($$('ul > li:nth-child(odd)'), $$('ul > li:nth-child(2n+1)')); 
    345                        assertEnumEqual($$('ul > li:first-child'), $$('ul > li:nth-child(1)')); 
    346                        assertEnumEqual($$('ul > li:last-child'), $$('ul > li:nth-last-child(1)')); 
    347                        assertEnumEqual($$('#troubleForm *:enabled'), $$('#troubleForm *:not(:disabled)')); 
    348                }}, 
    349                  
    350                testSelectorsThatShouldReturnNothing: function() {with(this) { 
    351                        assertEnumEqual([], $$('span:empty > *')); 
    352                        assertEnumEqual([], $$('div.brothers:not(.brothers)')); 
    353                        assertEnumEqual([], $$('#level2_2 :only-child:not(:last-child)')); 
    354                        assertEnumEqual([], $$('#level2_2 :only-child:not(:first-child)')); 
    355                }}, 
    356  
    357                testCommasFor$$: function() {with(this) { 
    358                        assertEnumEqual($('list', 'p', 'link_1', 'item_1', 'item_3', 'troubleForm'), $$('#list, .first,*[xml:lang="es-us"] , #troubleForm')); 
    359                        assertEnumEqual($('list', 'p', 'link_1', 'item_1', 'item_3', 'troubleForm'), $$('#list, .first,', '*[xml:lang="es-us"] , #troubleForm')); 
    360                        assertEnumEqual($('commaParent', 'commaChild'), $$('form[title*="commas,"], input[value="#commaOne,#commaTwo"]')); 
    361                        assertEnumEqual($('commaParent', 'commaChild'), $$('form[title*="commas,"]', 'input[value="#commaOne,#commaTwo"]')); 
    362                }} 
    363        }, 'testlog'); 
     96  // Added by TDD - 2007.02.20 
     97  $RunBenchmarks = false; 
     98 
     99  new Test.Unit.Runner({ 
     100     
     101    testSelectorWithTagName: function() {with(this) { 
     102      assertEnumEqual($A(document.getElementsByTagName('li')), $$('li')); 
     103      assertEnumEqual([$('strong')], $$('strong')); 
     104      assertEnumEqual([], $$('nonexistent')); 
     105      assertEnumEqual($A(document.getElementsByTagName('*')), $$('*')); 
     106    }}, 
     107     
     108    testSelectorWithId: function() {with(this) { 
     109      assertEnumEqual([$('fixtures')], $$('#fixtures')); 
     110      assertEnumEqual([], $$('#nonexistent')); 
     111      assertEnumEqual([$('troubleForm')], $$('#troubleForm')); 
     112    }}, 
     113     
     114    testSelectorWithClassName: function() {with(this) { 
     115      assertEnumEqual($('p', 'link_1', 'item_1'), $$('.first')); 
     116      assertEnumEqual([], $$('.second')); 
     117    }}, 
     118     
     119    testSelectorWithTagNameAndId: function() {with(this) { 
     120      assertEnumEqual([$('strong')], $$('strong#strong')); 
     121      assertEnumEqual([], $$('p#strong')); 
     122    }}, 
     123     
     124    testSelectorWithTagNameAndClassName: function() {with(this) { 
     125      assertEnumEqual($('link_1', 'link_2'), $$('a.internal')); 
     126      assertEnumEqual([$('link_2')], $$('a.internal.highlight')); 
     127      assertEnumEqual([$('link_2')], $$('a.highlight.internal')); 
     128      assertEnumEqual([], $$('a.highlight.internal.nonexistent')); 
     129    }}, 
     130     
     131    testSelectorWithIdAndClassName: function() {with(this) { 
     132      assertEnumEqual([$('link_2')], $$('#link_2.internal')); 
     133      assertEnumEqual([$('link_2')], $$('.internal#link_2')); 
     134      assertEnumEqual([$('link_2')], $$('#link_2.internal.highlight')); 
     135      assertEnumEqual([], $$('#link_2.internal.nonexistent')); 
     136    }}, 
     137     
     138    testSelectorWithTagNameAndIdAndClassName: function() {with(this) { 
     139      assertEnumEqual([$('link_2')], $$('a#link_2.internal')); 
     140      assertEnumEqual([$('link_2')], $$('a.internal#link_2')); 
     141      assertEnumEqual([$('item_1')], $$('li#item_1.first')); 
     142      assertEnumEqual([], $$('li#item_1.nonexistent')); 
     143      assertEnumEqual([], $$('li#item_1.first.nonexistent')); 
     144    }}, 
     145     
     146    test$$MatchesAncestryWithTokensSeparatedByWhitespace: function() {with(this) { 
     147      assertEnumEqual($('em', 'span'), $$('#fixtures a *')); 
     148      assertEnumEqual([$('p')], $$('div#fixtures p')); 
     149    }}, 
     150     
     151    test$$CombinesResultsWhenMultipleExpressionsArePassed: function() {with(this) { 
     152      assertEnumEqual($('link_1', 'link_2', 'item_1', 'item_2', 'item_3'), $$('#p a', ' ul#list li ')); 
     153    }}, 
     154 
     155    testSelectorWithTagNameAndAttributeExistence: function() {with(this) { 
     156      assertEnumEqual($$('#fixtures h1'), $$('h1[class]')); 
     157      assertEnumEqual($$('#fixtures h1'), $$('h1[CLASS]')); 
     158      assertEnumEqual([$('item_3')], $$('li#item_3[class]')); 
     159    }}, 
     160     
     161    testSelectorWithTagNameAndSpecificAttributeValue: function() {with(this) { 
     162      assertEnumEqual($('link_1', 'link_2', 'link_3'), $$('a[href="#"]')); 
     163      assertEnumEqual($('link_1', 'link_2', 'link_3'), $$('a[href=#]')); 
     164    }}, 
     165     
     166    testSelectorWithTagNameAndWhitespaceTokenizedAttributeValue: function() {with(this) { 
     167      assertEnumEqual($('link_1', 'link_2'), $$('a[class~="internal"]')); 
     168      assertEnumEqual($('link_1', 'link_2'), $$('a[class~=internal]')); 
     169    }}, 
     170     
     171    testSelectorWithUniversalAndHyphenTokenizedAttributeValue: function() {with(this) { 
     172      assertEnumEqual([$('item_3')], $$('*[xml:lang|="es"]')); 
     173      assertEnumEqual([$('item_3')], $$('*[xml:lang|="ES"]')); 
     174    }}, 
     175     
     176    testSelectorWithTagNameAndNegatedAttributeValue: function() {with(this) { 
     177      assertEnumEqual([], $$('a[href!=#]')); 
     178    }}, 
     179     
     180    test$$WithNestedAttributeSelectors: function() {with(this) { 
     181      assertEnumEqual([$('strong')], $$('div[style] p[id] strong')); 
     182    }}, 
     183     
     184    testSelectorWithMultipleConditions: function() {with(this) { 
     185      assertEnumEqual([$('link_3')], $$('a[class~=external][href="#"]')); 
     186      assertEnumEqual([], $$('a[class~=external][href!="#"]')); 
     187    }}, 
     188     
     189    testSelectorMatchElements: function() {with(this) { 
     190      assertElementsMatch(Selector.matchElements($('list').descendants(), 'li'), '#item_1', '#item_2', '#item_3'); 
     191      assertElementsMatch(Selector.matchElements($('fixtures').descendants(), 'a.internal'), '#link_1', '#link_2'); 
     192      assertEnumEqual([], Selector.matchElements($('fixtures').descendants(), 'p.last')); 
     193    }}, 
     194     
     195    testSelectorFindElement: function() {with(this) { 
     196      assertElementMatches(Selector.findElement($('list').descendants(), 'li'), 'li#item_1.first'); 
     197      assertElementMatches(Selector.findElement($('list').descendants(), 'li', 1), 'li#item_2'); 
     198      assertElementMatches(Selector.findElement($('list').descendants(), 'li#item_3'), 'li'); 
     199      assertEqual(undefined, Selector.findElement($('list').descendants(), 'em')); 
     200    }}, 
     201 
     202    testSelectorWithSpaceInAttributeValue: function() {with(this) { 
     203      assertEnumEqual([$('with_title')], $$('cite[title="hello world!"]')); 
     204    }}, 
     205     
     206    // AND NOW COME THOSE NEW TESTS AFTER ANDREW'S REWRITE! 
     207 
     208    testSelectorWithNamespacedAttributes: function() { with(this) { 
     209      if (Prototype.BrowserFeatures.XPath) { 
     210        assertUndefined(new Selector('html[xml:lang]').xpath); 
     211        assertUndefined(new Selector('body p[xml:lang]').xpath); 
     212      } else 
     213        info("Could not test XPath bypass: no XPath to begin with!"); 
     214    }}, 
     215 
     216    testSelectorWithChild: function() { with(this) { 
     217      assertEnumEqual($('link_1', 'link_2'), $$('p.first > a')); 
     218      assertEnumEqual($('father', 'uncle'), $$('div#grandfather > div')); 
     219      assertEnumEqual($('level2_1', 'level2_2'), $$('#level1>span')); 
     220      assertEnumEqual($('level2_1', 'level2_2'), $$('#level1 > span')); 
     221      assertEnumEqual($('level3_1', 'level3_2'), $$('#level2_1 > *')); 
     222      $RunBenchmarks && wait(500, function() { 
     223        benchmark(function() { $$('#level1 > span') }, 1000); 
     224      }); 
     225    }}, 
     226 
     227    testSelectorWithAdjacence: function() { with(this) { 
     228      assertEnumEqual([$('uncle')], $$('div.brothers + div.brothers')); 
     229      assertEnumEqual([$('uncle')], $$('div.brothers + div'));       
     230      assertEqual($('level2_2'), $$('#level2_1+span').reduce()); 
     231      assertEqual($('level2_2'), $$('#level2_1 + span').reduce()); 
     232      assertEqual($('level2_2'), $$('#level2_1 + *').reduce()); 
     233      assertEnumEqual([], $$('#level2_2 + span')); 
     234      assertEqual($('level3_2'), $$('#level3_1 + span').reduce()); 
     235      assertEqual($('level3_2'), $$('#level3_1 + *').reduce()); 
     236      assertEnumEqual([], $$('#level3_2 + *')); 
     237      assertEnumEqual([], $$('#level3_1 + em')); 
     238      $RunBenchmarks && wait(500, function() { 
     239        benchmark(function() { $$('#level3_1 + span') }, 1000); 
     240      }); 
     241    }}, 
     242 
     243    testSelectorWithLaterSibling: function() { with(this) { 
     244      assertEnumEqual([$('list')], $$('h1 ~ ul')); 
     245      assertEqual($('level2_2'), $$('#level2_1 ~ span').reduce()); 
     246      assertEnumEqual($('level2_2', 'level2_3'), $$('#level2_1 ~ *').reduce()); 
     247      assertEnumEqual([], $$('#level2_2 ~ span')); 
     248      assertEnumEqual([], $$('#level3_2 ~ *')); 
     249      assertEnumEqual([], $$('#level3_1 ~ em')); 
     250      assertEnumEqual([$('level3_2')], $$('#level3_1 ~ #level3_2')); 
     251      assertEnumEqual([$('level3_2')], $$('span ~ #level3_2')); 
     252      assertEnumEqual([], $$('div ~ #level3_2')); 
     253      assertEnumEqual([], $$('div ~ #level2_3')); 
     254      $RunBenchmarks && wait(500, function() { 
     255        benchmark(function() { $$('#level2_1 ~ span') }, 1000); 
     256      }); 
     257    }}, 
     258 
     259    testSelectorWithNewAttributeOperators: function() { with(this) { 
     260      assertEnumEqual($('father', 'uncle'), $$('div[class^=bro]'), 'matching beginning of string'); 
     261      assertEnumEqual($('father', 'uncle'), $$('div[class$=men]'), 'matching end of string'); 
     262      assertEnumEqual($('father', 'uncle'), $$('div[class*="ers m"]'), 'matching substring') 
     263      assertEnumEqual($('level2_1', 'level2_2', 'level2_3'), $$('#level1 *[id^="level2_"]')); 
     264      assertEnumEqual($('level2_1', 'level2_2', 'level2_3'), $$('#level1 *[id^=level2_]')); 
     265      assertEnumEqual($('level2_1', 'level3_1'), $$('#level1 *[id$="_1"]')); 
     266      assertEnumEqual($('level2_1', 'level3_1'), $$('#level1 *[id$=_1]')); 
     267      assertEnumEqual($('level2_1', 'level3_2', 'level2_2', 'level2_3'), $$('#level1 *[id*="2"]')); 
     268      assertEnumEqual($('level2_1', 'level3_2', 'level2_2', 'level2_3'), $$('#level1 *[id*=2]')); 
     269      $RunBenchmarks && wait(500, function() { 
     270        benchmark(function() { $$('#level1 *[id^=level2_]') }, 1000, '[^=]'); 
     271        benchmark(function() { $$('#level1 *[id$=_1]') }, 1000, '[$=]'); 
     272        benchmark(function() { $$('#level1 *[id*=_2]') }, 1000, '[*=]'); 
     273      }); 
     274    }}, 
     275 
     276    testSelectorWithDuplicates: function() { with(this) { 
     277      assertEnumEqual($$('div div'), $$('div div').uniq()); 
     278      assertEnumEqual($('dupL2', 'dupL3', 'dupL4', 'dupL5'), $$('#dupContainer span span')); 
     279      $RunBenchmarks && wait(500, function() { 
     280        benchmark(function() { $$('#dupContainer span span') }, 1000); 
     281      }); 
     282    }}, 
     283 
     284    testSelectorWithFirstLastOnlyNthNthLastChild: function() { with(this) { 
     285      assertEnumEqual([$('level2_1')], $$('#level1>*:first-child')); 
     286      assertEnumEqual($('level2_1', 'level3_1', 'level_only_child'), $$('#level1 *:first-child')); 
     287      assertEnumEqual([$('level2_3')], $$('#level1>*:last-child')); 
     288      assertEnumEqual($('level3_2', 'level_only_child', 'level2_3'), $$('#level1 *:last-child')); 
     289      assertEnumEqual([$('level2_3')], $$('#level1>div:last-child')); 
     290      assertEnumEqual([$('level2_3')], $$('#level1 div:last-child')); 
     291      assertEnumEqual([], $$('#level1>div:first-child')); 
     292      assertEnumEqual([], $$('#level1>span:last-child')); 
     293      assertEnumEqual($('level2_1', 'level3_1'), $$('#level1 span:first-child')); 
     294      assertEnumEqual([], $$('#level1:first-child')); 
     295      assertEnumEqual([], $$('#level1>*:only-child')); 
     296      assertEnumEqual([$('level_only_child')], $$('#level1 *:only-child')); 
     297      assertEnumEqual([], $$('#level1:only-child')); 
     298      assertEnumEqual([$('link_2')], $$('#p *:nth-last-child(2)'), 'nth-last-child'); 
     299      assertEnumEqual([$('link_2')], $$('#p *:nth-child(3)'), 'nth-child'); 
     300      assertEnumEqual([$('link_2')], $$('#p a:nth-child(3)'), 'nth-child'); 
     301      $RunBenchmarks && wait(500, function() { 
     302        benchmark(function() { $$('#level1 *:first-child') }, 1000, ':first-child'); 
     303        benchmark(function() { $$('#level1 *:last-child') }, 1000, ':last-child'); 
     304        benchmark(function() { $$('#level1 *:only-child') }, 1000, ':only-child'); 
     305      }); 
     306    }}, 
     307     
     308    testSelectorWithFirstLastNthNthLastOfType: function() {with(this) { 
     309      assertEnumEqual([$('link_2')], $$('#p a:nth-of-type(2)'), 'nth-of-type'); 
     310      assertEnumEqual([$('link_1')], $$('#p a:nth-of-type(1)'), 'nth-of-type'); 
     311      assertEnumEqual([$('link_2')], $$('#p a:nth-last-of-type(1)'), 'nth-last-of-type'); 
     312      assertEnumEqual([$('link_1')], $$('#p a:first-of-type'), 'first-of-type'); 
     313      assertEnumEqual([$('link_2')], $$('#p a:last-of-type'), 'last-of-type'); 
     314    }}, 
     315     
     316    testSelectorWithNot: function() {with(this) { 
     317      assertEnumEqual([$('link_2')], $$('#p a:not(:first-of-type)')); 
     318      assertEnumEqual([$('link_1')], $$('#p a:not(:last-of-type)')); 
     319      assertEnumEqual([$('link_2')], $$('#p a:not(:nth-of-type(1))')); 
     320      assertEnumEqual([$('link_1')], $$('#p a:not(:nth-last-of-type(1))')); 
     321      assertEnumEqual([$('link_2')], $$('#p a:not([rel~=nofollow])')); 
     322      assertEnumEqual([$('link_2')], $$('#p a:not([rel^=external])')); 
     323      assertEnumEqual([$('link_2')], $$('#p a:not([rel$=nofollow])')); 
     324    }}, 
     325     
     326    testSelectorWithEnabledDisabledChecked: function() {with(this) { 
     327      assertEnumEqual([$('disabled_text_field')], $$('#troubleForm > *:disabled')); 
     328      assertEnumEqual($('troubleForm').getInputs().without($('disabled_text_field')), $$('#troubleForm > *:enabled')); 
     329      assertEnumEqual($('checked_box', 'checked_radio'), $$('#troubleForm *:checked')); 
     330    }}, 
     331     
     332    testSelectorWithEmpty: function() {with(this) { 
     333      assertEnumEqual($('level3_1', 'level3_2', 'level_only_child', 'level2_3'), $$('#level1 *:empty')); 
     334      assertEnumEqual([$('level_only_child')], $$('#level_only_child:empty')); 
     335    }},     
     336     
     337    testIdenticalResultsFromEquivalentSelectors: function() {with(this) { 
     338      assertEnumEqual($$('div.brothers'), $$('div[class~=brothers]')); 
     339      assertEnumEqual($$('div.brothers'), $$('div[class~=brothers].brothers')); 
     340      assertEnumEqual($$('div:not(.brothers)'), $$('div:not([class~=brothers])')); 
     341      assertEnumEqual($$('li ~ li'), $$('li:not(:first-child)')); 
     342      assertEnumEqual($$('ul > li'), $$('ul > li:nth-child(n)')); 
     343      assertEnumEqual($$('ul > li:nth-child(even)'), $$('ul > li:nth-child(2n)')); 
     344      assertEnumEqual($$('ul > li:nth-child(odd)'), $$('ul > li:nth-child(2n+1)')); 
     345      assertEnumEqual($$('ul > li:first-child'), $$('ul > li:nth-child(1)')); 
     346      assertEnumEqual($$('ul > li:last-child'), $$('ul > li:nth-last-child(1)')); 
     347      assertEnumEqual($$('#troubleForm *:enabled'), $$('#troubleForm *:not(:disabled)')); 
     348    }}, 
     349     
     350    testSelectorsThatShouldReturnNothing: function() {with(this) { 
     351      assertEnumEqual([], $$('span:empty > *')); 
     352      assertEnumEqual([], $$('div.brothers:not(.brothers)')); 
     353      assertEnumEqual([], $$('#level2_2 :only-child:not(:last-child)')); 
     354      assertEnumEqual([], $$('#level2_2 :only-child:not(:first-child)')); 
     355    }}, 
     356 
     357    testCommasFor$$: function() {with(this) { 
     358      assertEnumEqual($('list', 'p', 'link_1', 'item_1', 'item_3', 'troubleForm'), $$('#list, .first,*[xml:lang="es-us"] , #troubleForm')); 
     359      assertEnumEqual($('list', 'p', 'link_1', 'item_1', 'item_3', 'troubleForm'), $$('#list, .first,', '*[xml:lang="es-us"] , #troubleForm')); 
     360      assertEnumEqual($('commaParent', 'commaChild'), $$('form[title*="commas,"], input[value="#commaOne,#commaTwo"]')); 
     361      assertEnumEqual($('commaParent', 'commaChild'), $$('form[title*="commas,"]', 'input[value="#commaOne,#commaTwo"]')); 
     362    }} 
     363  }, 'testlog'); 
    364364// ]]> 
    365365</script>