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: 10.1.2_a
|
2014-07-22 01:09:02 +02:00
|
|
|
description: Tests that Intl.Collator 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 collator and have it sort an array for comparison with the subclass
|
|
|
|
var locales = ["tlh", "id", "en"];
|
|
|
|
var a = ["A", "C", "E", "B", "D", "F"];
|
|
|
|
var referenceCollator = new Intl.Collator(locales);
|
|
|
|
var referenceSorted = a.slice().sort(referenceCollator.compare);
|
|
|
|
|
2015-07-08 19:13:31 +02:00
|
|
|
class MyCollator extends Intl.Collator {
|
|
|
|
constructor(locales, options) {
|
|
|
|
super(locales, options);
|
2012-08-27 05:50:24 +02:00
|
|
|
// could initialize MyCollator properties
|
2015-07-08 19:13:31 +02:00
|
|
|
}
|
|
|
|
// could add methods to MyCollator.prototype
|
2012-08-27 05:50:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var collator = new MyCollator(locales);
|
|
|
|
a.sort(collator.compare);
|
2017-12-21 21:08:10 +01:00
|
|
|
assert.compareArray(a, referenceSorted);
|