JE

 view release on metacpan or  search on metacpan

t/15.01.03-uri-functions.t  view on Meta::CPAN

#!perl -T
do './t/jstest.pl' or die __DATA__

function is_nan(n){ // checks to see whether the number is *really* NaN
                    // & not something which converts to NaN when numified
	return n!=n
}

// ===================================================
// 15.1.3.1: decodeURI
// ===================================================

// 10 tests (boilerplate stuff for built-ins)
is(typeof decodeURI, 'function', 'typeof decodeURI');
is(Object.prototype.toString.apply(decodeURI), '[object Function]',
	'class of decodeURI')
ok(Function.prototype.isPrototypeOf(decodeURI), 'decodeURI\'s prototype')
$catched = false;
try{ new decodeURI } catch(e) { $catched = e }
ok($catched, 'new decodeURI fails')
ok(!('prototype' in decodeURI), 'decodeURI has no prototype property')
ok(decodeURI.length === 1, 'decodeURI.length')
ok(!decodeURI.propertyIsEnumerable('length'),
	'decodeURI.length is not enumerable')
ok(!delete decodeURI.length, 'decodeURI.length cannot be deleted')
is((decodeURI.length++, decodeURI.length), 1, 'decodeURI.length is read-only')
ok(decodeURI() === 'undefined', 'decodeURI() w/o args')


// 5 tests for type conversion
ok(decodeURI(undefined) === 'undefined', 'decodeURI(undefined)')
ok(decodeURI(null     ) === 'null',      'decodeURI(null)')
ok(decodeURI(true     ) === 'true',      'decodeURI(bool)')
ok(decodeURI(0        ) === '0',         'decodeURI(num)')
ok(decodeURI({})==='[object Object]',    'decodeURI({})')

// 18 tests for the algorithm itself

ok(decodeURI('blah@#!$(&@\u0100\xff\ud800') ===
	'blah@#!$(&@\u0100\xff\ud800', 'non-% chars go right through')

ok(decodeURI('%ed%a0%80') === '\ud800', 'encoded surrogates get decoded')

error = false
try{decodeURI('oenh%')}catch(e){error = e}
ok(error instanceof URIError, 'decodeURI dies with a final %')

error = false
try{decodeURI('oenh%a')}catch(e){error = e}
ok(error instanceof URIError, 'decodeURI dies with a partial %xx')

error = false
try{decodeURI('oenh%g3')}catch(e){error = e}
ok(error instanceof URIError, 'decodeURI dies with a invalid %xx')

error = false
try{decodeURI('oenh%3H')}catch(e){error = e}
ok(error instanceof URIError, 'decodeURI dies with a invalid %xx (again)')

// I mix capitalisation in this test, to make sure that what doesn’t get
// unescaped retains it capitalisation:
is(decodeURI('%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F' +
             '%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F' +
             '%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2D%2E%2f' +
             '%30%31%32%33%34%35%36%37%38%39%3a%3B%3C%3D%3E%3F' +



( run in 1.688 second using v1.01-cache-2.11-cpan-804bf51f3ce )