mirror of https://github.com/tc39/test262.git
feat(optional-chaining): add tests for IterationStatement
This commit is contained in:
parent
7040938bd0
commit
3d0c2037c3
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright 2019 Google, LLC. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: prod-OptionalExpression
|
||||||
|
description: >
|
||||||
|
optional chain in test portion of do while statement
|
||||||
|
info: |
|
||||||
|
IterationStatement
|
||||||
|
do Statement while (OptionalExpression)
|
||||||
|
features: [optional-chaining]
|
||||||
|
---*/
|
||||||
|
let count = 0;
|
||||||
|
const obj = {a: true};
|
||||||
|
do {
|
||||||
|
count++;
|
||||||
|
break;
|
||||||
|
} while (obj?.a);
|
||||||
|
assert.sameValue(1, count);
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright 2019 Google, LLC. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: prod-OptionalExpression
|
||||||
|
description: >
|
||||||
|
optional chain RHS of for await statement
|
||||||
|
info: |
|
||||||
|
IterationStatement
|
||||||
|
for await (LeftHandSideExpression of AssignmentExpression) Statement
|
||||||
|
features: [optional-chaining]
|
||||||
|
---*/
|
||||||
|
const obj = {
|
||||||
|
iterable: {
|
||||||
|
[Symbol.asyncIterator]() {
|
||||||
|
return {
|
||||||
|
i: 0,
|
||||||
|
next() {
|
||||||
|
if (this.i < 3) {
|
||||||
|
return Promise.resolve({ value: this.i++, done: false });
|
||||||
|
}
|
||||||
|
return Promise.resolve({ done: true });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
async function checkAssertions() {
|
||||||
|
let count = 0;
|
||||||
|
for await (const num of obj?.iterable) {
|
||||||
|
count += num;
|
||||||
|
}
|
||||||
|
assert.sameValue(3, count);
|
||||||
|
}
|
||||||
|
checkAssertions().then($DONE, $DONE);
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright 2019 Google, LLC. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: prod-OptionalExpression
|
||||||
|
description: >
|
||||||
|
optional chain in test portion of do while statement
|
||||||
|
info: |
|
||||||
|
IterationStatement
|
||||||
|
for (LeftHandSideExpression in Expression) Statement
|
||||||
|
features: [optional-chaining]
|
||||||
|
---*/
|
||||||
|
const obj = {
|
||||||
|
inner: {
|
||||||
|
a: 1,
|
||||||
|
b: 2
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let str = '';
|
||||||
|
for (const key in obj?.inner) {
|
||||||
|
str += key;
|
||||||
|
}
|
||||||
|
assert.sameValue('ab', str);
|
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright 2019 Google, LLC. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: prod-OptionalExpression
|
||||||
|
description: >
|
||||||
|
optional chain returning undefined in RHS of for of statement
|
||||||
|
info: |
|
||||||
|
IterationStatement
|
||||||
|
for (LeftHandSideExpression of Expression) Statement
|
||||||
|
features: [optional-chaining]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
const obj = undefined;
|
||||||
|
for (const key of obj?.a) {
|
||||||
|
str += key;
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright 2019 Google, LLC. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: prod-OptionalExpression
|
||||||
|
description: >
|
||||||
|
optional chain in init/test/update of for statement
|
||||||
|
info: |
|
||||||
|
IterationStatement
|
||||||
|
for (Expression; Expression; Expression) Statement
|
||||||
|
features: [optional-chaining]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// OptionalExpression in test.
|
||||||
|
let count;
|
||||||
|
const obj = {a: true};
|
||||||
|
for (count = 0; obj?.a; count++) {
|
||||||
|
if (count > 0) break;
|
||||||
|
}
|
||||||
|
assert.sameValue(1, count);
|
||||||
|
|
||||||
|
// OptionalExpression in init/test/update.
|
||||||
|
let count2 = 0;
|
||||||
|
const obj2 = undefined;
|
||||||
|
for (obj?.a; obj2?.a; obj?.a) {
|
||||||
|
count2++;
|
||||||
|
}
|
||||||
|
assert.sameValue(0, count2);
|
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright 2019 Google, LLC. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: prod-OptionalExpression
|
||||||
|
description: >
|
||||||
|
optional chain in test portion of while statement
|
||||||
|
info: |
|
||||||
|
IterationStatement
|
||||||
|
while (Expression) Statement
|
||||||
|
features: [optional-chaining]
|
||||||
|
---*/
|
||||||
|
let count = 0;
|
||||||
|
const obj = {a: true};
|
||||||
|
while (obj?.a) {
|
||||||
|
count++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
assert.sameValue(1, count);
|
Loading…
Reference in New Issue