From 632640821596fa609a3c19d6f0152778faa08da1 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Tue, 28 Jul 2015 17:52:16 -0400 Subject: [PATCH] Add tests for Reflect.enumerate --- ...does-not-iterate-over-symbol-properties.js | 37 +++++++++++ test/built-ins/Reflect/enumerate/enumerate.js | 17 +++++ test/built-ins/Reflect/enumerate/length.js | 17 +++++ test/built-ins/Reflect/enumerate/name.js | 22 +++++++ .../enumerate/return-abrupt-from-result.js | 24 +++++++ .../Reflect/enumerate/return-iterator.js | 62 +++++++++++++++++++ .../enumerate/target-is-not-object-throws.js | 28 +++++++++ .../enumerate/target-is-symbol-throws.js | 17 +++++ 8 files changed, 224 insertions(+) create mode 100644 test/built-ins/Reflect/enumerate/does-not-iterate-over-symbol-properties.js create mode 100644 test/built-ins/Reflect/enumerate/enumerate.js create mode 100644 test/built-ins/Reflect/enumerate/length.js create mode 100644 test/built-ins/Reflect/enumerate/name.js create mode 100644 test/built-ins/Reflect/enumerate/return-abrupt-from-result.js create mode 100644 test/built-ins/Reflect/enumerate/return-iterator.js create mode 100644 test/built-ins/Reflect/enumerate/target-is-not-object-throws.js create mode 100644 test/built-ins/Reflect/enumerate/target-is-symbol-throws.js diff --git a/test/built-ins/Reflect/enumerate/does-not-iterate-over-symbol-properties.js b/test/built-ins/Reflect/enumerate/does-not-iterate-over-symbol-properties.js new file mode 100644 index 0000000000..95d038ee5d --- /dev/null +++ b/test/built-ins/Reflect/enumerate/does-not-iterate-over-symbol-properties.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 Leonardo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.5 +description: > + Returned iterator does not iterate over symbol properties. +info: > + 26.1.5 Reflect.enumerate ( target ) + + ... + 2. Return target.[[Enumerate]](). +features: [Symbol] +---*/ + +var iter, step; +var s = Symbol('1'); + +var o = { + 'a': 1, + 'b': 1 +}; + +o[s] = 1; + +iter = Reflect.enumerate(o); + +step = iter.next(); +assert.sameValue(step.value, 'a'); +assert.sameValue(step.done, false); + +step = iter.next(); +assert.sameValue(step.value, 'b'); +assert.sameValue(step.done, false); + +step = iter.next(); +assert.sameValue(step.value, undefined); +assert.sameValue(step.done, true); diff --git a/test/built-ins/Reflect/enumerate/enumerate.js b/test/built-ins/Reflect/enumerate/enumerate.js new file mode 100644 index 0000000000..845084e5a2 --- /dev/null +++ b/test/built-ins/Reflect/enumerate/enumerate.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.5 +description: > + Reflect.enumerate is configurable, writable and not enumerable. +info: > + 26.1.5 Reflect.enumerate ( target ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Reflect, 'enumerate'); +verifyWritable(Reflect, 'enumerate'); +verifyConfigurable(Reflect, 'enumerate'); diff --git a/test/built-ins/Reflect/enumerate/length.js b/test/built-ins/Reflect/enumerate/length.js new file mode 100644 index 0000000000..66c9361662 --- /dev/null +++ b/test/built-ins/Reflect/enumerate/length.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.5 +description: > + Reflect.enumerate.length value and property descriptor +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Reflect.enumerate.length, 1, + 'The value of `Reflect.enumerate.length` is `1`' +); + +verifyNotEnumerable(Reflect.enumerate, 'length'); +verifyNotWritable(Reflect.enumerate, 'length'); +verifyConfigurable(Reflect.enumerate, 'length'); diff --git a/test/built-ins/Reflect/enumerate/name.js b/test/built-ins/Reflect/enumerate/name.js new file mode 100644 index 0000000000..2f210a14c9 --- /dev/null +++ b/test/built-ins/Reflect/enumerate/name.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.5 +description: > + Reflect.enumerate.name value and property descriptor +info: > + 26.1.5 Reflect.enumerate ( target ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + Reflect.enumerate.name, 'enumerate', + 'The value of `Reflect.enumerate.name` is `"enumerate"`' +); + +verifyNotEnumerable(Reflect.enumerate, 'name'); +verifyNotWritable(Reflect.enumerate, 'name'); +verifyConfigurable(Reflect.enumerate, 'name'); diff --git a/test/built-ins/Reflect/enumerate/return-abrupt-from-result.js b/test/built-ins/Reflect/enumerate/return-abrupt-from-result.js new file mode 100644 index 0000000000..ce26191b15 --- /dev/null +++ b/test/built-ins/Reflect/enumerate/return-abrupt-from-result.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.5 +description: > + Return abrupt result. +info: > + 26.1.5 Reflect.enumerate ( target ) + + ... + 2. Return target.[[Enumerate]](). +features: [Proxy] +---*/ + +var o = {}; +var p = new Proxy(o, { + enumerate: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.enumerate(p); +}); diff --git a/test/built-ins/Reflect/enumerate/return-iterator.js b/test/built-ins/Reflect/enumerate/return-iterator.js new file mode 100644 index 0000000000..3d7c9f6288 --- /dev/null +++ b/test/built-ins/Reflect/enumerate/return-iterator.js @@ -0,0 +1,62 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.5 +description: > + Return an iterator. +info: > + 26.1.5 Reflect.enumerate ( target ) + + ... + 2. Return target.[[Enumerate]](). +---*/ + +var iter, step; +var arr = ['a', 'b', 'c']; + +iter = Reflect.enumerate(arr); + +step = iter.next(); +assert.sameValue(step.value, '0'); +assert.sameValue(step.done, false); + +step = iter.next(); +assert.sameValue(step.value, '1'); +assert.sameValue(step.done, false); + +step = iter.next(); +assert.sameValue(step.value, '2'); +assert.sameValue(step.done, false); + +step = iter.next(); +assert.sameValue(step.value, undefined); +assert.sameValue(step.done, true); + +var o = { + 'a': 42, + 'b': 43, + 'c': 44 +}; + +Object.defineProperty(o, 'd', { + enumerable: false, + value: 45 +}); + +iter = Reflect.enumerate(o); + +step = iter.next(); +assert.sameValue(step.value, 'a'); +assert.sameValue(step.done, false); + +step = iter.next(); +assert.sameValue(step.value, 'b'); +assert.sameValue(step.done, false); + +step = iter.next(); +assert.sameValue(step.value, 'c'); +assert.sameValue(step.done, false); + +step = iter.next(); +assert.sameValue(step.value, undefined); +assert.sameValue(step.done, true); diff --git a/test/built-ins/Reflect/enumerate/target-is-not-object-throws.js b/test/built-ins/Reflect/enumerate/target-is-not-object-throws.js new file mode 100644 index 0000000000..8c0dc61442 --- /dev/null +++ b/test/built-ins/Reflect/enumerate/target-is-not-object-throws.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.5 +description: > + Throws a TypeError if target is not an Object. +info: > + 26.1.5 Reflect.enumerate ( target ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + Reflect.enumerate(1); +}); + +assert.throws(TypeError, function() { + Reflect.enumerate(null); +}); + +assert.throws(TypeError, function() { + Reflect.enumerate(undefined); +}); + +assert.throws(TypeError, function() { + Reflect.enumerate(''); +}); diff --git a/test/built-ins/Reflect/enumerate/target-is-symbol-throws.js b/test/built-ins/Reflect/enumerate/target-is-symbol-throws.js new file mode 100644 index 0000000000..f8377df5d3 --- /dev/null +++ b/test/built-ins/Reflect/enumerate/target-is-symbol-throws.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 26.1.5 +description: > + Throws a TypeError if target is a Symbol +info: > + 26.1.5 Reflect.enumerate ( target ) + + 1. If Type(target) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + Reflect.enumerate(Symbol(1), 'p'); +});