diff options
Diffstat (limited to 'test/suite/intl402/ch13/13.2/13.2.1_4.js')
-rw-r--r-- | test/suite/intl402/ch13/13.2/13.2.1_4.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/suite/intl402/ch13/13.2/13.2.1_4.js b/test/suite/intl402/ch13/13.2/13.2.1_4.js new file mode 100644 index 000000000..e6e0b1163 --- /dev/null +++ b/test/suite/intl402/ch13/13.2/13.2.1_4.js @@ -0,0 +1,67 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Number.prototype.toLocaleString throws the same exceptions as Intl.NumberFormat. + * @author Norbert Lindenberg + */ + +var locales = [null, [NaN], ["i"], ["de_DE"]]; +var options = [ + {localeMatcher: null}, + {style: "invalid"}, + {style: "currency"}, + {style: "currency", currency: "ßP"}, + {maximumSignificantDigits: -Infinity} +]; + +locales.forEach(function (locales) { + var referenceError, error; + try { + var format = new Intl.NumberFormat(locales); + } catch (e) { + referenceError = e; + } + if (referenceError === undefined) { + $ERROR("Internal error: Expected exception was not thrown by Intl.NumberFormat for locales " + locales + "."); + } + + try { + var result = (0).toLocaleString(locales); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Number.prototype.toLocaleString didn't throw exception for locales " + locales + "."); + } else if (error.name !== referenceError.name) { + $ERROR("Number.prototype.toLocaleString threw exception " + error.name + + " for locales " + locales + "; expected " + referenceError.name + "."); + } +}); + +options.forEach(function (options) { + var referenceError, error; + try { + var format = new Intl.NumberFormat([], options); + } catch (e) { + referenceError = e; + } + if (referenceError === undefined) { + $ERROR("Internal error: Expected exception was not thrown by Intl.NumberFormat for options " + + JSON.stringify(options) + "."); + } + + try { + var result = (0).toLocaleString([], options); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Number.prototype.toLocaleString didn't throw exception for options " + + JSON.stringify(options) + "."); + } else if (error.name !== referenceError.name) { + $ERROR("Number.prototype.toLocaleString threw exception " + error.name + + " for options " + JSON.stringify(options) + "; expected " + referenceError.name + "."); + } +}); + |