2012-08-27 05:50:24 +02:00
|
|
|
// 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.
|
|
|
|
|
2014-07-22 01:09:02 +02:00
|
|
|
/*---
|
2014-07-25 00:41:42 +02:00
|
|
|
es5id: 11.1.2
|
2014-07-22 01:09:02 +02:00
|
|
|
description: Tests that Intl.NumberFormat can be subclassed.
|
|
|
|
author: Norbert Lindenberg
|
2017-12-21 21:08:10 +01:00
|
|
|
includes: [testIntl.js, compareArray.js]
|
2014-07-22 01:09:02 +02:00
|
|
|
---*/
|
2012-08-27 05:50:24 +02:00
|
|
|
|
|
|
|
// get a number format and have it format an array of numbers for comparison with the subclass
|
|
|
|
var locales = ["tlh", "id", "en"];
|
|
|
|
var a = [0, 1, -1, -123456.789, -Infinity, NaN];
|
|
|
|
var referenceNumberFormat = new Intl.NumberFormat(locales);
|
|
|
|
var referenceFormatted = a.map(referenceNumberFormat.format);
|
|
|
|
|
2015-07-08 19:13:31 +02:00
|
|
|
class MyNumberFormat extends Intl.NumberFormat {
|
|
|
|
constructor(locales, options) {
|
|
|
|
super(locales, options);
|
2012-08-27 05:50:24 +02:00
|
|
|
// could initialize MyNumberFormat properties
|
2015-07-08 19:13:31 +02:00
|
|
|
}
|
|
|
|
// could add methods to MyNumberFormat.prototype
|
2012-08-27 05:50:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var format = new MyNumberFormat(locales);
|
|
|
|
var actual = a.map(format.format);
|
2017-12-21 21:08:10 +01:00
|
|
|
assert.compareArray(actual, referenceFormatted);
|