Repository: jquery/jquery
File: test/unit/selector.js (JavaScript)

Code before:
	assert.equal( jQuery.escapeSelector( "\xA0\xA1\xA2" ), "\xA0\xA1\xA2",
		"Doesn't escape non-ASCII ISO-8859-1 characters" );
	assert.equal( jQuery.escapeSelector( "a0123456789b" ), "a0123456789b",
		"Doesn't escape embedded numbers" );
	assert.equal( jQuery.escapeSelector( "abcdefghijklmnopqrstuvwxyz" ), "abcdefghijklmnopqrstuvwxyz",
		"Doesn't escape lowercase ASCII letters" );
	assert.equal( jQuery.escapeSelector( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ), "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
		"Doesn't escape uppercase ASCII letters" );
	assert.equal( jQuery.escapeSelector( "\x20\x21\x78\x79" ), "\\ \\!xy",
		"Escapes non-word ASCII characters" );

	// Astral symbol (U+1D306 TETRAGRAM FOR CENTRE)
	assert.equal( jQuery.escapeSelector( "\uD834\uDF06" ), "\uD834\uDF06",
		"Doesn't escape astral characters" );

	// Lone surrogates
	assert.equal( jQuery.escapeSelector( "\uDF06" ), "\uDF06", "Doesn't escape lone low surrogate" );
	assert.equal( jQuery.escapeSelector( "\uD834" ), "\uD834", "Doesn't escape lone high surrogate" );
} );

QUnit.test( "custom pseudos", function( assert ) {
	assert.expect( 6 );

	jQuery.expr.filters.foundation = jQuery.expr.filters.root;
	assert.deepEqual( jQuery.find( ":foundation" ), [ document.documentElement ], "Copy element filter with new name" );
	delete jQuery.expr.filters.foundation;

	jQuery.expr.setFilters.primary = jQuery.expr.setFilters.first;
	assert.t( "Copy set filter with new name", "div#qunit-fixture :primary", [ "firstp" ] );
	delete jQuery.expr.setFilters.primary;

	jQuery.expr.filters.aristotlean = jQuery.expr.createPseudo( function() {
		return function( elem ) {
			return !!elem.id;
		};
	} );
	assert.t( "Custom element filter", "#foo :aristotlean", [ "sndp", "en", "yahoo", "sap", "anchor2", "simon" ] );
	delete jQuery.expr.filters.aristotlean;

	jQuery.expr.filters.endswith = jQuery.expr.createPseudo( function( text ) {
		return function( elem ) {
			return jQuery.text( elem ).slice( -text.length ) === text;
		};
	} );
	assert.t( "Custom element filter with argument", "a:endswith(ogle)", [ "google" ] );
	delete jQuery.expr.filters.endswith;

	jQuery.expr.setFilters.second = jQuery.expr.createPseudo( function() {
		return jQuery.expr.createPseudo( function( seed, matches ) {
			if ( seed[ 1 ] ) {
				matches[ 1 ] = seed[ 1 ];

Review comment (suggestion):
For good hygiene, I think we should wrap this in a `try` block move the cleanup into `finally` (or anything else that accomplishes the same isolation).

Code after:
	assert.equal( jQuery.escapeSelector( "\xA0\xA1\xA2" ), "\xA0\xA1\xA2",
		"Doesn't escape non-ASCII ISO-8859-1 characters" );
	assert.equal( jQuery.escapeSelector( "a0123456789b" ), "a0123456789b",
		"Doesn't escape embedded numbers" );
	assert.equal( jQuery.escapeSelector( "abcdefghijklmnopqrstuvwxyz" ), "abcdefghijklmnopqrstuvwxyz",
		"Doesn't escape lowercase ASCII letters" );
	assert.equal( jQuery.escapeSelector( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ), "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
		"Doesn't escape uppercase ASCII letters" );
	assert.equal( jQuery.escapeSelector( "\x20\x21\x78\x79" ), "\\ \\!xy",
		"Escapes non-word ASCII characters" );

	// Astral symbol (U+1D306 TETRAGRAM FOR CENTRE)
	assert.equal( jQuery.escapeSelector( "\uD834\uDF06" ), "\uD834\uDF06",
		"Doesn't escape astral characters" );

	// Lone surrogates
	assert.equal( jQuery.escapeSelector( "\uDF06" ), "\uDF06", "Doesn't escape lone low surrogate" );
	assert.equal( jQuery.escapeSelector( "\uD834" ), "\uD834", "Doesn't escape lone high surrogate" );
} );

QUnit.test( "custom pseudos", function( assert ) {
	assert.expect( 6 );

	try {
		jQuery.expr.filters.foundation = jQuery.expr.filters.root;
		assert.deepEqual( jQuery.find( ":foundation" ), [ document.documentElement ], "Copy element filter with new name" );
	} finally {
		delete jQuery.expr.filters.foundation;
	}

	try {
		jQuery.expr.setFilters.primary = jQuery.expr.setFilters.first;
		assert.t( "Copy set filter with new name", "div#qunit-fixture :primary", [ "firstp" ] );
	} finally {
		delete jQuery.expr.setFilters.primary;
	}

	try {
		jQuery.expr.filters.aristotlean = jQuery.expr.createPseudo( function() {
			return function( elem ) {
				return !!elem.id;
			};
		} );
		assert.t( "Custom element filter", "#foo :aristotlean", [ "sndp", "en", "yahoo", "sap", "anchor2", "simon" ] );
	} finally {
		delete jQuery.expr.filters.aristotlean;
	}

	try {
		jQuery.expr.filters.endswith = jQuery.expr.createPseudo( function( text ) {
			return function( elem ) {