JE
view release on metacpan or search on metacpan
t/15.05-string-objects.t view on Meta::CPAN
// 7 tests
// ===================================================
ok(String() === '', 'String()')
ok(String(void 0) === 'undefined', 'String(undefined)')
ok(String(876) === '876', 'String(number)')
ok(String(true) === 'true', 'String(boolean)')
ok(String('ffo') === 'ffo', 'String(str)')
ok(String(null) === 'null', 'String(null)')
ok(String({}) === '[object Object]', 'String(object)')
// ===================================================
// 15.5.2: new String
// 9 tests
// ===================================================
ok(new String().constructor === String, 'prototype of new String')
is(Object.prototype.toString.apply(new String()), '[object String]',
'class of new String')
ok(new String().valueOf() === '', 'value of new String')
ok(new String('foo').valueOf() === 'foo', 'value of new String(foo)')
ok(new String(void 0).valueOf() === 'undefined', 'new String(undefined)')
ok(new String(876).valueOf() === '876', 'new String(number)')
ok(new String(true).valueOf() === 'true', 'new String(boolean)')
ok(new String(null).valueOf() === 'null', 'new String(null)')
ok(new String({}).valueOf() === '[object Object]', 'new String(object)')
// ===================================================
// 15.5.3 String
// ===================================================
// 10 tests (boilerplate stuff for constructors)
is(typeof String, 'function', 'typeof String');
is(Object.prototype.toString.apply(String), '[object Function]',
'class of String')
ok(String.constructor === Function, 'String\'s prototype')
ok(String.length === 1, 'String.length')
ok(!String.propertyIsEnumerable('length'),
'String.length is not enumerable')
ok(!delete String.length, 'String.length cannot be deleted')
is((String.length++, String.length), 1, 'String.length is read-only')
ok(!String.propertyIsEnumerable('prototype'),
'String.prototype is not enumerable')
ok(!delete String.prototype, 'String.prototype cannot be deleted')
cmp_ok((String.prototype = 7, String.prototype), '!=', 7,
'String.prototype is read-only')
// ===================================================
// 15.5.3.2: fromCharCode
// ===================================================
// 10 tests
method_boilerplate_tests(String,'fromCharCode',1)
// 1 tests
is(String.fromCharCode(
undefined,null,true,false,'a','3',{},NaN,+0,-0,Infinity,-Infinity,
1,32.5,2147483648,3000000000,4000000000.23,5000000000,4294967296,
4294967298.479,6442450942,6442450943.674,6442450944,6442450945,
6442450946.74,-1,-32.5,-3000000000,-4000000000.23,-5000000000,
-4294967298.479,-6442450942,-6442450943.674,-6442450944,
-6442450945,-6442450946.74
), "\x00\x00\x01\x00\x00\x03\x00\x00\x00\x00\x00\x00\x01\x20\x00å¸â \uf200"+
"\x00\x02\ufffe\uffff\x00\x01\x02\uffffï¿ ê\ud800\u0e00\ufffe\x02\x01" +
"\x00\uffff\ufffe", 'fromCharCode')
// ===================================================
// 15.5.4: String prototype
// ===================================================
// 3 tests
is(Object.prototype.toString.apply(String.prototype),
'[object String]',
'class of String.prototype')
is(String.prototype, '',
'String.prototype as string')
ok(peval('shift->prototype',String.prototype) === Object.prototype,
'String.prototype\'s prototype')
// ===================================================
// 15.5.4.1 String.prototype.constructor
// ===================================================
// 2 tests
ok(String.prototype.hasOwnProperty('constructor'),
'String.prototype has its own constructor property')
ok(String.prototype.constructor === String,
'value of String.prototype.constructor')
// ===================================================
// 15.5.4.2: toString
// ===================================================
// 10 tests
method_boilerplate_tests(String.prototype,'toString',0)
// 3 tests for misc this values
0,function(){
var f = String.prototype.toString;
var testname='toString with number for this';
try{f.call(8); fail(testname) }
catch(e){ok(e instanceof TypeError,testname)}
var testname='toString with object for this';
try{f.call({}); fail(testname) }
catch(e){ok(e instanceof TypeError,testname)}
var testname='toString with boolean for this';
try{f.call(true); fail(testname) }
catch(e){ok(e instanceof TypeError,testname)}
}()
// 1 test more
ok(new String("foo").toString() === 'foo', 'toString')
// ===================================================
( run in 1.030 second using v1.01-cache-2.11-cpan-39bf76dae61 )