From 8162f8c58f5111886e71174666d2f11e278b444e Mon Sep 17 00:00:00 2001 From: Liviu Rau Date: Fri, 27 Oct 2023 09:48:09 -0700 Subject: [PATCH] [test262] Add set method tests to staging Reland https://crrev.com/c/4913993 This CL adds three tests from test methods tests to staging directory with correct format. Bug: v8:13556 Change-Id: I93817eb84e077436071dbae98bc800dd58851f91 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4983674 Reviewed-by: Michael Achenbach Commit-Queue: Liviu Rau Cr-Commit-Position: refs/heads/main@{#90645} --- features.txt | 4 +++ .../set-intersect-other-is-set-like.js | 31 +++++++++++++++++++ .../set-intersection-other-is-map.js | 24 ++++++++++++++ .../set-intersection-other-is-set.js | 24 ++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 test/staging/set-methods/set-intersect-other-is-set-like.js create mode 100644 test/staging/set-methods/set-intersection-other-is-map.js create mode 100644 test/staging/set-methods/set-intersection-other-is-set.js diff --git a/features.txt b/features.txt index 495fb466c0..692cbf9bcc 100644 --- a/features.txt +++ b/features.txt @@ -263,3 +263,7 @@ __setter__ IsHTMLDDA host-gc-required + +# Set methods +# https://github.com/tc39/proposal-set-methods +set-methods diff --git a/test/staging/set-methods/set-intersect-other-is-set-like.js b/test/staging/set-methods/set-intersect-other-is-set-like.js new file mode 100644 index 0000000000..168b2fa2b4 --- /dev/null +++ b/test/staging/set-methods/set-intersect-other-is-set-like.js @@ -0,0 +1,31 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: test intersection method when `other` is a set-like. +features: [set-methods] +includes: [compareArray.js] +---*/ + +const SetLike = { + arr: [42, 43, 45], + size: 3, + keys() { + return this.arr[Symbol.iterator](); + }, + has(key) { + return this.arr.indexOf(key) != -1; + } + }; + +const firstSet = new Set(); +firstSet.add(42); +firstSet.add(43); + +const resultSet = new Set(); +resultSet.add(42); +resultSet.add(43); + +const resultArray = Array.from(resultSet); +const intersectionArray = Array.from(firstSet.intersection(SetLike)); + +assert.compareArray(resultArray, intersectionArray); diff --git a/test/staging/set-methods/set-intersection-other-is-map.js b/test/staging/set-methods/set-intersection-other-is-map.js new file mode 100644 index 0000000000..9ea6ea8217 --- /dev/null +++ b/test/staging/set-methods/set-intersection-other-is-map.js @@ -0,0 +1,24 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: test intersection method when `other` is a map. +features: [set-methods] +includes: [compareArray.js] +---*/ + +const firstSet = new Set(); +firstSet.add(42); +firstSet.add(43); + +const other = new Map(); +other.set(42); +other.set(46); +other.set(47); + +const resultSet = new Set(); +resultSet.add(42); + +const resultArray = Array.from(resultSet); +const intersectionArray = Array.from(firstSet.intersection(other)); + +assert.compareArray(resultArray, intersectionArray); diff --git a/test/staging/set-methods/set-intersection-other-is-set.js b/test/staging/set-methods/set-intersection-other-is-set.js new file mode 100644 index 0000000000..b9f2201906 --- /dev/null +++ b/test/staging/set-methods/set-intersection-other-is-set.js @@ -0,0 +1,24 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: test intersection method when `other` is a set. +features: [set-methods] +includes: [compareArray.js] +---*/ + +const firstSet = new Set(); +firstSet.add(42); +firstSet.add(43); +firstSet.add(44); + +const otherSet = new Set(); +otherSet.add(42); +otherSet.add(45); + +const resultSet = new Set(); +resultSet.add(42); + +const resultArray = Array.from(resultSet); +const intersectionArray = Array.from(firstSet.intersection(otherSet)); + +assert.compareArray(resultArray, intersectionArray);