mirror of https://github.com/tc39/test262.git
Merge pull request #293 from yanlxu/Object-Assign
Add tests for Object-Assign
This commit is contained in:
commit
12cc01484e
|
@ -0,0 +1,13 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*--
|
||||||
|
description: Object properties are assigned to target in ascending index order,
|
||||||
|
i.e. a later assignment to the same property overrides an earlier assignment.
|
||||||
|
es6id: 19.1.2.1
|
||||||
|
--*/
|
||||||
|
|
||||||
|
var target = {a: 1};
|
||||||
|
var result = Object.assign(target,{a:2},{a:"c"});
|
||||||
|
|
||||||
|
assert.sameValue(result.a, "c", "The value should be 'c'.");
|
|
@ -0,0 +1,13 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: test Object.Assign(target,...sources),only one argument was passed,
|
||||||
|
return ToObject(target)
|
||||||
|
es6id: 19.1.2.1.3
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var target = "a";
|
||||||
|
var result = Object.assign(target);
|
||||||
|
|
||||||
|
assert.sameValue(result.valueOf(), "a", "The value should be 'a'.");
|
|
@ -0,0 +1,17 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Test override of Object.Assign(target,...sources),
|
||||||
|
Every string from sources will be wrapped to objects, and override from the first letter(result[0]) all the time
|
||||||
|
es6id: 19.1.2.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var target = 12;
|
||||||
|
var result = Object.assign(target,"aaa","bb2b","1c");
|
||||||
|
|
||||||
|
assert.sameValue(Object.keys(result).length, 4 , "The length should be 4 in the final object.");
|
||||||
|
assert.sameValue(result[0], "1", "The value should be {\"0\":\"1\"}.");
|
||||||
|
assert.sameValue(result[1], "c", "The value should be {\"1\":\"c\"}.");
|
||||||
|
assert.sameValue(result[2], "2", "The value should be {\"2\":\"2\"}.");
|
||||||
|
assert.sameValue(result[3], "b", "The value should be {\"3\":\"b\"}.");
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Test Object.Assign(target,...sources).
|
||||||
|
es6id: 19.1.2.1.5.c
|
||||||
|
---*/
|
||||||
|
|
||||||
|
//"a" will be an property of the final object and the value should be 1
|
||||||
|
var target = {a:1};
|
||||||
|
/*---
|
||||||
|
"1a2c3" have own enumerable properties, so it Should be wrapped to objects;
|
||||||
|
{b:6} is an object,should be assigned to final object.
|
||||||
|
undefined and null should be ignored;
|
||||||
|
125 is a number,it cannot has own enumerable properties;
|
||||||
|
{a:"c"},{a:5} will override property a, the value should be 5.
|
||||||
|
---*/
|
||||||
|
var result = Object.assign(target,"1a2c3",{a:"c"},undefined,{b:6},null,125,{a:5});
|
||||||
|
|
||||||
|
assert.sameValue(Object.keys(result).length, 7 , "The length should be 7 in the final object.");
|
||||||
|
assert.sameValue(result.a, 5, "The value should be {a:5}.");
|
||||||
|
assert.sameValue(result[0], "1", "The value should be {\"0\":\"1\"}.");
|
||||||
|
assert.sameValue(result[1], "a", "The value should be {\"1\":\"a\"}.");
|
||||||
|
assert.sameValue(result[2], "2", "The value should be {\"2\":\"2\"}.");
|
||||||
|
assert.sameValue(result[3], "c", "The value should be {\"3\":\"c\"}.");
|
||||||
|
assert.sameValue(result[4], "3", "The value should be {\"4\":\"3\"}.");
|
||||||
|
assert.sameValue(result.b, 6, "The value should be {b:6}.");
|
|
@ -0,0 +1,12 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: null and undefined source should be ignored,result should be original object.
|
||||||
|
es6id: 19.1.2.1.5.a
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var target = new Object();
|
||||||
|
var result = Object.assign(target,undefined,null);
|
||||||
|
|
||||||
|
assert.sameValue(result, target, "null and undefined should be ignored, result should be original object.");
|
|
@ -0,0 +1,13 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*--
|
||||||
|
description: Number,Boolean,Symbol cannot have own enumerable properties,
|
||||||
|
So cannot be Assigned.Here result should be original object.
|
||||||
|
es6id: 19.1.2.1.5.c
|
||||||
|
--*/
|
||||||
|
|
||||||
|
var target = new Object();
|
||||||
|
var result = Object.assign(target,123,true,Symbol('foo'));
|
||||||
|
|
||||||
|
assert.sameValue(result, target, "Numbers, booleans, and symbols cannot have wrappers with own enumerable properties.");
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Test Object.Assign(target,...sources), string have own enumerable properties, so it can be wrapped to objects.
|
||||||
|
es6id: 19.1.2.1.5.c
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var target = new Object();
|
||||||
|
var result = Object.assign(target,"123");
|
||||||
|
|
||||||
|
assert.sameValue(result[0], "1", "The value should be {\"0\":\"1\"}.");
|
||||||
|
assert.sameValue(result[1], "2", "The value should be {\"1\":\"2\"}.");
|
||||||
|
assert.sameValue(result[2], "3", "The value should be {\"2\":\"3\"}.");
|
|
@ -0,0 +1,12 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Test the first argument(target) of Object.Assign(target,...sources),
|
||||||
|
if target is Boolean,the return value should be a new object whose value is target.
|
||||||
|
es6id: 19.1.2.1.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = Object.assign(true,{a:1});
|
||||||
|
assert.sameValue(typeof result, "object", "Return value should be an object.");
|
||||||
|
assert.sameValue(result.valueOf(), true, "Return value should be true.");
|
|
@ -0,0 +1,10 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Test the first argument(target) of Object.Assign(target,...sources),
|
||||||
|
if target is null,Should Throw a TypeError exception.
|
||||||
|
es6id: 19.1.2.1.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function(){Object.assign(null, {a:1});});
|
|
@ -0,0 +1,12 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Test the first argument(target) of Object.Assign(target,...sources),
|
||||||
|
if target is Number,the return value should be a new object whose value is target.
|
||||||
|
es6id: 19.1.2.1.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = Object.assign(1,{a:1});
|
||||||
|
assert.sameValue(typeof result, "object", "Return value should be an object.");
|
||||||
|
assert.sameValue(result.valueOf(), 1, "Return value should be 1.");
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Test the first argument(target) of Object.Assign(target,...sources),
|
||||||
|
if target is Object,its properties will be the properties of new object.
|
||||||
|
es6id: 19.1.2.1.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var target = {foo: 1};
|
||||||
|
var result = Object.assign(target,{a:2});
|
||||||
|
|
||||||
|
assert.sameValue(result.foo, 1, "The value should be {foo: 1}.");
|
||||||
|
assert.sameValue(result.a, 2, "The value should be {a: 2}.");
|
|
@ -0,0 +1,12 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Test the first argument(target) of Object.Assign(target,...sources),
|
||||||
|
if target is String,the return value should be a new object whose value is target.
|
||||||
|
es6id: 19.1.2.1.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = Object.assign("test",{a:1});
|
||||||
|
assert.sameValue(typeof result, "object", "Return value should be an object.");
|
||||||
|
assert.sameValue(result.valueOf(), "test", "Return value should be 'test'.");
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Test the first argument(target) of Object.Assign(target,...sources),
|
||||||
|
if target is Symbol,the return value should be a new Symbol object whose [[SymbolData]] value is target.
|
||||||
|
es6id: 19.1.2.1.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var target = Symbol('foo');
|
||||||
|
var result = Object.assign(target,{a:1});
|
||||||
|
|
||||||
|
assert.sameValue(typeof result, "object", "Return value should be a symbol object.");
|
||||||
|
assert.sameValue(result.toString(), "Symbol(foo)", "Return value should be 'Symbol(foo)'.");
|
|
@ -0,0 +1,10 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Test the first argument(target) of Object.Assign(target,...sources),
|
||||||
|
if target is Undefined,Should Throw a TypeError exception.
|
||||||
|
es6id: 19.1.2.1.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function(){Object.assign(undefined, {a:1});});
|
|
@ -0,0 +1,13 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Testing descriptor property of Object.assign
|
||||||
|
includes:
|
||||||
|
- propertyHelper.js
|
||||||
|
es6id: 19.1.2.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyWritable(Object, "assign");
|
||||||
|
verifyNotEnumerable(Object, "assign");
|
||||||
|
verifyConfigurable(Object, "assign");
|
|
@ -0,0 +1,9 @@
|
||||||
|
// Copyright 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: The length property of the assign method should be 2
|
||||||
|
es6id: 19.1.2.1
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(Object.assign.length, 2, "The length property of the assign method should be 2.");
|
Loading…
Reference in New Issue