diff options
Diffstat (limited to 'js/src/tests/test262/intl402/ch11/11.3')
18 files changed, 482 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3.1.js b/js/src/tests/test262/intl402/ch11/11.3/11.3.1.js new file mode 100644 index 000000000..46c7fc519 --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.1.js @@ -0,0 +1,14 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.NumberFormat.prototype.constructor is the + * Intl.NumberFormat. + * @author: Roozbeh Pournader + */ + +if (Intl.NumberFormat.prototype.constructor !== Intl.NumberFormat) { + $ERROR("Intl.NumberFormat.prototype.constructor is not the same as " + + "Intl.NumberFormat"); +} + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3.2_1_a_L15.js b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_1_a_L15.js new file mode 100644 index 000000000..8e1c95835 --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_1_a_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that the function returned by Intl.NumberFormat.prototype.format + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(new Intl.NumberFormat().format, true, false, [], 1); + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3.2_1_a_ii.js b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_1_a_ii.js new file mode 100644 index 000000000..cb284f43e --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_1_a_ii.js @@ -0,0 +1,27 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.NumberFormat.prototype.format + * converts other types to numbers. + * @author: Roozbeh Pournader + */ + +var formatter = new Intl.NumberFormat(); +var testData = [undefined, null, true, '0.6666666', {valueOf: function () { return '0.1234567';}}]; +var number; +var i, input, correctResult, result; + +for (i in testData) { + input = testData[i]; + number = +input; + correctResult = formatter.format(number); + + result = formatter.format(input); + if (result !== correctResult) { + $ERROR('Intl.NumberFormat does not convert other ' + + 'types to numbers. Input: "'+input+'" Output: "'+result+'" '+ + 'Expected output: "'+correctResult+'"'); + } +} + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3.2_1_c.js b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_1_c.js new file mode 100644 index 000000000..3fc877b31 --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_1_c.js @@ -0,0 +1,41 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that format function is bound to its Intl.NumberFormat. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var numbers = [0, -0, 1, -1, 5.5, 123, -123, -123.45, 123.44501, 0.001234, + -0.00000000123, 0.00000000000000000000000000000123, 1.2, 0.0000000012344501, + 123445.01, 12344501000000000000000000000000000, -12344501000000000000000000000000000, + Infinity, -Infinity, NaN]; +var locales = [undefined, ["de"], ["th-u-nu-thai"], ["en"], ["ja-u-nu-jpanfin"], ["ar-u-nu-arab"]]; +var options = [ + undefined, + {style: "percent"}, + {style: "currency", currency: "EUR", currencyDisplay: "symbol"}, + {style: "currency", currency: "IQD", currencyDisplay: "symbol"}, + {style: "currency", currency: "KMF", currencyDisplay: "symbol"}, + {style: "currency", currency: "CLF", currencyDisplay: "symbol"}, + {useGrouping: false, minimumIntegerDigits: 3, minimumFractionDigits: 1, maximumFractionDigits: 3} +]; + +locales.forEach(function (locales) { + options.forEach(function (options) { + var formatObj = new Intl.NumberFormat(locales, options); + var formatFunc = formatObj.format; + numbers.forEach(function (number) { + var referenceFormatted = formatObj.format(number); + var formatted = formatFunc(number); + if (referenceFormatted !== formatted) { + $ERROR("format function produces different result than format method for locales " + + locales + "; options: " + (options ? JSON.stringify(options) : options) + + " : " + formatted + " vs. " + referenceFormatted + "."); + } + }); + }); +}); + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3.2_FN_1.js b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_FN_1.js new file mode 100644 index 000000000..5f14e7772 --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_FN_1.js @@ -0,0 +1,19 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.NumberFormat.prototype.format + * doesn't treat all numbers as negative. + * @author: Roozbeh Pournader + */ + +var formatter = new Intl.NumberFormat(); + +if (formatter.format(1) === formatter.format(-1)) { + $ERROR('Intl.NumberFormat is formatting 1 and -1 the same way.'); +} + +if (formatter.format(-0) !== formatter.format(0)) { + $ERROR('Intl.NumberFormat is formatting signed zeros differently.'); +} + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3.2_FN_2.js b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_FN_2.js new file mode 100644 index 000000000..ec11a679d --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_FN_2.js @@ -0,0 +1,59 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.NumberFormat.prototype.format + * handles NaN, Infinity, and -Infinity properly. + * @author: Roozbeh Pournader + */ + +// FIXME: We are only listing Numeric_Type=Decimal. May need to add more +// when the spec clarifies. Current as of Unicode 6.1. +var hasUnicodeDigits = new RegExp('.*([' + + '0-9\u0660-\u0669\u06F0-\u06F9\u07C0-\u07C9\u0966-\u096F' + + '\u09E6-\u09EF\u0A66-\u0A6F\u0AE6-\u0AEF\u0B66-\u0B6F\u0BE6-\u0BEF' + + '\u0C66-\u0C6F\u0CE6-\u0CEF\u0D66-\u0D6F\u0E50-\u0E59\u0ED0-\u0ED9' + + '\u0F20-\u0F29\u1040-\u1049\u1090-\u1099\u17E0-\u17E9\u1810-\u1819' + + '\u1946-\u194F\u19D0-\u19D9\u1A80-\u1A89\u1A90-\u1A99\u1B50-\u1B59' + + '\u1BB0-\u1BB9\u1C40-\u1C49\u1C50-\u1C59\uA620-\uA629\uA8D0-\uA8D9' + + '\uA900-\uA909\uA9D0-\uA9D9\uAA50-\uAA59\uABF0-\uABF9\uFF10-\uFF19' + + ']|' + + '\uD801[\uDCA0-\uDCA9]|' + + '\uD804[\uDC66-\uDC6F\uDCF0-\uDCF9\uDD36-\uDD3F\uDDD0-\uDDD9]|' + + '\uD805[\uDEC0-\uDEC9]|' + + '\uD835[\uDFCE-\uDFFF])'); + +var formatter = new Intl.NumberFormat(); +var formattedNaN = formatter.format(NaN); +var formattedInfinity = formatter.format(Infinity); +var formattedNegativeInfinity = formatter.format(-Infinity); + +if (formattedNaN === formattedInfinity) { + $ERROR('Intl.NumberFormat formats NaN and Infinity the ' + + 'same way.'); +} + +if (formattedNaN === formattedNegativeInfinity) { + $ERROR('Intl.NumberFormat formats NaN and negative ' + + 'Infinity the same way.'); +} + +if (formattedInfinity === formattedNegativeInfinity) { + $ERROR('Intl.NumberFormat formats Infinity and ' + + 'negative Infinity the same way.'); +} + +if (hasUnicodeDigits.test(formattedNaN)) { + $ERROR('Intl.NumberFormat formats NaN using a digit.'); +} + +if (hasUnicodeDigits.test(formattedInfinity)) { + $ERROR('Intl.NumberFormat formats Infinity using a ' + + 'digit.'); +} + +if (hasUnicodeDigits.test(formattedNegativeInfinity)) { + $ERROR('Intl.NumberFormat formats negative Infinity ' + + 'using a digit.'); +} + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3.2_FN_3_b.js b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_FN_3_b.js new file mode 100644 index 000000000..efe15575d --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_FN_3_b.js @@ -0,0 +1,27 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.NumberFormat.prototype.format + * formats percent values properly. + * @author: Roozbeh Pournader + */ + +var numberFormatter = new Intl.NumberFormat(); +var percentFormatter = new Intl.NumberFormat(undefined, {style: 'percent'}); + +var formattedTwenty = numberFormatter.format(20); +var formattedTwentyPercent = percentFormatter.format(0.20); + +// FIXME: May not work for some theoretical locales where percents and +// normal numbers are formatted using different numbering systems. +if (formattedTwentyPercent.indexOf(formattedTwenty) === -1) { + $ERROR("Intl.NumberFormat's formatting of 20% does not include a " + + "formatting of 20 as a substring."); +} + +// FIXME: Move this to somewhere appropriate +if (percentFormatter.format(0.011) === percentFormatter.format(0.02)) { + $ERROR('Intl.NumberFormat is formatting 1.1% and 2% the same way.'); +} + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3.2_FN_3_e.js b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_FN_3_e.js new file mode 100644 index 000000000..234ae6325 --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_FN_3_e.js @@ -0,0 +1,47 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.NumberFormat.prototype.format + * supports all alternative numbering systems. + * @author: Roozbeh Pournader + */ + +var numberingSystems = { + arab: 0x0660, + arabext: 0x06F0, + beng: 0x09E6, + deva: 0x0966, + fullwide: 0xFF10, + gujr: 0x0AE6, + guru: 0x0A66, + hanidec: [0x3007, 0x4E00, 0x4E8C, 0x4E09, 0x56DB, + 0x4E94, 0x516D, 0x4E03, 0x516B, 0x4E5D], + khmr: 0x17E0, + knda: 0x0CE6, + laoo: 0x0ED0, + latn: 0x0030, + mlym: 0x0D66, + mong: 0x1810, + mymr: 0x1040, + orya: 0x0B66, + tamldec: 0x0BE6, + telu: 0x0C66, + thai: 0x0E50, + tibt: 0x0F20 +}; + +var options, formatter; +var s, zeroCode, digitList; + +for (s in numberingSystems) { + zeroCode = numberingSystems[s]; + if (typeof zeroCode === 'number') { + digitList = [zeroCode, zeroCode+1, zeroCode+2, zeroCode+3, zeroCode+4, + zeroCode+5, zeroCode+6, zeroCode+7, zeroCode+8, zeroCode+9]; + numberingSystems[s] = digitList; + } +} + +// FIXME: Unfinished + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3.2_L15.js b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_L15.js new file mode 100644 index 000000000..17b688b7a --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that the getter for Intl.NumberFormat.prototype.format + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Object.getOwnPropertyDescriptor(Intl.NumberFormat.prototype, "format").get , true, false, [], 0); + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3.2_TRF.js b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_TRF.js new file mode 100644 index 000000000..c042a318a --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_TRF.js @@ -0,0 +1,56 @@ +// Copyright 2011-2012 Norbert Lindenberg. All rights reserved. +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the digits are determined correctly when specifying pre/post decimal digits. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var locales = [ + new Intl.NumberFormat().resolvedOptions().locale, + "ar", "de", "th", "ja" +]; +var numberingSystems = [ + "arab", + "latn", + "thai", + "hanidec" +]; +var testData = { + "0": "000.0", + "-0": "000.0", + "123": "123.0", + "-123": "-123.0", + "12345": "12345.0", + "-12345": "-12345.0", + "123.45": "123.45", + "-123.45": "-123.45", + "123.444499": "123.444", + "-123.444499": "-123.444", + "123.444500": "123.445", + "-123.444500": "-123.445", + "123.44501": "123.445", + "-123.44501": "-123.445", + "0.001234": "000.001", + "-0.001234": "-000.001", + "0.00000000123": "000.0", + "-0.00000000123": "-000.0", + "0.00000000000000000000000000000123": "000.0", + "-0.00000000000000000000000000000123": "-000.0", + "1.2": "001.2", + "-1.2": "-001.2", + "0.0000000012344501": "000.0", + "-0.0000000012344501": "-000.0", + "123445.01": "123445.01", + "-123445.01": "-123445.01", + "12344501000000000000000000000000000": "12344501000000000000000000000000000.0", + "-12344501000000000000000000000000000": "-12344501000000000000000000000000000.0" +}; + +testNumberFormat(locales, numberingSystems, + {useGrouping: false, minimumIntegerDigits: 3, minimumFractionDigits: 1, maximumFractionDigits: 3}, + testData); + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3.2_TRP.js b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_TRP.js new file mode 100644 index 000000000..9ab6550b6 --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.2_TRP.js @@ -0,0 +1,56 @@ +// Copyright 2011-2012 Norbert Lindenberg. All rights reserved. +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the digits are determined correctly when specifying significant digits. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var locales = [ + new Intl.NumberFormat().resolvedOptions().locale, + "ar", "de", "th", "ja" +]; +var numberingSystems = [ + "arab", + "latn", + "thai", + "hanidec" +]; +var testData = { + "0": "0.00", + "-0": "0.00", + "123": "123", + "-123": "-123", + "12345": "12345", + "-12345": "-12345", + "123.45": "123.45", + "-123.45": "-123.45", + "123.44499": "123.44", + "-123.44499": "-123.44", + "123.44500": "123.45", + "-123.44500": "-123.45", + "123.44501": "123.45", + "-123.44501": "-123.45", + "0.001234": "0.001234", + "-0.001234": "-0.001234", + "0.00000000123": "0.00000000123", + "-0.00000000123": "-0.00000000123", + "0.00000000000000000000000000000123": "0.00000000000000000000000000000123", + "-0.00000000000000000000000000000123": "-0.00000000000000000000000000000123", + "1.2": "1.20", + "-1.2": "-1.20", + "0.0000000012344501": "0.0000000012345", + "-0.0000000012344501": "-0.0000000012345", + "123445.01": "123450", + "-123445.01": "-123450", + "12344501000000000000000000000000000": "12345000000000000000000000000000000", + "-12344501000000000000000000000000000": "-12345000000000000000000000000000000" +}; + +testNumberFormat(locales, numberingSystems, + {useGrouping: false, minimumSignificantDigits: 3, maximumSignificantDigits: 5}, + testData); + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3.3.js b/js/src/tests/test262/intl402/ch11/11.3/11.3.3.js new file mode 100644 index 000000000..5a220ccc9 --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.3.js @@ -0,0 +1,31 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that the object returned by Intl.NumberFormat.prototype.resolvedOptions + * has the right properties. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var actual = new Intl.NumberFormat().resolvedOptions(); + +var actual2 = new Intl.NumberFormat().resolvedOptions(); +if (actual2 === actual) { + $ERROR("resolvedOptions returned the same object twice."); +} + +// this assumes the default values where the specification provides them +mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag); +mustHaveProperty(actual, "numberingSystem", isValidNumberingSystem); +mustHaveProperty(actual, "style", ["decimal"]); +mustNotHaveProperty(actual, "currency"); +mustNotHaveProperty(actual, "currencyDisplay"); +mustHaveProperty(actual, "minimumIntegerDigits", [1]); +mustHaveProperty(actual, "minimumFractionDigits", [0]); +mustHaveProperty(actual, "maximumFractionDigits", [3]); +mustNotHaveProperty(actual, "minimumSignificantDigits"); +mustNotHaveProperty(actual, "maximumSignificantDigits"); +mustHaveProperty(actual, "useGrouping", [true]); + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3.3_L15.js b/js/src/tests/test262/intl402/ch11/11.3/11.3.3_L15.js new file mode 100644 index 000000000..b9f95866d --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3.3_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Intl.NumberFormat.prototype.resolvedOptions + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Intl.NumberFormat.prototype.resolvedOptions, true, false, [], 0); + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3_L15.js b/js/src/tests/test262/intl402/ch11/11.3/11.3_L15.js new file mode 100644 index 000000000..ac1f0c05d --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Intl.NumberFormat.prototype + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Intl.NumberFormat.prototype, false, false, ["constructor", "format", "resolvedOptions"]); + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3_a.js b/js/src/tests/test262/intl402/ch11/11.3/11.3_a.js new file mode 100644 index 000000000..282a10bf6 --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3_a.js @@ -0,0 +1,16 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.NumberFormat.prototype is an object that + * has been initialized as an Intl.NumberFormat. + * @author: Roozbeh Pournader + */ + +// test by calling a function that would fail if "this" were not an object +// initialized as an Intl.NumberFormat +if (typeof Intl.NumberFormat.prototype.format(0) !== "string") { + $ERROR("Intl.NumberFormat's prototype is not an object that has been " + + "initialized as an Intl.NumberFormat"); +} + diff --git a/js/src/tests/test262/intl402/ch11/11.3/11.3_b.js b/js/src/tests/test262/intl402/ch11/11.3/11.3_b.js new file mode 100644 index 000000000..6d0162b1d --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/11.3_b.js @@ -0,0 +1,33 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.NumberFormat.prototype functions throw a + * TypeError if called on a non-object value or an object that hasn't been + * initialized as a NumberFormat. + * @author Norbert Lindenberg + */ + +var functions = { + "format getter": Object.getOwnPropertyDescriptor(Intl.NumberFormat.prototype, "format").get, + resolvedOptions: Intl.NumberFormat.prototype.resolvedOptions +}; +var invalidTargets = [undefined, null, true, 0, "NumberFormat", [], {}]; + +Object.getOwnPropertyNames(functions).forEach(function (functionName) { + var f = functions[functionName]; + invalidTargets.forEach(function (target) { + var error; + try { + f.call(target); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Calling " + functionName + " on " + target + " was not rejected."); + } else if (error.name !== "TypeError") { + $ERROR("Calling " + functionName + " on " + target + " was rejected with wrong error " + error.name + "."); + } + }); +}); + diff --git a/js/src/tests/test262/intl402/ch11/11.3/browser.js b/js/src/tests/test262/intl402/ch11/11.3/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/browser.js diff --git a/js/src/tests/test262/intl402/ch11/11.3/shell.js b/js/src/tests/test262/intl402/ch11/11.3/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch11/11.3/shell.js |