File: 15.06-boolean-objects.t

package info (click to toggle)
libje-perl 0.066-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,008 kB
  • sloc: perl: 31,288; makefile: 2
file content (132 lines) | stat: -rw-r--r-- 4,667 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!perl -T
do './t/jstest.pl' or die __DATA__

// ===================================================
// 15.6.1: Boolean as a function
// 7 tests
// ===================================================

ok(Boolean() === false, 'Boolean()')
ok(Boolean(void 0) === false, 'Boolean(undefined)')
ok(Boolean(876) === true, 'Boolean(number)')
ok(Boolean(true) === true, 'Boolean(boolean)')
ok(Boolean('ffo') === true, 'Boolean(str)')
ok(Boolean(null) === false, 'Boolean(null)')
ok(Boolean({}) === true, 'Boolean(object)')


// ===================================================
// 15.6.2: new Boolean
// 10 tests
// ===================================================

ok(new Boolean().constructor === Boolean, 'prototype of new Boolean')
is(Object.prototype.toString.apply(new Boolean()), '[object Boolean]',
	'class of new Boolean')
ok(new Boolean().valueOf() === false, 'value of new Boolean')
ok(new Boolean(true).valueOf() === true, 'value of new Boolean(true)')
ok(new Boolean(false).valueOf() === false, 'value of new Boolean(false)')

ok(new Boolean(void 0).valueOf() === false, 'new Boolean(undefined)')
ok(new Boolean(876).valueOf() === true, 'new Boolean(number)')
ok(new Boolean("tru").valueOf() === true, 'new Boolean(string)')
ok(new Boolean(null).valueOf() === false, 'new Boolean(null)')
ok(new Boolean({}).valueOf() === true, 'new Boolean(object)')


// ===================================================
// 15.6.3 Boolean
// ===================================================

// 10 tests (boilerplate stuff for constructors)
is(typeof Boolean, 'function', 'typeof Boolean');
is(Object.prototype.toString.apply(Boolean), '[object Function]',
	'class of Boolean')
ok(Boolean.constructor === Function, 'Boolean\'s prototype')
ok(Boolean.length === 1, 'Boolean.length')
ok(!Boolean.propertyIsEnumerable('length'),
	'Boolean.length is not enumerable')
ok(!delete Boolean.length, 'Boolean.length cannot be deleted')
is((Boolean.length++, Boolean.length), 1, 'Boolean.length is read-only')
ok(!Boolean.propertyIsEnumerable('prototype'),
	'Boolean.prototype is not enumerable')
ok(!delete Boolean.prototype, 'Boolean.prototype cannot be deleted')
cmp_ok((Boolean.prototype = 7, Boolean.prototype), '!=', 7,
	'Boolean.prototype is read-only')


// ===================================================
// 15.6.4: Boolean prototype
// ===================================================

// 3 tests
is(Object.prototype.toString.apply(Boolean.prototype),
	'[object Boolean]',
	'class of Boolean.prototype')
is(Boolean.prototype, false,
	'value of Boolean.prototype')
ok(peval('shift->prototype',Boolean.prototype) === Object.prototype,
	'Boolean.prototype\'s prototype')


// ===================================================
// 15.6.4.1 Boolean.prototype.constructor
// ===================================================

// 2 tests
ok(Boolean.prototype.hasOwnProperty('constructor'),
	'Boolean.prototype has its own constructor property')
ok(Boolean.prototype.constructor === Boolean,
	'value of Boolean.prototype.constructor')


// ===================================================
// 15.6.4.2: toString
// ===================================================

// 10 tests
method_boilerplate_tests(Boolean.prototype,'toString',0)

// 3 tests for misc this values
0,function(){
	var f = Boolean.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 string for this';
	try{f.call('true'); fail(testname) }
	catch(e){ok(e instanceof TypeError,testname)}
}()

// 2 tests more
ok(new Boolean("foo").toString() === 'true', 'toString (true)')
ok(new Boolean("").toString() === 'false', 'toString (floss)')


// ===================================================
// 15.6.4.3: valueOf
// ===================================================

// 10 tests
method_boilerplate_tests(Boolean.prototype,'valueOf',0)

// 3 tests for misc this values
0,function(){
	var f = Boolean.prototype.valueOf;
	var testname='valueOf with number for this';
	try{f.call(8); fail(testname) }
	catch(e){ok(e instanceof TypeError,testname)}
	var testname='valueOf with object for this';
	try{f.call({}); fail(testname) }
	catch(e){ok(e instanceof TypeError,testname)}
	var testname='valueOf with string for this';
	try{f.call('true'); fail(testname) }
	catch(e){ok(e instanceof TypeError,testname)}
}()

// 2 tests more
ok(new Boolean("foo").valueOf() === true, 'valueOf (true)')
ok(new Boolean("").valueOf() === false, 'valueOf (false)')