summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Math/trunc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/Math/trunc
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Math/trunc')
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/Math.trunc_Infinity.js13
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/Math.trunc_NaN.js12
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/Math.trunc_NegDecimal.js12
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/Math.trunc_PosDecimal.js12
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/Math.trunc_Success.js12
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/Math.trunc_Zero.js12
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/length.js27
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/name.js28
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/not-a-constructor.js31
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/prop-desc.js14
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/shell.js24
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/trunc-sampleTests.js49
-rw-r--r--js/src/tests/test262/built-ins/Math/trunc/trunc-specialVals.js18
14 files changed, 264 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_Infinity.js b/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_Infinity.js
new file mode 100644
index 0000000000..283ede8ae0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_Infinity.js
@@ -0,0 +1,13 @@
+// Copyright (c) 2014 Ryan Lewis. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es6id: 20.2.2.35
+author: Ryan Lewis
+description: Return arg when called with Infinity or -Infinity.
+---*/
+
+assert.sameValue(Math.trunc(Infinity), Infinity, 'Math.trunc(Infinity)');
+assert.sameValue(Math.trunc(-Infinity), -Infinity, 'Math.trunc(-Infinity)');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_NaN.js b/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_NaN.js
new file mode 100644
index 0000000000..be3598e4f3
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_NaN.js
@@ -0,0 +1,12 @@
+// Copyright (c) 2014 Ryan Lewis. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es6id: 20.2.2.35
+author: Ryan Lewis
+description: Math.trunc should return NaN when called with NaN.
+---*/
+
+assert.sameValue(Math.trunc(NaN), NaN);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_NegDecimal.js b/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_NegDecimal.js
new file mode 100644
index 0000000000..1543bdeefd
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_NegDecimal.js
@@ -0,0 +1,12 @@
+// Copyright (c) 2014 Ryan Lewis. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es6id: 20.2.2.35
+author: Ryan Lewis
+description: Math.trunc should return -0 if called with a value between 0 and -1.
+---*/
+
+assert.sameValue(Math.trunc(-.9), -0, 'Math.trunc(-.9)');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_PosDecimal.js b/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_PosDecimal.js
new file mode 100644
index 0000000000..4a5ec1db63
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_PosDecimal.js
@@ -0,0 +1,12 @@
+// Copyright (c) 2014 Ryan Lewis. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es6id: 20.2.2.35
+author: Ryan Lewis
+description: Math.trunc should return 0 if called with a value between 0 and 1.
+---*/
+
+assert.sameValue(Math.trunc(.9), 0, 'Math.trunc(.9)');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_Success.js b/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_Success.js
new file mode 100644
index 0000000000..24f2eaa38a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_Success.js
@@ -0,0 +1,12 @@
+// Copyright (c) 2014 Ryan Lewis. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es6id: 20.2.2.35
+author: Ryan Lewis
+description: Math.trunc should return 4578 if called with 4578.584949
+---*/
+
+assert.sameValue(Math.trunc(4578.584949), 4578, 'Math.trunc(4578.584949)');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_Zero.js b/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_Zero.js
new file mode 100644
index 0000000000..87e4068b6c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/Math.trunc_Zero.js
@@ -0,0 +1,12 @@
+// Copyright (c) 2014 Ryan Lewis. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es6id: 20.2.2.35
+author: Ryan Lewis
+description: Math.trunc should return 0 when called with 0.
+---*/
+
+assert.sameValue(Math.trunc(0), 0, 'Math.trunc(0)');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Math/trunc/browser.js b/js/src/tests/test262/built-ins/Math/trunc/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/browser.js
diff --git a/js/src/tests/test262/built-ins/Math/trunc/length.js b/js/src/tests/test262/built-ins/Math/trunc/length.js
new file mode 100644
index 0000000000..593f893d82
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/length.js
@@ -0,0 +1,27 @@
+// Copyright 2015 Microsoft Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+description: length property of Math.trunc
+es6id: 20.2.2.35
+info: |
+ Math.trunc ( x )
+
+ 17 ECMAScript Standard Built-in Objects:
+ Every built-in Function object, including constructors, that is not
+ identified as an anonymous function has a name property whose value
+ is a String.
+
+ Unless otherwise specified, the name property of a built-in Function
+ object, if it exists, has the attributes { [[Writable]]: false,
+ [[Enumerable]]: false, [[Configurable]]: true }.
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(Math.trunc.length, 1);
+
+verifyNotEnumerable(Math.trunc, "length");
+verifyNotWritable(Math.trunc, "length");
+verifyConfigurable(Math.trunc, "length");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Math/trunc/name.js b/js/src/tests/test262/built-ins/Math/trunc/name.js
new file mode 100644
index 0000000000..25f8a0cc3c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/name.js
@@ -0,0 +1,28 @@
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+es6id: 20.2.2.35
+description: >
+ Math.trunc.name is "trunc".
+info: |
+ Math.trunc ( x )
+
+ 17 ECMAScript Standard Built-in Objects:
+ Every built-in Function object, including constructors, that is not
+ identified as an anonymous function has a name property whose value
+ is a String.
+
+ Unless otherwise specified, the name property of a built-in Function
+ object, if it exists, has the attributes { [[Writable]]: false,
+ [[Enumerable]]: false, [[Configurable]]: true }.
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(Math.trunc.name, "trunc");
+
+verifyNotEnumerable(Math.trunc, "name");
+verifyNotWritable(Math.trunc, "name");
+verifyConfigurable(Math.trunc, "name");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Math/trunc/not-a-constructor.js b/js/src/tests/test262/built-ins/Math/trunc/not-a-constructor.js
new file mode 100644
index 0000000000..1a55c671b4
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/not-a-constructor.js
@@ -0,0 +1,31 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-ecmascript-standard-built-in-objects
+description: >
+ Math.trunc does not implement [[Construct]], is not new-able
+info: |
+ ECMAScript Function Objects
+
+ Built-in function objects that are not identified as constructors do not
+ implement the [[Construct]] internal method unless otherwise specified in
+ the description of a particular function.
+
+ sec-evaluatenew
+
+ ...
+ 7. If IsConstructor(constructor) is false, throw a TypeError exception.
+ ...
+includes: [isConstructor.js]
+features: [Reflect.construct, arrow-function]
+---*/
+
+assert.sameValue(isConstructor(Math.trunc), false, 'isConstructor(Math.trunc) must return false');
+
+assert.throws(TypeError, () => {
+ new Math.trunc();
+}, '`new Math.trunc()` throws TypeError');
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Math/trunc/prop-desc.js b/js/src/tests/test262/built-ins/Math/trunc/prop-desc.js
new file mode 100644
index 0000000000..a6734854fe
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/prop-desc.js
@@ -0,0 +1,14 @@
+// Copyright 2015 Microsoft Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+description: Testing descriptor property of Math.trunc
+includes: [propertyHelper.js]
+es6id: 20.2.2.35
+---*/
+
+verifyNotEnumerable(Math, "trunc");
+verifyWritable(Math, "trunc");
+verifyConfigurable(Math, "trunc");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Math/trunc/shell.js b/js/src/tests/test262/built-ins/Math/trunc/shell.js
new file mode 100644
index 0000000000..eda1477282
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/shell.js
@@ -0,0 +1,24 @@
+// GENERATED, DO NOT EDIT
+// file: isConstructor.js
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: |
+ Test if a given function is a constructor function.
+defines: [isConstructor]
+features: [Reflect.construct]
+---*/
+
+function isConstructor(f) {
+ if (typeof f !== "function") {
+ throw new Test262Error("isConstructor invoked with a non-function value");
+ }
+
+ try {
+ Reflect.construct(function(){}, [], f);
+ } catch (e) {
+ return false;
+ }
+ return true;
+}
diff --git a/js/src/tests/test262/built-ins/Math/trunc/trunc-sampleTests.js b/js/src/tests/test262/built-ins/Math/trunc/trunc-sampleTests.js
new file mode 100644
index 0000000000..70da243d80
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/trunc-sampleTests.js
@@ -0,0 +1,49 @@
+// Copyright 2015 Microsoft Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+description: sample tests for trunc
+es6id: 20.2.2.35
+---*/
+
+assert.sameValue(1 / Math.trunc(0.02047410048544407), Number.POSITIVE_INFINITY,
+ "Math.trunc should produce +0 for values between 0 and 1");
+assert.sameValue(1 / Math.trunc(0.00000000000000001), Number.POSITIVE_INFINITY,
+ "Math.trunc should produce +0 for values between 0 and 1");
+assert.sameValue(1 / Math.trunc(0.9999999999999999), Number.POSITIVE_INFINITY,
+ "Math.trunc should produce +0 for values between 0 and 1");
+assert.sameValue(1 / Math.trunc(Number.EPSILON), Number.POSITIVE_INFINITY,
+ "Math.trunc should produce +0 for values between 0 and 1");
+assert.sameValue(1 / Math.trunc(Number.MIN_VALUE), Number.POSITIVE_INFINITY,
+ "Math.trunc should produce +0 for values between 0 and 1");
+
+assert.sameValue(1 / Math.trunc(-0.02047410048544407), Number.NEGATIVE_INFINITY,
+ "Math.trunc should produce -0 for values between -1 and 0");
+assert.sameValue(1 / Math.trunc(-0.00000000000000001), Number.NEGATIVE_INFINITY,
+ "Math.trunc should produce -0 for values between -1 and 0");
+assert.sameValue(1 / Math.trunc(-0.9999999999999999), Number.NEGATIVE_INFINITY,
+ "Math.trunc should produce -0 for values between -1 and 0");
+assert.sameValue(1 / Math.trunc(-Number.EPSILON), Number.NEGATIVE_INFINITY,
+ "Math.trunc should produce -0 for values between -1 and 0");
+assert.sameValue(1 / Math.trunc(-Number.MIN_VALUE), Number.NEGATIVE_INFINITY,
+ "Math.trunc should produce -0 for values between -1 and 0");
+
+assert.sameValue(Math.trunc(Number.MAX_VALUE), Math.floor(Number.MAX_VALUE),
+ "Math.trunc produces incorrect result for Number.MAX_VALUE");
+assert.sameValue(Math.trunc(10), Math.floor(10),
+ "Math.trunc produces incorrect result for 10");
+assert.sameValue(Math.trunc(3.9), Math.floor(3.9),
+ "Math.trunc produces incorrect result for 3.9");
+assert.sameValue(Math.trunc(4.9), Math.floor(4.9),
+ "Math.trunc produces incorrect result for 4.9");
+
+assert.sameValue(Math.trunc(-Number.MAX_VALUE), Math.ceil(-Number.MAX_VALUE),
+ "Math.trunc produces incorrect result for -Number.MAX_VALUE");
+assert.sameValue(Math.trunc(-10), Math.ceil(-10),
+ "Math.trunc produces incorrect result for -10");
+assert.sameValue(Math.trunc(-3.9), Math.ceil(-3.9),
+ "Math.trunc produces incorrect result for -3.9");
+assert.sameValue(Math.trunc(-4.9), Math.ceil(-4.9),
+ "Math.trunc produces incorrect result for -4.9");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Math/trunc/trunc-specialVals.js b/js/src/tests/test262/built-ins/Math/trunc/trunc-specialVals.js
new file mode 100644
index 0000000000..7e6c8c1051
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Math/trunc/trunc-specialVals.js
@@ -0,0 +1,18 @@
+// Copyright 2015 Microsoft Corporation. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+description: Math.trunc with sample values.
+es6id: 20.2.2.35
+---*/
+
+assert.sameValue(Math.trunc(Number.NEGATIVE_INFINITY), Number.NEGATIVE_INFINITY,
+ "Math.trunc should produce negative infinity for Number.NEGATIVE_INFINITY");
+assert.sameValue(Math.trunc(Number.POSITIVE_INFINITY), Number.POSITIVE_INFINITY,
+ "Math.trunc should produce positive infinity for Number.POSITIVE_INFINITY");
+assert.sameValue(1 / Math.trunc(-0), Number.NEGATIVE_INFINITY,
+ "Math.trunc should produce -0 for -0");
+assert.sameValue(1 / Math.trunc(0), Number.POSITIVE_INFINITY,
+ "Math.trunc should produce +0 for +0");
+
+reportCompare(0, 0);