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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
#!perl -T
BEGIN { require './t/test.pl' }
use Test::More tests => 111;
use strict;
use utf8;
# Test 1: See if the module loads
BEGIN { use_ok('JE') };
my $j = new JE;
# Tests 2-3: Bind the ok and diag functions
isa_ok( $j->new_function( ok => \&ok ), 'JE::Object::Function' );
isa_ok( $j->new_function( diag => \&diag ), 'JE::Object::Function' );
# JS tests
defined $j->eval( <<'--end--' ) or die;
// ===================================================
// 11.4.1 delete
// ===================================================
/* Tests 4-15 */
s = String;
var x //undeletable
eval('var y,z') //deletable
ok( delete(x,y) && 'x' in this && 'y' in this, 'delete(a,b)')
ok( delete(x=3) && 'x' in this, 'delete(a=b)')
ok( delete(1?y:x) && 'y' in this, 'delete(a?b:c)')
ok( delete(x||y) && 'x' in this && 'y' in this, 'delete(a||b)')
ok( delete(x&&y) && 'x' in this && 'y' in this, 'delete(a&&b)')
ok( delete "y" && 'y' in this, 'delete "a"')
ok( delete y &&!('y' in this), 'delete a')
ok( delete( z ) &&!('z' in this), 'delete(a)')
ok(!delete x && 'x' in this, 'delete a when a is undeletable')
ok( delete w &&!('w' in this), 'delete a when a does not exist')
ok( delete this.String &&!('String' in this), 'delete a.b')
// Hey, wait a minute! I still need that! Better put it back:
String = s
ok( delete []["\ud800"], 'delete []["\\ud800"]')
// ===================================================
// 11.4.2 void
// ===================================================
/* Tests 16-17 */
ok(typeof void delete undefined == 'undefined', 'void expr')
error = 0
try { void oentuahn }
catch(me) { me instanceof ReferenceError && (error = 1) }
ok(error, '"void identifier" when var does not exist')
// ===================================================
// 11.4.3 typeof
// ===================================================
/* Tests 18-33 */
ok( typeof undefined === 'undefined', 'typeof undefined (lvalue)')
ok((x = null, typeof x === 'object'), 'typeof null (lvalue)')
ok((x = true, typeof x === 'boolean'), 'typeof boolean (lvalue)')
ok((x = 0, typeof x === 'number'), 'typeof number (lvalue)')
ok((x = '', typeof x === 'string'), 'typeof string (lvalue)')
ok((x = {}, typeof x === 'object'), 'typeof object (lvalue)')
ok( typeof eval === 'function', 'typeof function (lvalue)')
ok( typeof easun === 'undefined', 'typeof nonexistent_var')
ok( typeof '3'.toStoo === 'undefined', 'typeof nonexistent.prop')
ok( typeof void 0 === 'undefined', 'typeof undefined')
ok( typeof null === 'object', 'typeof null')
ok( typeof true === 'boolean', 'typeof boolean')
ok( typeof 3 === 'number', 'typeof number')
ok( typeof '3' === 'string', 'typeof string')
ok( typeof new new Function === 'object', 'typeof object')
ok( typeof new Function === 'function', 'typeof function')
// ===================================================
// 11.4.4 ++
// ===================================================
/* Tests 34-41 */
ok((x = void 0, isNaN(++x) && isNaN(x)), '++undefined')
ok((x = null, ++x === 1 && x === 1), '++null')
ok((x = true, ++x === 2 && x === 2), '++true')
ok((x = false, ++x === 1 && x === 1), '++false')
ok((x = 'a', isNaN(++x) && isNaN(x)), '++"a"')
ok((x = '3', ++x === 4 && x === 4), '++"3"')
ok((x = 4.2, ++x === 5.2 && x === 5.2), '++4.2')
ok((x = {}, isNaN(++x) && isNaN(x)), '++{}')
// ===================================================
// 11.4.5 --
// ===================================================
/* Tests 42-9 */
ok((x = void 0, isNaN(--x) && isNaN(x)), '--undefined')
ok((x = null, --x === -1 && x === -1), '--null')
ok((x = true, --x === 0 && x === 0), '--true')
ok((x = false, --x === -1 && x === -1), '--false')
ok((x = 'a', isNaN(--x) && isNaN(x)), '--"a"')
ok((x = '3', --x === 2 && x === 2), '--"3"')
ok((x = 4.2, --x === 3.2 && x === 3.2), '--4.2')
ok((x = {}, isNaN(--x) && isNaN(x)), '--{}')
// ===================================================
// 11.4.6 +
// ===================================================
/* Tests 50-7 */
ok(isNaN(+void 0), '+undefined')
ok( +null === 0, '+null')
ok( +true === 1, '+true')
ok( +false === 0, '+false')
ok(isNaN(+'a'), '+"a"')
ok( +'3.00' === 3, '+"3.00"')
ok( +4.2 === 4.2, '+4.2')
ok(isNaN(+{}), '+{}')
// ===================================================
// 11.4.7 -
// ===================================================
/* Tests 58-66 */
ok(isNaN(-void 0), '-undefined')
ok( -null === 0, '-null')
ok( -true === -1, '-true')
ok( -false === 0, '-false')
ok(isNaN(-'a'), '-"a"')
ok( -"-5" === 5, '-"-5"')
ok( -4.2 === -4.2, '-4.2')
ok(isNaN(-{}), '-{}')
ok( - -5 === 5, '- -5')
// ===================================================
// 11.4.8 ~
// ===================================================
/* Tests 67-101 */
ok(~ undefined === -1 , "~undefined" )
ok(~ null === -1 , "~null" )
ok(~ true === -2 , "~true" )
ok(~ false === -1 , "~false" )
ok(~'a' === -1 , "~'a'" )
ok(~'3' === -4 , "~'3'" )
ok(~ {} === -1 , "~{}" )
ok(~ NaN === -1 , "~NaN" )
ok(~ 0 === -1 , "~0" )
ok(~-0 === -1 , "~-0" )
ok(~ Infinity === -1 , "~Infinity" )
ok(~-Infinity === -1 , "~-Infinity" )
ok(~ 1 === -2 , "~1" )
ok(~ 32.5 === -33 , "~32.5" )
ok(~ 2147483648 === 2147483647, "~2147483648" )
ok(~ 3000000000 === 1294967295, "~3000000000" )
ok(~ 4000000000.23 === 294967295 , "~4000000000.23" )
ok(~ 5000000000 === -705032705 , "~5000000000" )
ok(~ 4294967296 === -1 , "~4294967296" )
ok(~ 4294967298.479 === -3 , "~4294967298.479" )
ok(~ 6442450942 === -2147483647, "~6442450942" )
ok(~ 6442450943.674 === -2147483648, "~6442450943.674" )
ok(~ 6442450944 === 2147483647, "~6442450944" )
ok(~ 6442450945 === 2147483646, "~6442450945" )
ok(~ 6442450946.74 === 2147483645, "~6442450946.74" )
ok(~-1 === 0 , "~-1" )
ok(~-32.5 === 31 , "~-32.5" )
ok(~-3000000000 === -1294967297, "~-3000000000" )
ok(~-4000000000.23 === -294967297 , "~-4000000000.23" )
ok(~-5000000000 === 705032703 , "~-5000000000" )
ok(~-4294967298.479 === 1 , "~-4294967298.479")
ok(~-6442450942 === 2147483645, "~-6442450942" )
ok(~-6442450943.674 === 2147483646, "~-6442450943.674")
ok(~-6442450945 === -2147483648, "~-6442450945" )
ok(~-6442450946.74 === -2147483647, "~-6442450946.74" )
// ===================================================
// 11.4.9 !
// ===================================================
/* Tests 102-11 */
ok(!undefined === true , "!undefined")
ok(!null === true , "!null" )
ok(!true === false, "!true" )
ok(!false === true , "!false" )
ok(!'' === true , "!''" )
ok(!"false" === false, "!\"false\"")
ok(!0 === true , '!0' )
ok(!1 === false, '!1' )
ok(!NaN === true , "!NaN" )
ok(!{} === false, "!{}" )
--end--
|