Testcase for jQuery Ticket 7263 #2
by jitter
HTML
<ul class="test" style="display:none">
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
<ul style="display:none">
<li><p>asd</p></li>
</ul>
<div style="display:none"><input type="text" /><input type="radio" /></div>
JavaScript
var log = function (val, expected) {
var color = val === expected ? "green" : "red";
$("body").append("<p style='color:"+color+"'>"+val+"</p>");
};
var breaker = function() {
$("body").append("<p>---------</p>");
};
log($( 'li:first' ).is( 'li' ), true);
log($( 'li:first' ).is( 'li:first' ), true);
log($( 'li:first' ).is( '.test li:last' ), false);
//strange "li:nth-child(3)" and ".test li:last" should yield the same result with this markup
log($( 'li:first' ).is( 'li:nth-child(3)' ), false);
//strange li:nth-child(3) and li:nth-child(last) also don't yield the same result here??
log($( 'li:first' ).is( 'li:nth-child(last)' ), false);
breaker();
log($( 'li:first' ).is( 'p' ), false);
log($( 'li:first' ).is( 'p:last' ), false);
breaker();
log($( 'li:first' ).is( 'ul' ), false);
log($( 'li:first' ).is( 'ul:last' ), false);
breaker();
log($( 'li:first' ).is( 'ul p' ), false);
log($( 'li:first' ).is( 'ul > p' ), false);
log($( 'li:first' ).is( 'ul:last > p' ), false);
log($( 'li:first' ).is( 'ul > p:last' ), false);
//introducing a pseudo pos selector seems to break the is functionality
//if the selector is an ancestor descendant selector
//that these tests yield true is especially concerning
log($( 'li:first' ).is( 'ul:last p' ), false);
log($( 'li:first' ).is( 'ul p:last' ), false);
breaker();
log($( 'li:first' ).is( 'li:first-child' ), true);
log($( 'li:first' ).is( 'ul li:first-child' ), true);
log($( 'li:last' ).is( 'li:last-child' ), true);
log($( 'li:last' ).is( 'ul li:last-child' ), true);
breaker();
// :even is zero based so the 2nd li shouldn't be even
log($( 'li:eq(1)' ).is( 'li:even' ), false);
breaker();
//here adding .test seems to alter the previously correct result
log($( 'li:first' ).is( 'li:eq(1)' ), false);
log($( 'li:first' ).is( '.test li:eq(1)' ), false);
breaker();
log($( 'input:first' ).is( 'input' ), true);
log($( 'input:first' ).is( 'div' ), false);
log($( 'input:first' ).is( 'div input' ), true);
log($( 'input:first'...