summaryrefslogtreecommitdiff
path: root/test/suite/intl402/ch13/13.2/13.2.1_1.js
diff options
context:
space:
mode:
authorNorbert Lindenberg <ecmascript@lindenbergsoftware.com>2012-08-26 20:50:24 -0700
committerNorbert Lindenberg <ecmascript@lindenbergsoftware.com>2012-08-26 20:50:24 -0700
commit2f88b751bd6eb49bc2ca985e89aea86deb67a1de (patch)
tree79aed459cf2d8f9d26f8e0ece825d5e20b1d4650 /test/suite/intl402/ch13/13.2/13.2.1_1.js
parent02764dfe42d9b70f574fcad9db5210a0336d6d8f (diff)
downloadtest262-2f88b751bd6eb49bc2ca985e89aea86deb67a1de.tar.gz
Added new tests for chapters 10 to 13 of the ECMAScript Internationalization API Specification.
--HG-- rename : test/suite/intl402/ch10/10.3/10.3.js => test/suite/intl402/ch10/10.3/10.3_a.js rename : test/suite/intl402/ch11/11.3/11.3.js => test/suite/intl402/ch11/11.3/11.3_a.js rename : test/suite/intl402/ch12/12.3/12.3.js => test/suite/intl402/ch12/12.3/12.3_a.js
Diffstat (limited to 'test/suite/intl402/ch13/13.2/13.2.1_1.js')
-rw-r--r--test/suite/intl402/ch13/13.2/13.2.1_1.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/suite/intl402/ch13/13.2/13.2.1_1.js b/test/suite/intl402/ch13/13.2/13.2.1_1.js
new file mode 100644
index 000000000..da1ee8fe5
--- /dev/null
+++ b/test/suite/intl402/ch13/13.2/13.2.1_1.js
@@ -0,0 +1,37 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that toLocaleString handles "this Number value" correctly.
+ * @author Norbert Lindenberg
+ */
+
+var invalidValues = [undefined, null, "5", false, {valueOf: function () { return 5; }}];
+var validValues = [5, NaN, -1234567.89, -Infinity];
+
+invalidValues.forEach(function (value) {
+ var error;
+ try {
+ var result = Number.prototype.toLocaleString.call(value);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Number.prototype.toLocaleString did not reject this = " + value + ".");
+ } else if (error.name !== "TypeError") {
+ $ERROR("Number.prototype.toLocaleString rejected this = " + value + " with wrong error " + error.name + ".");
+ }
+});
+
+// for valid values, just check that a Number value and the corresponding
+// Number object get the same result.
+validValues.forEach(function (value) {
+ var Constructor = Number; // to keep jshint happy
+ var valueResult = Number.prototype.toLocaleString.call(value);
+ var objectResult = Number.prototype.toLocaleString.call(new Constructor(value));
+ if (valueResult !== objectResult) {
+ $ERROR("Number.prototype.toLocaleString produces different results for Number value " +
+ value + " and corresponding Number object: " + valueResult + " vs. " + objectResult + ".");
+ }
+});
+