Skip to content

Commit 3ab8adc

Browse files
gibson042rwaldron
authored andcommitted
Require String.prototype.localeCompare to check for canonical equivalence
1 parent 3eea1a7 commit 3ab8adc

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

test/built-ins/String/prototype/localeCompare/15.5.4.9_CE.js

+17-25
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
// Copyright 2012 Norbert Lindenberg. All rights reserved.
22
// Copyright 2012 Mozilla Corporation. All rights reserved.
33
// Copyright 2013 Microsoft Corporation. All rights reserved.
4+
// Copyright (C) 2022 Richard Gibson. All rights reserved.
45
// This code is governed by the license found in the LICENSE file.
56

67
/*---
7-
es5id: 15.5.4.9_CE
88
description: >
9-
Tests that String.prototype.localeCompare returns 0 when
10-
comparing Strings that are considered canonically equivalent by
11-
the Unicode standard.
12-
author: Norbert Lindenberg
9+
String.prototype.localeCompare must return 0 when
10+
comparing Strings that are considered canonically equivalent by
11+
the Unicode Standard.
12+
esid: sec-string.prototype.localecompare
13+
info: |
14+
String.prototype.localeCompare ( _that_ [ , _reserved1_ [ , _reserved2_ ] ] )
15+
16+
This function must treat Strings that are canonically equivalent
17+
according to the Unicode standard as identical and must return `0`
18+
when comparing Strings that are considered canonically equivalent.
1319
---*/
1420

1521
// pairs with characters not in Unicode 3.0 are commented out
@@ -49,26 +55,12 @@ var pairs = [
4955
// ["\uD87E\uDC2B", "北"]
5056
];
5157

52-
// Detect whether we are using locale-sensitive comparisons or a bitwise comparison
53-
if ("a".localeCompare("Z") < 0) {
54-
// We are using locale-sensitive comparison, so all pairs should be canonically equivalent
55-
var i;
56-
for (i = 0; i < pairs.length; i++) {
57-
var pair = pairs[i];
58-
if (pair[0].localeCompare(pair[1]) !== 0) {
59-
throw new Test262Error("String.prototype.localeCompare considers " + pair[0] + " (" + toU(pair[0]) +
60-
") ≠ " + pair[1] + " (" + toU(pair[1]) + ").");
61-
}
62-
}
63-
} else {
64-
// We are using bitwise comparison, so all pairs should not be equivalent
65-
var i;
66-
for (i = 0; i < pairs.length; i++) {
67-
var pair = pairs[i];
68-
if (pair[0].localeCompare(pair[1]) === 0) {
69-
throw new Test262Error("String.prototype.localeCompare considers " + pair[0] + " (" + toU(pair[0]) +
70-
") = " + pair[1] + " (" + toU(pair[1]) + ").");
71-
}
58+
var i;
59+
for (i = 0; i < pairs.length; i++) {
60+
var pair = pairs[i];
61+
if (pair[0].localeCompare(pair[1]) !== 0) {
62+
throw new Test262Error("String.prototype.localeCompare considers " + pair[0] + " (" + toU(pair[0]) +
63+
") ≠ " + pair[1] + " (" + toU(pair[1]) + ").");
7264
}
7365
}
7466

0 commit comments

Comments
 (0)