mirror of https://github.com/tc39/test262.git
213 lines
33 KiB
JSON
213 lines
33 KiB
JSON
{
|
|
"testCollection": {
|
|
"name": "11.6.1_The_Addition_operator",
|
|
"numTests": 34,
|
|
"tests": [
|
|
{
|
|
"section": "11.6.1, 7.2, 7.3",
|
|
"description": "Checking by using eval",
|
|
"test": "//CHECK#1\nif (eval(\"1\\u0009+\\u00091\") !== 2) {\n $ERROR('#1: 1\\\\u0009+\\\\u00091 === 2');\n}\n\n//CHECK#2\nif (eval(\"1\\u000B+\\u000B1\") !== 2) {\n $ERROR('#2: 1\\\\u000B+\\\\u000B1 === 2'); \n}\n\n//CHECK#3\nif (eval(\"1\\u000C+\\u000C1\") !== 2) {\n $ERROR('#3: 1\\\\u000C+\\\\u000C1 === 2');\n}\n\n//CHECK#4\nif (eval(\"1\\u0020+\\u00201\") !== 2) {\n $ERROR('#4: 1\\\\u0020+\\\\u00201 === 2');\n}\n\n//CHECK#5\nif (eval(\"1\\u00A0+\\u00A01\") !== 2) {\n $ERROR('#5: 1\\\\u00A0+\\\\u00A01 === 2');\n}\n\n//CHECK#6\nif (eval(\"1\\u000A+\\u000A1\") !== 2) {\n $ERROR('#6: 1\\\\u000A+\\\\u000A1 === 2'); \n}\n\n//CHECK#7\nif (eval(\"1\\u000D+\\u000D1\") !== 2) {\n $ERROR('#7: 1\\\\u000D+\\\\u000D1 === 2');\n}\n\n//CHECK#8\nif (eval(\"1\\u2028+\\u20281\") !== 2) {\n $ERROR('#8: 1\\\\u2028+\\\\u20281 === 2');\n}\n\n//CHECK#9\nif (eval(\"1\\u2029+\\u20291\") !== 2) {\n $ERROR('#9: 1\\\\u2029+\\\\u20291 === 2');\n}\n\n//CHECK#10\nif (eval(\"1\\u0009\\u000B\\u000C\\u0020\\u00A0\\u000A\\u000D\\u2028\\u2029+\\u0009\\u000B\\u000C\\u0020\\u00A0\\u000A\\u000D\\u2028\\u20291\") !== 2) {\n $ERROR('#10: 1\\\\u0009\\\\u000B\\\\u000C\\\\u0020\\\\u00A0\\\\u000A\\\\u000D\\\\u2028\\\\u2029+\\\\u0009\\\\u000B\\\\u000C\\\\u0020\\\\u00A0\\\\u000A\\\\u000D\\\\u2028\\\\u20291 === 2');\n}\n",
|
|
"id": "S11.6.1_A1"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Either Type is not Reference or GetBase is not null",
|
|
"test": "//CHECK#1\nif (1 + 1 !== 2) {\n $ERROR('#1: 1 + 1 === 2. Actual: ' + (1 + 1));\n}\n\n//CHECK#2\nvar x = 1;\nif (x + 1 !== 2) {\n $ERROR('#2: var x = 1; x + 1 === 2. Actual: ' + (x + 1));\n}\n\n//CHECK#3\nvar y = 1;\nif (1 + y !== 2) {\n $ERROR('#3: var y = 1; 1 + y === 2. Actual: ' + (1 + y));\n}\n\n//CHECK#4\nvar x = 1;\nvar y = 1;\nif (x + y !== 2) {\n $ERROR('#4: var x = 1; var y = 1; x + y === 2. Actual: ' + (x + y));\n}\n\n//CHECK#5\nvar objectx = new Object();\nvar objecty = new Object();\nobjectx.prop = 1;\nobjecty.prop = 1;\nif (objectx.prop + objecty.prop !== 2) {\n $ERROR('#5: var objectx = new Object(); var objecty = new Object(); objectx.prop = 1; objecty.prop = 1; objectx.prop + objecty.prop === 2. Actual: ' + (objectx.prop + objecty.prop));\n}\n",
|
|
"id": "S11.6.1_A2.1_T1"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "If GetBase(x) is null, throw ReferenceError",
|
|
"test": "//CHECK#1\ntry {\n x + 1;\n $ERROR('#1.1: x + 1 throw ReferenceError. Actual: ' + (x + 1)); \n}\ncatch (e) {\n if ((e instanceof ReferenceError) !== true) {\n $ERROR('#1.2: x + 1 throw ReferenceError. Actual: ' + (e)); \n }\n}\n\n",
|
|
"id": "S11.6.1_A2.1_T2"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "If GetBase(y) is null, throw ReferenceError",
|
|
"test": "//CHECK#1\ntry {\n 1 + y;\n $ERROR('#1.1: 1 + y throw ReferenceError. Actual: ' + (1 + y)); \n}\ncatch (e) {\n if ((e instanceof ReferenceError) !== true) {\n $ERROR('#1.2: 1 + y throw ReferenceError. Actual: ' + (e)); \n }\n}\n\n",
|
|
"id": "S11.6.1_A2.1_T3"
|
|
},
|
|
{
|
|
"section": "11.6.1, 8.6.2.6",
|
|
"description": "If Type(value) is Object, evaluate ToPrimitive(value, Number)",
|
|
"test": "//CHECK#1\nif ({valueOf: function() {return 1}} + 1 !== 2) {\n $ERROR('#1: {valueOf: function() {return 1}} + 1 === 2. Actual: ' + ({valueOf: function() {return 1}} + 1));\n}\n\n//CHECK#2\nif ({valueOf: function() {return 1}, toString: function() {return 0}} + 1 !== 2) {\n $ERROR('#2: {valueOf: function() {return 1}, toString: function() {return 0}} + 1 === 2. Actual: ' + ({valueOf: function() {return 1}, toString: function() {return 0}} + 1));\n}\n\n//CHECK#3\nif ({valueOf: function() {return 1}, toString: function() {return {}}} + 1 !== 2) {\n $ERROR('#3: {valueOf: function() {return 1}, toString: function() {return {}}} + 1 === 2. Actual: ' + ({valueOf: function() {return 1}, toString: function() {return {}}} + 1));\n}\n\n//CHECK#4\ntry {\n if ({valueOf: function() {return 1}, toString: function() {throw \"error\"}} + 1 !== 2) {\n $ERROR('#4.1: {valueOf: function() {return 1}, toString: function() {throw \"error\"}} + 1 === 2. Actual: ' + ({valueOf: function() {return 1}, toString: function() {throw \"error\"}} + 1));\n }\n}\ncatch (e) {\n if (e === \"error\") {\n $ERROR('#4.2: {valueOf: function() {return 1}, toString: function() {throw \"error\"}} + 1 not throw \"error\"');\n } else {\n $ERROR('#4.3: {valueOf: function() {return 1}, toString: function() {throw \"error\"}} + 1 not throw Error. Actual: ' + (e));\n }\n}\n\n//CHECK#5\nif (1 + {toString: function() {return 1}} !== 2) {\n $ERROR('#5: 1 + {toString: function() {return 1}} === 2. Actual: ' + (1 + {toString: function() {return 1}}));\n}\n\n//CHECK#6\nif (1 + {valueOf: function() {return {}}, toString: function() {return 1}} !== 2) {\n $ERROR('#6: 1 + {valueOf: function() {return {}}, toString: function() {return 1}} === 2. Actual: ' + (1 + {valueOf: function() {return {}}, toString: function() {return 1}}));\n}\n\n//CHECK#7\ntry {\n 1 + {valueOf: function() {throw \"error\"}, toString: function() {return 1}};\n $ERROR('#7.1: 1 + {valueOf: function() {throw \"error\"}, toString: function() {return 1}} throw \"error\". Actual: ' + (1 + {valueOf: function() {throw \"error\"}, toString: function() {return 1}}));\n} \ncatch (e) {\n if (e !== \"error\") {\n $ERROR('#7.2: 1 + {valueOf: function() {throw \"error\"}, toString: function() {return 1}} throw \"error\". Actual: ' + (e));\n } \n}\n\n//CHECK#8\ntry {\n 1 + {valueOf: function() {return {}}, toString: function() {return {}}};\n $ERROR('#8.1: 1 + {valueOf: function() {return {}}, toString: function() {return {}}} throw TypeError. Actual: ' + (1 + {valueOf: function() {return {}}, toString: function() {return {}}}));\n} \ncatch (e) {\n if ((e instanceof TypeError) !== true) {\n $ERROR('#8.2: 1 + {valueOf: function() {return {}}, toString: function() {return {}}} throw TypeError. Actual: ' + (e));\n } \n}\n",
|
|
"id": "S11.6.1_A2.2_T1"
|
|
},
|
|
{
|
|
"section": "11.6.1, 8.6.2.6",
|
|
"description": "If Type(value) is Date object, evaluate ToPrimitive(value, String)",
|
|
"test": "//CHECK#1\nvar date = new Date();\nif (date + date !== date.toString() + date.toString()) {\n $ERROR('#1: var date = new Date(); date + date === date.toString() + date.toString(). Actual: ' + (date + date)); \n}\n\n//CHECK#2\nvar date = new Date();\nif (date + 0 !== date.toString() + \"0\") {\n $ERROR('#2: var date = new Date(); date + 0 === date.toString() + \"0\". Actual: ' + (date + 0)); \n}\n\n//CHECK#3\nvar date = new Date();\nif (date + true !== date.toString() + \"true\") {\n $ERROR('#3: var date = new Date(); date + true === date.toString() + \"true\". Actual: ' + (date + true)); \n}\n\n//CHECK#4\nvar date = new Date();\nif (date + new Object() !== date.toString() + \"[object Object]\") {\n $ERROR('#4: var date = new Date(); date + new Object() === date.toString() + \"[object Object]\". Actual: ' + (date + new Object())); \n}\n\n",
|
|
"id": "S11.6.1_A2.2_T2"
|
|
},
|
|
{
|
|
"section": "11.6.1, 8.6.2.6",
|
|
"description": "If Type(value) is Function, evaluate ToPrimitive(value, Number)",
|
|
"test": "//CHECK#1\nfunction f1(){\n return 0;\n}\nif (f1 + 1 !== f1.toString() + 1) {\n $ERROR('#1: function f1() {return 0;}; f1 + 1 === f1.toString() + 1');\n}\n\n//CHECK#2\nfunction f2(){\n return 0;\n}\nf2.valueOf = function() {return 1;};\nif (1 + f2 !== 1 + 1) {\n $ERROR('#2: f1unction f2() {return 0;} f2.valueOf = function() {return 1;}; 1 + f2 === 1 + 1. Actual: ' + (1 + f2));\n}\n\n//CHECK#3\nfunction f3(){\n return 0;\n}\nf3.toString = function() {return 1;};\nif (1 + f3 !== 1 + 1) {\n $ERROR('#3: f1unction f3() {return 0;} f3.toString() = function() {return 1;}; 1 + f3 === 1 + 1. Actual: ' + (1 + f3));\n}\n\n//CHECK#4\nfunction f4(){\n return 0;\n}\nf4.valueOf = function() {return -1;};\nf4.toString = function() {return 1;};\nif (f4 + 1 !== 1 - 1) {\n $ERROR('#4: f1unction f4() {return 0;}; f2.valueOf = function() {return -1;}; f4.toString() = function() {return 1;}; f4 + 1 === 1 - 1. Actual: ' + (f4 + 1));\n}\n",
|
|
"id": "S11.6.1_A2.2_T3"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Checking with \"throw\"",
|
|
"test": "//CHECK#1\nvar x = { valueOf: function () { throw \"x\"; } };\nvar y = { valueOf: function () { throw \"y\"; } };\ntry {\n x + y;\n $ERROR('#1.1: var x = { valueOf: function () { throw \"x\"; } }; var y = { valueOf: function () { throw \"y\"; } }; x + y throw \"x\". Actual: ' + (x + y));\n} catch (e) {\n if (e === \"y\") {\n $ERROR('#1.2: ToNumber(first expression) is called first, and then ToNumber(second expression)');\n } else {\n if (e !== \"x\") {\n $ERROR('#1.3: var x = { valueOf: function () { throw \"x\"; } }; var y = { valueOf: function () { throw \"y\"; } }; x + y throw \"x\". Actual: ' + (e));\n }\n }\n}\n",
|
|
"id": "S11.6.1_A2.3_T1"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Checking with \"=\"",
|
|
"test": "//CHECK#1\nvar x = 0; \nif ((x = 1) + x !== 2) {\n $ERROR('#1: var x = 0; (x = 1) + x === 2. Actual: ' + ((x = 1) + x));\n}\n\n//CHECK#2\nvar x = 0; \nif (x + (x = 1) !== 1) {\n $ERROR('#2: var x = 0; x + (x = 1) === 1. Actual: ' + (x + (x = 1)));\n}\n\n",
|
|
"id": "S11.6.1_A2.4_T1"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Checking with \"throw\"",
|
|
"test": "//CHECK#1\nvar x = function () { throw \"x\"; };\nvar y = function () { throw \"y\"; };\ntry {\n x() + y();\n $ERROR('#1.1: var x = function () { throw \"x\"; }; var y = function () { throw \"y\"; }; x() + y() throw \"x\". Actual: ' + (x() + y()));\n} catch (e) {\n if (e === \"y\") {\n $ERROR('#1.2: First expression is evaluated first, and then second expression');\n } else {\n if (e !== \"x\") {\n $ERROR('#1.3: var x = function () { throw \"x\"; }; var y = function () { throw \"y\"; }; x() + y() throw \"x\". Actual: ' + (e));\n }\n }\n}\n",
|
|
"id": "S11.6.1_A2.4_T2"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Checking with undeclarated variables",
|
|
"test": "//CHECK#1\ntry {\n x + (x = 1);\n $ERROR('#1.1: x + (x = 1) throw ReferenceError. Actual: ' + (x + (x = 1))); \n}\ncatch (e) {\n if ((e instanceof ReferenceError) !== true) {\n $ERROR('#1.2: x + (x = 1) throw ReferenceError. Actual: ' + (e)); \n }\n}\n\n//CHECK#2\nif ((y = 1) + y !== 2) {\n $ERROR('#2: (y = 1) + y === 2. Actual: ' + ((y = 1) + y));\n}\n\n",
|
|
"id": "S11.6.1_A2.4_T3"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) and Type(Primitive(y)) vary between primitive boolean and Boolean object",
|
|
"test": "//CHECK#1\nif (true + true !== 2) {\n $ERROR('#1: true + true === 2. Actual: ' + (true + true));\n}\n\n//CHECK#2\nif (new Boolean(true) + true !== 2) {\n $ERROR('#2: new Boolean(true) + true === 2. Actual: ' + (new Boolean(true) + true));\n}\n\n//CHECK#3\nif (true + new Boolean(true) !== 2) {\n $ERROR('#3: true + new Boolean(true) === 2. Actual: ' + (true + new Boolean(true)));\n}\n\n//CHECK#4\nif (new Boolean(true) + new Boolean(true) !== 2) {\n $ERROR('#4: new Boolean(true) + new Boolean(true) === 2. Actual: ' + (new Boolean(true) + new Boolean(true)));\n}\n",
|
|
"id": "S11.6.1_A3.1_T1.1"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) and Type(Primitive(y)) vary between primitive number and Number object",
|
|
"test": "//CHECK#1\nif (1 + 1 !== 2) {\n $ERROR('#1: 1 + 1 === 2. Actual: ' + (1 + 1));\n}\n\n//CHECK#2\nif (new Number(1) + 1 !== 2) {\n $ERROR('#2: new Number(1) + 1 === 2. Actual: ' + (new Number(1) + 1));\n}\n\n//CHECK#3\nif (1 + new Number(1) !== 2) {\n $ERROR('#3: 1 + new Number(1) === 2. Actual: ' + (1 + new Number(1)));\n}\n\n//CHECK#4\nif (new Number(1) + new Number(1) !== 2) {\n $ERROR('#4: new Number(1) + new Number(1) === 2. Actual: ' + (new Number(1) + new Number(1)));\n}\n\n",
|
|
"id": "S11.6.1_A3.1_T1.2"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) and Type(Primitive(y)) vary between Null and Undefined",
|
|
"test": "//CHECK#1\nif (isNaN(null + undefined) !== true) {\n $ERROR('#1: null + undefined === Not-a-Number. Actual: ' + (null + undefined));\n}\n\n//CHECK#2\nif (isNaN(undefined + null) !== true) {\n $ERROR('#2: undefined + null === Not-a-Number. Actual: ' + (undefined + null));\n}\n\n//CHECK#3\nif (isNaN(undefined + undefined) !== true) {\n $ERROR('#3: undefined + undefined === Not-a-Number. Actual: ' + (undefined + undefined));\n}\n\n//CHECK#4\nif (null + null !== 0) {\n $ERROR('#4: null + null === 0. Actual: ' + (null + null));\n}\n",
|
|
"id": "S11.6.1_A3.1_T1.3"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) is different from Type(Primitive(y)) and both types vary between Number (primitive or object) or Boolean (primitive and object)",
|
|
"test": "//CHECK#1\nif (true + 1 !== 2) {\n $ERROR('#1: true + 1 === 2. Actual: ' + (true + 1));\n}\n\n//CHECK#2\nif (1 + true !== 2) {\n $ERROR('#2: 1 + true === 2. Actual: ' + (1 + true));\n}\n\n//CHECK#3\nif (new Boolean(true) + 1 !== 2) {\n $ERROR('#3: new Boolean(true) + 1 === 2. Actual: ' + (new Boolean(true) + 1));\n}\n\n//CHECK#4\nif (1 + new Boolean(true) !== 2) {\n $ERROR('#4: 1 + new Boolean(true) === 2. Actual: ' + (1 + new Boolean(true)));\n}\n\n//CHECK#5\nif (true + new Number(1) !== 2) {\n $ERROR('#5: true + new Number(1) === 2. Actual: ' + (true + new Number(1)));\n}\n\n//CHECK#6\nif (new Number(1) + true !== 2) {\n $ERROR('#6: new Number(1) + true === 2. Actual: ' + (new Number(1) + true));\n}\n\n//CHECK#7\nif (new Boolean(true) + new Number(1) !== 2) {\n $ERROR('#7: new Boolean(true) + new Number(1) === 2. Actual: ' + (new Boolean(true) + new Number(1)));\n}\n\n//CHECK#8\nif (new Number(1) + new Boolean(true) !== 2) {\n $ERROR('#8: new Number(1) + new Boolean(true) === 2. Actual: ' + (new Number(1) + new Boolean(true)));\n}\n",
|
|
"id": "S11.6.1_A3.1_T2.1"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) is different from Type(Primitive(y)) and both types vary between Number (primitive or object) and Null",
|
|
"test": "//CHECK#1\nif (1 + null !== 1) {\n $ERROR('#1: 1 + null === 1. Actual: ' + (1 + null));\n}\n\n//CHECK#2\nif (null + 1 !== 1) {\n $ERROR('#2: null + 1 === 1. Actual: ' + (null + 1));\n}\n\n//CHECK#3\nif (new Number(1) + null !== 1) {\n $ERROR('#3: new Number(1) + null === 1. Actual: ' + (new Number(1) + null));\n}\n\n//CHECK#4\nif (null + new Number(1) !== 1) {\n $ERROR('#4: null + new Number(1) === 1. Actual: ' + (null + new Number(1)));\n}\n",
|
|
"id": "S11.6.1_A3.1_T2.2"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) is different from Type(Primitive(y)) and both types vary between Number (primitive or object) and Undefined",
|
|
"test": "//CHECK#1\nif (isNaN(1 + undefined) !== true) {\n $ERROR('#1: 1 + undefined === Not-a-Number. Actual: ' + (1 + undefined));\n}\n\n//CHECK#2\nif (isNaN(undefined + 1) !== true) {\n $ERROR('#2: undefined + 1 === Not-a-Number. Actual: ' + (undefined + 1));\n}\n\n//CHECK#3\nif (isNaN(new Number(1) + undefined) !== true) {\n $ERROR('#3: new Number(1) + undefined === Not-a-Number. Actual: ' + (new Number(1) + undefined));\n}\n\n//CHECK#4\nif (isNaN(undefined + new Number(1)) !== true) {\n $ERROR('#4: undefined + new Number(1) === Not-a-Number. Actual: ' + (undefined + new Number(1)));\n}\n",
|
|
"id": "S11.6.1_A3.1_T2.3"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) is different from Type(Primitive(y)) and both types vary between Boolean (primitive or object) and Undefined",
|
|
"test": "//CHECK#1\nif (isNaN(true + undefined) !== true) {\n $ERROR('#1: true + undefined === Not-a-Number. Actual: ' + (true + undefined));\n}\n\n//CHECK#2\nif (isNaN(undefined + true) !== true) {\n $ERROR('#2: undefined + true === Not-a-Number. Actual: ' + (undefined + true));\n}\n\n//CHECK#3\nif (isNaN(new Boolean(true) + undefined) !== true) {\n $ERROR('#3: new Boolean(true) + undefined === Not-a-Number. Actual: ' + (new Boolean(true) + undefined));\n}\n\n//CHECK#4\nif (isNaN(undefined + new Boolean(true)) !== true) {\n $ERROR('#4: undefined + new Boolean(true) === Not-a-Number. Actual: ' + (undefined + new Boolean(true)));\n}\n",
|
|
"id": "S11.6.1_A3.1_T2.4"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) is different from Type(Primitive(y)) and both types vary between Boolean (primitive or object) and Null",
|
|
"test": "//CHECK#1\nif (true + null !== 1) {\n $ERROR('#1: true + null === 1. Actual: ' + (true + null));\n}\n\n//CHECK#2\nif (null + true !== 1) {\n $ERROR('#2: null + true === 1. Actual: ' + (null + true));\n}\n\n//CHECK#3\nif (new Boolean(true) + null !== 1) {\n $ERROR('#3: new Boolean(true) + null === 1. Actual: ' + (new Boolean(true) + null));\n}\n\n//CHECK#4\nif (null + new Boolean(true) !== 1) {\n $ERROR('#4: null + new Boolean(true) === 1. Actual: ' + (null + new Boolean(true)));\n}\n",
|
|
"id": "S11.6.1_A3.1_T2.5"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) and Type(Primitive(y)) vary between primitive string and String object",
|
|
"test": "//CHECK#1\nif (\"1\" + \"1\" !== \"11\") {\n $ERROR('#1: \"1\" + \"1\" === \"11\". Actual: ' + (\"1\" + \"1\"));\n}\n\n//CHECK#2\nif (new String(\"1\") + \"1\" !== \"11\") {\n $ERROR('#2: new String(\"1\") + \"1\" === \"11\". Actual: ' + (new String(\"1\") + \"1\"));\n}\n\n//CHECK#3\nif (\"1\" + new String(\"1\") !== \"11\") {\n $ERROR('#3: \"1\" + new String(\"1\") === \"11\". Actual: ' + (\"1\" + new String(\"1\")));\n}\n\n//CHECK#4\nif (new String(\"1\") + new String(\"1\") !== \"11\") {\n $ERROR('#4: new String(\"1\") + new String(\"1\") === \"11\". Actual: ' + (new String(\"1\") + new String(\"1\")));\n}\n\n//CHECK#5\nif (\"x\" + \"1\" !==\"x1\") {\n $ERROR('#5: \"x\" + \"1\" === \"x1\". Actual: ' + (\"x\" + \"1\"));\n}\n\n//CHECK#6\nif (\"1\" + \"x\" !== \"1x\") {\n $ERROR('#6: \"1\" + \"x\" === \"1x\". Actual: ' + (\"1\" + \"x\"));\n}\n",
|
|
"id": "S11.6.1_A3.2_T1.1"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) and Type(Primitive(y)) vary between Object object and Function object",
|
|
"test": "//CHECK#1\nif (({} + function(){return 1}) !== ({}.toString() + function(){return 1}.toString())) {\n $ERROR('#1: ({} + function(){return 1}) === ({}.toString() + function(){return 1}.toString()). Actual: ' + (({} + function(){return 1})));\n}\n\n//CHECK#2\nif ((function(){return 1} + {}) !== (function(){return 1}.toString() + {}.toString())) {\n $ERROR('#2: (function(){return 1} + {}) === (function(){return 1}.toString() + {}.toString()). Actual: ' + ((function(){return 1} + {})));\n}\n\n//CHECK#3\nif ((function(){return 1} + function(){return 1}) !== (function(){return 1}.toString() + function(){return 1}.toString())) {\n $ERROR('#3: (function(){return 1} + function(){return 1}) === (function(){return 1}.toString() + function(){return 1}.toString()). Actual: ' + ((function(){return 1} + function(){return 1})));\n}\n\n//CHECK#4\nif (({} + {}) !== ({}.toString() + {}.toString())) {\n $ERROR('#4: ({} + {}) === ({}.toString() + {}.toString()). Actual: ' + (({} + {})));\n}\n\n\n",
|
|
"id": "S11.6.1_A3.2_T1.2"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) is different from Type(Primitive(y)) and both types vary between Number (primitive or object) and String (primitive and object)",
|
|
"test": "//CHECK#1\nif (\"1\" + 1 !== \"11\") {\n $ERROR('#1: \"1\" + 1 === \"11\". Actual: ' + (\"1\" + 1));\n}\n\n//CHECK#2\nif (1 + \"1\" !== \"11\") {\n $ERROR('#2: 1 + \"1\" === \"11\". Actual: ' + (1 + \"1\"));\n}\n\n//CHECK#3\nif (new String(\"1\") + 1 !== \"11\") {\n $ERROR('#3: new String(\"1\") + 1 === \"11\". Actual: ' + (new String(\"1\") + 1));\n}\n\n//CHECK#4\nif (1 + new String(\"1\") !== \"11\") {\n $ERROR('#4: 1 + new String(\"1\") === \"11\". Actual: ' + (1 + new String(\"1\")));\n}\n\n//CHECK#5\nif (\"1\" + new Number(1) !== \"11\") {\n $ERROR('#5: \"1\" + new Number(1) === \"11\". Actual: ' + (\"1\" + new Number(1)));\n}\n\n//CHECK#6\nif (new Number(1) + \"1\" !== \"11\") {\n $ERROR('#6: new Number(1) + \"1\" === \"11\". Actual: ' + (new Number(1) + \"1\"));\n}\n\n//CHECK#7\nif (new String(\"1\") + new Number(1) !== \"11\") {\n $ERROR('#7: new String(\"1\") + new Number(1) === \"11\". Actual: ' + (new String(\"1\") + new Number(1)));\n}\n\n//CHECK#8\nif (new Number(1) + new String(\"1\") !== \"11\") {\n $ERROR('#8: new Number(1) + new String(\"1\") === \"11\". Actual: ' + (new Number(1) + new String(\"1\")));\n}\n\n//CHECK#9\nif (\"x\" + 1 !==\"x1\") {\n $ERROR('#9: \"x\" + 1 === \"x1\". Actual: ' + (\"x\" + 1));\n}\n\n//CHECK#10\nif (1 + \"x\" !== \"1x\") {\n $ERROR('#10: 1 + \"x\" === \"1x\". Actual: ' + (1 + \"x\"));\n}\n",
|
|
"id": "S11.6.1_A3.2_T2.1"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) is different from Type(Primitive(y)) and both types vary between String (primitive or object) and Boolean (primitive and object)",
|
|
"test": "//CHECK#1\nif (true + \"1\" !== \"true1\") {\n $ERROR('#1: true + \"1\" === \"true1\". Actual: ' + (true + \"1\"));\n}\n\n//CHECK#2\nif (\"1\" + true !== \"1true\") {\n $ERROR('#2: \"1\" + true === \"1true\". Actual: ' + (\"1\" + true));\n}\n\n//CHECK#3\nif (new Boolean(true) + \"1\" !== \"true1\") {\n $ERROR('#3: new Boolean(true) + \"1\" === \"true1\". Actual: ' + (new Boolean(true) + \"1\"));\n}\n\n//CHECK#4\nif (\"1\" + new Boolean(true) !== \"1true\") {\n $ERROR('#4: \"1\" + new Boolean(true) === \"1true\". Actual: ' + (\"1\" + new Boolean(true)));\n}\n\n//CHECK#5\nif (true + new String(\"1\") !== \"true1\") {\n $ERROR('#5: true + new String(\"1\") === \"true1\". Actual: ' + (true + new String(\"1\")));\n}\n\n//CHECK#6\nif (new String(\"1\") + true !== \"1true\") {\n $ERROR('#6: new String(\"1\") + true === \"1true\". Actual: ' + (new String(\"1\") + true));\n}\n\n//CHECK#7\nif (new Boolean(true) + new String(\"1\") !== \"true1\") {\n $ERROR('#7: new Boolean(true) + new String(\"1\") === \"true1\". Actual: ' + (new Boolean(true) + new String(\"1\")));\n}\n\n//CHECK#8\nif (new String(\"1\") + new Boolean(true) !== \"1true\") {\n $ERROR('#8: new String(\"1\") + new Boolean(true) === \"1true\". Actual: ' + (new String(\"1\") + new Boolean(true)));\n}\n",
|
|
"id": "S11.6.1_A3.2_T2.2"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) is different from Type(Primitive(y)) and both types vary between String (primitive or object) and Undefined",
|
|
"test": "//CHECK#1\nif (\"1\" + undefined !== \"1undefined\") {\n $ERROR('#1: \"1\" + undefined === \"1undefined\". Actual: ' + (\"1\" + undefined));\n}\n\n//CHECK#2\nif (undefined + \"1\" !== \"undefined1\") {\n $ERROR('#2: undefined + \"1\" === \"undefined1\". Actual: ' + (undefined + \"1\"));\n}\n\n//CHECK#3\nif (new String(\"1\") + undefined !== \"1undefined\") {\n $ERROR('#3: new String(\"1\") + undefined === \"1undefined\". Actual: ' + (new String(\"1\") + undefined));\n}\n\n//CHECK#4\nif (undefined + new String(\"1\") !== \"undefined1\") {\n $ERROR('#4: undefined + new String(\"1\") === \"undefined1\". Actual: ' + (undefined + new String(\"1\")));\n}\n",
|
|
"id": "S11.6.1_A3.2_T2.3"
|
|
},
|
|
{
|
|
"section": "11.6.1",
|
|
"description": "Type(Primitive(x)) is different from Type(Primitive(y)) and both types vary between String (primitive or object) and Null",
|
|
"test": "//CHECK#1\nif (\"1\" + null !== \"1null\") {\n $ERROR('#1: \"1\" + null === \"1null\". Actual: ' + (\"1\" + null));\n}\n\n//CHECK#2\nif (null + \"1\" !== \"null1\") {\n $ERROR('#2: null + \"1\" === \"null1\". Actual: ' + (null + \"1\"));\n}\n\n//CHECK#3\nif (new String(\"1\") + null !== \"1null\") {\n $ERROR('#3: new String(\"1\") + null === \"1null\". Actual: ' + (new String(\"1\") + null));\n}\n\n//CHECK#4\nif (null + new String(\"1\") !== \"null1\") {\n $ERROR('#4: null + new String(\"1\") === \"null1\". Actual: ' + (null + new String(\"1\")));\n}\n",
|
|
"id": "S11.6.1_A3.2_T2.4"
|
|
},
|
|
{
|
|
"section": "11.6.1, 11.6.3",
|
|
"description": "If either operand is NaN, the result is NaN",
|
|
"test": "//CHECK#1\nif (isNaN(Number.NaN + 1) !== true ) {\n $ERROR('#1: NaN + 1 === Not-a-Number. Actual: ' + (NaN + 1));\n}\n\n//CHECK#2\nif (isNaN(1 + Number.NaN) !== true ) {\n $ERROR('#2: 1 + NaN === Not-a-Number. Actual: ' + (1 + NaN));\n}\n\n//CHECK#3\nif (isNaN(Number.NaN + Number.POSITIVE_INFINITY) !== true ) {\n $ERROR('#3: NaN + Infinity === Not-a-Number. Actual: ' + (NaN + Infinity));\n}\n\n//CHECK#4\nif (isNaN(Number.POSITIVE_INFINITY + Number.NaN) !== true ) {\n $ERROR('#4: Infinity + NaN === Not-a-Number. Actual: ' + (Infinity + NaN));\n}\n\n//CHECK#5\nif (isNaN(Number.NaN + Number.NEGATIVE_INFINITY) !== true ) {\n $ERROR('#5: NaN + Infinity === Not-a-Number. Actual: ' + (NaN + Infinity));\n}\n\n//CHECK#6\nif (isNaN(Number.NEGATIVE_INFINITY + Number.NaN) !== true ) {\n $ERROR('#6: Infinity + NaN === Not-a-Number. Actual: ' + (Infinity + NaN));\n}\n\n",
|
|
"id": "S11.6.1_A4_T1"
|
|
},
|
|
{
|
|
"section": "11.6.1, 11.6.3",
|
|
"description": "The sum of two infinities of opposite sign is NaN",
|
|
"test": "//CHECK#1\nif (isNaN(Number.POSITIVE_INFINITY + Number.NEGATIVE_INFINITY) !== true ) {\n $ERROR('#1: Infinity + -Infinity === Not-a-Number. Actual: ' + (Infinity + -Infinity));\n}\n\n//CHECK#2\nif (isNaN(Number.NEGATIVE_INFINITY + Number.POSITIVE_INFINITY) !== true ) {\n $ERROR('#2: -Infinity + Infinity === Not-a-Number. Actual: ' + (-Infinity + Infinity));\n}\n\n\n\n",
|
|
"id": "S11.6.1_A4_T2"
|
|
},
|
|
{
|
|
"section": "11.6.1, 11.6.3",
|
|
"description": "The sum of two infinities of the same sign is the infinity of that sign",
|
|
"test": "//CHECK#1\nif (Number.POSITIVE_INFINITY + Number.POSITIVE_INFINITY !== Number.POSITIVE_INFINITY ) {\n $ERROR('#1: Infinity + Infinity === Infinity. Actual: ' + (Infinity + Infinity));\n}\n\n//CHECK#2\nif (Number.NEGATIVE_INFINITY + Number.NEGATIVE_INFINITY !== Number.NEGATIVE_INFINITY ) {\n $ERROR('#2: -Infinity + -Infinity === -Infinity. Actual: ' + (-Infinity + -Infinity));\n}\n\n\n\n",
|
|
"id": "S11.6.1_A4_T3"
|
|
},
|
|
{
|
|
"section": "11.6.1, 11.6.3",
|
|
"description": "The sum of an infinity and a finite value is equal to the infinite operand",
|
|
"test": "//CHECK#1\nif (Number.POSITIVE_INFINITY + 1 !== Number.POSITIVE_INFINITY ) {\n $ERROR('#1: Infinity + 1 === Infinity. Actual: ' + (Infinity + 1));\n}\n\n//CHECK#2\nif (-1 + Number.POSITIVE_INFINITY !== Number.POSITIVE_INFINITY ) {\n $ERROR('#2: -1 + Infinity === Infinity. Actual: ' + (-1 + Infinity));\n}\n\n//CHECK#3\nif (Number.NEGATIVE_INFINITY + 1 !== Number.NEGATIVE_INFINITY ) {\n $ERROR('#3: -Infinity + 1 === -Infinity. Actual: ' + (-Infinity + 1));\n}\n\n//CHECK#4\nif (-1 + Number.NEGATIVE_INFINITY !== Number.NEGATIVE_INFINITY ) {\n $ERROR('#4: -1 + -Infinity === -Infinity. Actual: ' + (-1 + -Infinity));\n}\n\n//CHECK#5\nif (Number.POSITIVE_INFINITY + Number.MAX_VALUE !== Number.POSITIVE_INFINITY ) {\n $ERROR('#5: Infinity + Number.MAX_VALUE === Infinity. Actual: ' + (Infinity + Number.MAX_VALUE));\n}\n\n//CHECK#6\nif (-Number.MAX_VALUE + Number.POSITIVE_INFINITY !== Number.POSITIVE_INFINITY ) {\n $ERROR('#6: -Number.MAX_VALUE + Infinity === Infinity. Actual: ' + (-Number.MAX_VALUE + Infinity));\n}\n\n//CHECK#7\nif (Number.NEGATIVE_INFINITY + Number.MAX_VALUE !== Number.NEGATIVE_INFINITY ) {\n $ERROR('#7: -Infinity + Number.MAX_VALUE === -Infinity. Actual: ' + (-Infinity + Number.MAX_VALUE));\n}\n\n//CHECK#8\nif (-Number.MAX_VALUE + Number.NEGATIVE_INFINITY !== Number.NEGATIVE_INFINITY ) {\n $ERROR('#8: -Number.MAX_VALUE + -Infinity === -Infinity. Actual: ' + (-Number.MAX_VALUE + -Infinity));\n}\n\n\n\n",
|
|
"id": "S11.6.1_A4_T4"
|
|
},
|
|
{
|
|
"section": "11.6.1, 11.6.3",
|
|
"description": "The sum of two negative zeros is -0. The sum of two positive zeros, or of two zeros of opposite sign is +0",
|
|
"test": "//CHECK#1\nif (-0 + -0 !== -0 ) { \n $ERROR('#1.1: -0 + -0 === 0. Actual: ' + (-0 + -0));\n} else {\n if (1 / (-0 + -0) !== Number.NEGATIVE_INFINITY) {\n $ERROR('#1.1: -0 + -0 === - 0. Actual: +0');\n }\n}\n\n//CHECK#2\nif (0 + -0 !== 0 ) { \n $ERROR('#2.1: 0 + -0 === 0. Actual: ' + (0 + -0));\n} else {\n if (1 / (0 + -0) !== Number.POSITIVE_INFINITY) {\n $ERROR('#2.2: 0 + -0 === + 0. Actual: -0');\n }\n}\n\n//CHECK#3\nif (-0 + 0 !== 0 ) { \n $ERROR('#3.1: -0 + 0 === 0. Actual: ' + (-0 + 0));\n} else {\n if (1 / (-0 + 0) !== Number.POSITIVE_INFINITY) {\n $ERROR('#3.2: -0 + 0 === + 0. Actual: -0');\n }\n}\n\n//CHECK#4\nif (0 + 0 !== 0 ) { \n $ERROR('#4.1: 0 + 0 === 0. Actual: ' + (0 + 0));\n} else {\n if (1 / (0 + 0) !== Number.POSITIVE_INFINITY) {\n $ERROR('#4.2: 0 + 0 === + 0. Actual: -0');\n }\n}\n",
|
|
"id": "S11.6.1_A4_T5"
|
|
},
|
|
{
|
|
"section": "11.6.1, 11.6.3",
|
|
"description": "The sum of a zero and a nonzero finite value is equal to the nonzero operand",
|
|
"test": "//CHECK#1\nif (1 + -0 !== 1 ) { \n $ERROR('#1: 1 + -0 === 1. Actual: ' + (1 + -0));\n}\n\n//CHECK#2\nif (1 + 0 !== 1 ) { \n $ERROR('#2: 1 + 0 === 1. Actual: ' + (1 + 0));\n} \n\n//CHECK#3\nif (-0 + 1 !== 1 ) { \n $ERROR('#3: -0 + 1 === 1. Actual: ' + (-0 + 1));\n}\n\n//CHECK#4\nif (0 + 1 !== 1 ) { \n $ERROR('#4: 0 + 1 === 1. Actual: ' + (0 + 1));\n} \n\n//CHECK#5\nif (Number.MAX_VALUE + -0 !== Number.MAX_VALUE ) { \n $ERROR('#5: Number.MAX_VALUE + -0 === Number.MAX_VALUE. Actual: ' + (Number.MAX_VALUE + -0));\n}\n\n//CHECK#6\nif (Number.MAX_VALUE + 0 !== Number.MAX_VALUE ) { \n $ERROR('#6: Number.MAX_VALUE + 0 === Number.MAX_VALUE. Actual: ' + (Number.MAX_VALUE + 0));\n} \n\n//CHECK#7\nif (-0 + Number.MIN_VALUE !== Number.MIN_VALUE ) { \n $ERROR('#7: -0 + Number.MIN_VALUE === Number.MIN_VALUE. Actual: ' + (-0 + Number.MIN_VALUE));\n}\n\n//CHECK#8\nif (0 + Number.MIN_VALUE !== Number.MIN_VALUE ) { \n $ERROR('#8: 0 + Number.MIN_VALUE === Number.MIN_VALUE. Actual: ' + (0 + Number.MIN_VALUE));\n} \n",
|
|
"id": "S11.6.1_A4_T6"
|
|
},
|
|
{
|
|
"section": "11.6.1, 11.6.3",
|
|
"description": "The sum of two nonzero finite values of the same magnitude and opposite sign is +0",
|
|
"test": "//CHECK#1\nif (-Number.MIN_VALUE + Number.MIN_VALUE !== +0) { \n $ERROR('#1.1: -Number.MIN_VALUE + Number.MIN_VALUE === 0. Actual: ' + (-Number.MIN_VALUE + Number.MIN_VALUE));\n} else {\n if (1 / (-Number.MIN_VALUE + Number.MIN_VALUE) !== Number.POSITIVE_INFINITY) {\n $ERROR('#1.2: -Number.MIN_VALUE + Number.MIN_VALUE === + 0. Actual: -0');\n }\n}\n\n//CHECK#2\nif (-Number.MAX_VALUE + Number.MAX_VALUE !== +0) { \n $ERROR('#2.1: -Number.MAX_VALUE + Number.MAX_VALUE === 0. Actual: ' + (-Number.MAX_VALUE + Number.MAX_VALUE));\n} else {\n if (1 / (-Number.MAX_VALUE + Number.MAX_VALUE) !== Number.POSITIVE_INFINITY) {\n $ERROR('#2.2: -Number.MAX_VALUE + Number.MAX_VALUE === + 0. Actual: -0');\n }\n}\n\n//CHECK#3\nif (-1 / Number.MAX_VALUE + 1 / Number.MAX_VALUE !== +0) { \n $ERROR('#3.1: -1 / Number.MAX_VALUE + 1 / Number.MAX_VALUE === 0. Actual: ' + (-1 / Number.MAX_VALUE + 1 / Number.MAX_VALUE));\n} else {\n if (1 / (-1 / Number.MAX_VALUE + 1 / Number.MAX_VALUE) !== Number.POSITIVE_INFINITY) {\n $ERROR('#3.2: -1 / Number.MAX_VALUE + 1 / Number.MAX_VALUE === + 0. Actual: -0');\n }\n}\n",
|
|
"id": "S11.6.1_A4_T7"
|
|
},
|
|
{
|
|
"section": "11.6.1, 11.6.3",
|
|
"description": "If the magnitude is too large to represent, the operation overflows and the result is then an infinity of appropriate sign",
|
|
"test": "//CHECK#1\nif (Number.MAX_VALUE + Number.MAX_VALUE !== Number.POSITIVE_INFINITY) {\n $ERROR('#1: Number.MAX_VALUE + Number.MAX_VALUE === Number.POSITIVE_INFINITY. Actual: ' + (Number.MAX_VALUE + Number.MAX_VALUE));\n}\n\n//CHECK#2\nif (-Number.MAX_VALUE - Number.MAX_VALUE !== Number.NEGATIVE_INFINITY) {\n $ERROR('#2: -Number.MAX_VALUE - Number.MAX_VALUE === Number.NEGATIVE_INFINITY. Actual: ' + (-Number.MAX_VALUE - Number.MAX_VALUE));\n}\n\n//CHECK#3\nif (1e+308 + 1e+308 !== Number.POSITIVE_INFINITY) {\n $ERROR('#3: 1e+308 + 1e+308 === Number.POSITIVE_INFINITY. Actual: ' + (1e+308 + 1e+308));\n}\n\n//CHECK#4\nif (-8.99e+307 - 8.99e+307 !== Number.NEGATIVE_INFINITY) {\n $ERROR('#4: -8.99e+307 - 8.99e+307 === Number.NEGATIVE_INFINITY. Actual: ' + (-8.99e+307 - 8.99e+307));\n}\n",
|
|
"id": "S11.6.1_A4_T8"
|
|
},
|
|
{
|
|
"section": "11.6.1, 11.6.3",
|
|
"description": "The addition operator is not always associative ( x + y + z is the same (x + y) + z, not x + (y + z))",
|
|
"test": "//CHECK#1\nif (-Number.MAX_VALUE + Number.MAX_VALUE + Number.MAX_VALUE !== (-Number.MAX_VALUE + Number.MAX_VALUE) + Number.MAX_VALUE) {\n $ERROR('#1: -Number.MAX_VALUE + Number.MAX_VALUE + Number.MAX_VALUE === (-Number.MAX_VALUE + Number.MAX_VALUE) + Number.MAX_VALUE. Actual: ' + (-Number.MAX_VALUE + Number.MAX_VALUE + Number.MAX_VALUE));\n} \n\n//CHECK#2\nif ((-Number.MAX_VALUE + Number.MAX_VALUE) + Number.MAX_VALUE === -Number.MAX_VALUE + (Number.MAX_VALUE + Number.MAX_VALUE)) {\n $ERROR('#2: (-Number.MAX_VALUE + Number.MAX_VALUE) + Number.MAX_VALUE === -Number.MAX_VALUE + (Number.MAX_VALUE + Number.MAX_VALUE). Actual: ' + ((-Number.MAX_VALUE + Number.MAX_VALUE) + Number.MAX_VALUE));\n}\n\n//CHECK#3\nif (\"1\" + 1 + 1 !== (\"1\" + 1) + 1) {\n $ERROR('#3: \"1\" + 1 + 1 === (\"1\" + 1) + 1. Actual: ' + (\"1\" + 1 + 1));\n} \n\n//CHECK#4\nif ((\"1\" + 1) + 1 === \"1\" + (1 + 1)) {\n $ERROR('#4: (\"1\" + 1) + 1 !== \"1\" + (1 + 1)');\n}\n",
|
|
"id": "S11.6.1_A4_T9"
|
|
}
|
|
]
|
|
}
|
|
}
|