From 1a7aee6ba09d08f3c7d24d65aca3219e89ec166b Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Wed, 20 May 2020 19:25:07 -0700 Subject: [PATCH] Add missing coverage for String.prototype.split (#2632) Fixes #2622 --- .../prototype/split/S15.5.4.14_A1_T6.js | 50 -------------- .../split/separator-undef-limit-custom.js | 67 +++++++++++++++++++ .../split/separator-undef-limit-zero.js | 64 ++++++++++++++++++ .../String/prototype/split/separator-undef.js | 31 +++++++++ 4 files changed, 162 insertions(+), 50 deletions(-) delete mode 100644 test/built-ins/String/prototype/split/S15.5.4.14_A1_T6.js create mode 100644 test/built-ins/String/prototype/split/separator-undef-limit-custom.js create mode 100644 test/built-ins/String/prototype/split/separator-undef-limit-zero.js create mode 100644 test/built-ins/String/prototype/split/separator-undef.js diff --git a/test/built-ins/String/prototype/split/S15.5.4.14_A1_T6.js b/test/built-ins/String/prototype/split/S15.5.4.14_A1_T6.js deleted file mode 100644 index 815d13d199..0000000000 --- a/test/built-ins/String/prototype/split/S15.5.4.14_A1_T6.js +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: | - String.prototype.split(separator, limit): - i) can be transferred to other kinds of objects for use as a method. - separator and limit can be any kinds of object since: - ii) if separator is not RegExp ToString(separator) performs and - iii) ToInteger(limit) performs -es5id: 15.5.4.14_A1_T6 -description: Argument is x, and instance is new String. x is undefined variable ----*/ - -//since ToString(undefined) evaluates to "" split(undefined) evaluates to split("",0) -var __split = new String("1undefined").split(x); - -////////////////////////////////////////////////////////////////////////////// -//CHECK#1 -if (typeof __split !== "object") { - $ERROR('#1: var x; __split = new String("1undefined").split(x); typeof __split === "object". Actual: ' + typeof __split); -} -// -////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////// -//CHECK#2 -if (__split.constructor !== Array) { - $ERROR('#2: var x; __split = new String("1undefined").split(x); __split.constructor === Array. Actual: ' + __split.constructor); -} -// -////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////// -//CHECK#3 -if (__split.length !== 1) { - $ERROR('#3: var x; __split = new String("1undefined").split(x); __split.length === 1. Actual: ' + __split.length); -} -// -////////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////////// -//CHECK#4 -if (__split[0] !== "1undefined") { - $ERROR('#4: var x; __split = new String("1undefined").split(x); __split[0] === "1undefined". Actual: ' + __split[0]); -} -// -////////////////////////////////////////////////////////////////////////////// - -var x; diff --git a/test/built-ins/String/prototype/split/separator-undef-limit-custom.js b/test/built-ins/String/prototype/split/separator-undef-limit-custom.js new file mode 100644 index 0000000000..9d03451d8c --- /dev/null +++ b/test/built-ins/String/prototype/split/separator-undef-limit-custom.js @@ -0,0 +1,67 @@ +// Copyright (C) 2020 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.split +description: Separator is undefined, limit is a positive number, return a new array with the string +info: | + ... + 3. Let S be ? ToString(O). + 4. Let A be ! ArrayCreate(0). + ... + 6. If limit is undefined, let lim be 232 - 1; else let lim be ? ToUint32(limit). + 7. Let R be ? ToString(separator). + 8. If lim = 0, return A. + 9. If separator is undefined, then + a. Perform ! CreateDataPropertyOrThrow(A, "0", S). + b. Return A. +---*/ + +var str = 'undefined is not a function'; + +var result = str.split(undefined, 1); + +assert.sameValue(Array.isArray(result), true, '1, result is array'); +assert.sameValue(result.length, 1, '1, result.length'); +assert.sameValue(result[0], str, '1, [0] is the same string'); + +result = str.split(undefined, 2); + +assert.sameValue(Array.isArray(result), true, '2, result is array'); +assert.sameValue(result.length, 1, '2, result.length'); +assert.sameValue(result[0], str, '2, [0] is the same string'); + +result = str.split(undefined, undefined); + +assert.sameValue(Array.isArray(result), true, 'undefined, result is array'); +assert.sameValue(result.length, 1, 'undefined, result.length'); +assert.sameValue(result[0], str, 'undefined, [0] is the same string'); + +result = str.split(undefined, true); + +assert.sameValue(Array.isArray(result), true, 'boolean, result is array'); +assert.sameValue(result.length, 1, 'boolean, result.length'); +assert.sameValue(result[0], str, 'boolean, [0] is the same string'); + +result = str.split(undefined, 2 ** 32 + 1); + +assert.sameValue(Array.isArray(result), true, 'ToUint32 2 ** 32 + 1, result is array'); +assert.sameValue(result.length, 1, 'ToUint32 2 ** 32 + 1, result.length'); +assert.sameValue(result[0], str, 'ToUint32 2 ** 32 + 1, [0] is the same string'); + +result = str.split(undefined, 2 ** 31); + +assert.sameValue(Array.isArray(result), true, 'ToUint32 2 ** 31, result is array'); +assert.sameValue(result.length, 1, 'ToUint32 2 ** 31, result.length'); +assert.sameValue(result[0], str, 'ToUint32 2 ** 31, [0] is the same string'); + +result = str.split(undefined, 2 ** 16); + +assert.sameValue(Array.isArray(result), true, 'ToUint32 2 ** 16, result is array'); +assert.sameValue(result.length, 1, 'ToUint32 2 ** 16, result.length'); +assert.sameValue(result[0], str, 'ToUint32 2 ** 16, [0] is the same string'); + +result = str.split(undefined, {valueOf() { return 1; }}); + +assert.sameValue(Array.isArray(result), true, 'boolean, result is array'); +assert.sameValue(result.length, 1, 'boolean, result.length'); +assert.sameValue(result[0], str, 'boolean, [0] is the same string'); diff --git a/test/built-ins/String/prototype/split/separator-undef-limit-zero.js b/test/built-ins/String/prototype/split/separator-undef-limit-zero.js new file mode 100644 index 0000000000..4bb0593384 --- /dev/null +++ b/test/built-ins/String/prototype/split/separator-undef-limit-zero.js @@ -0,0 +1,64 @@ +// Copyright (C) 2020 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.split +description: Separator is undefined, limit is zero, return a new empty array +info: | + ... + 3. Let S be ? ToString(O). + 4. Let A be ! ArrayCreate(0). + ... + 6. If limit is undefined, let lim be 2**32 - 1; else let lim be ? ToUint32(limit). + 7. Let R be ? ToString(separator). + 8. If lim = 0, return A. + + ToUint32 ( argument ) + + 1. Let number be ? ToNumber(argument). + 2. If number is NaN, +0, -0, +∞, or -∞, return +0. + 3. Let int be the Number value that is the same sign as number and whose magnitude is floor(abs(number)). + 4. Let int32bit be int modulo 232. + 5. Return int32bit. +---*/ + +var str = 'undefined is not a function'; + +var result = str.split(undefined, 0); + +assert.sameValue(Array.isArray(result), true, 'result is array'); +assert.sameValue(result.length, 0, 'result.length'); + +result = str.split(undefined, false); + +assert.sameValue(Array.isArray(result), true, 'boolean, result is array'); +assert.sameValue(result.length, 0, 'boolean, result.length'); + +result = str.split(undefined, null); + +assert.sameValue(Array.isArray(result), true, 'null, result is array'); +assert.sameValue(result.length, 0, 'null, result.length'); + +result = str.split(undefined, {valueOf() { return undefined; }}); + +assert.sameValue(Array.isArray(result), true, 'obj > undefined, result is array'); +assert.sameValue(result.length, 0, 'obj > undefined, result.length'); + +result = str.split(undefined, {valueOf() { return 0; }}); + +assert.sameValue(Array.isArray(result), true, 'obj > 0, result is array'); +assert.sameValue(result.length, 0, 'obj > 0, result.length'); + +result = str.split(undefined, NaN); + +assert.sameValue(Array.isArray(result), true, 'NaN, result is array'); +assert.sameValue(result.length, 0, 'NaN, result.length'); + +result = str.split(undefined, 2 ** 32); + +assert.sameValue(Array.isArray(result), true, '2 ** 32, result is array'); +assert.sameValue(result.length, 0, '2 ** 32, result.length'); + +result = str.split(undefined, 2 ** 33); + +assert.sameValue(Array.isArray(result), true, '2 ** 33, result is array'); +assert.sameValue(result.length, 0, '2 ** 33, result.length'); diff --git a/test/built-ins/String/prototype/split/separator-undef.js b/test/built-ins/String/prototype/split/separator-undef.js new file mode 100644 index 0000000000..2e491b409a --- /dev/null +++ b/test/built-ins/String/prototype/split/separator-undef.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.split +description: Separator is undefined, return a new array with the string +info: | + ... + 3. Let S be ? ToString(O). + 4. Let A be ! ArrayCreate(0). + ... + 6. If limit is undefined, let lim be 232 - 1; else let lim be ? ToUint32(limit). + 7. Let R be ? ToString(separator). + 8. If lim = 0, return A. + 9. If separator is undefined, then + a. Perform ! CreateDataPropertyOrThrow(A, "0", S). + b. Return A. +---*/ + +var str = 'undefined is not a function'; + +var result = str.split(); + +assert.sameValue(Array.isArray(result), true, 'implicit separator, result is array'); +assert.sameValue(result.length, 1, 'implicit separator, result.length'); +assert.sameValue(result[0], str, 'implicit separator, [0] is the same string'); + +result = str.split(undefined); + +assert.sameValue(Array.isArray(result), true, 'explicit separator, result is array'); +assert.sameValue(result.length, 1, 'explicit separator, result.length'); +assert.sameValue(result[0], str, 'explicit separator, [0] is the same string');