summaryrefslogtreecommitdiff
path: root/test/suite/intl402/ch13/13.1/13.1.1_6.js
blob: 30607d3171642304be83122ce85d7430ffdbe3ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2012 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/**
 * @description Tests that String.prototype.localeCompare throws the same exceptions as Intl.Collator.
 * @author Norbert Lindenberg
 */

var locales = [null, [NaN], ["i"], ["de_DE"]];
var options = [
    {localeMatcher: null},
    {usage: "invalid"},
    {sensitivity: "invalid"}
];

locales.forEach(function (locales) {
    var referenceError, error;
    try {
        var collator = new Intl.Collator(locales);
    } catch (e) {
        referenceError = e;
    }
    if (referenceError === undefined) {
        $ERROR("Internal error: Expected exception was not thrown by Intl.Collator for locales " + locales + ".");
    }
    
    try {
        var result = "".localeCompare("", locales);
    } catch (e) {
        error = e;
    }
    if (error === undefined) {
        $ERROR("String.prototype.localeCompare didn't throw exception for locales " + locales + ".");
    } else if (error.name !== referenceError.name) {
        $ERROR("String.prototype.localeCompare threw exception " + error.name +
            " for locales " + locales + "; expected " + referenceError.name + ".");
    }
});

options.forEach(function (options) {
    var referenceError, error;
    try {
        var collator = new Intl.Collator([], options);
    } catch (e) {
        referenceError = e;
    }
    if (referenceError === undefined) {
        $ERROR("Internal error: Expected exception was not thrown by Intl.Collator for options " +
            JSON.stringify(options) + ".");
    }
    
    try {
        var result = "".localeCompare("", [], options);
    } catch (e) {
        error = e;
    }
    if (error === undefined) {
        $ERROR("String.prototype.localeCompare didn't throw exception for options " +
            JSON.stringify(options) + ".");
    } else if (error.name !== referenceError.name) {
        $ERROR("String.prototype.localeCompare threw exception " + error.name +
            " for options " + JSON.stringify(options) + "; expected " + referenceError.name + ".");
    }
});