• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15var str1 = "ab";
16var str2 = "cd";
17assert (str1.localeCompare(str1) === 0);
18assert (str1.localeCompare(str2) === -1);
19assert (str2.localeCompare(str1) === 1);
20
21var x = "32";
22var y = "-32";
23assert (y.localeCompare(-31) === 1);
24assert (y.localeCompare("") === 1);
25assert (y.localeCompare(-32) === 0);
26assert (x.localeCompare(33) === -1);
27assert (x.localeCompare() === -1);
28assert (x.localeCompare(null) === -1);
29assert (x.localeCompare(NaN) === -1);
30assert (x.localeCompare(Infinity) === -1);
31assert (x.localeCompare(-Infinity) === 1);
32
33var array1 = ["1", 2];
34var array2 = [3, 4];
35assert (String.prototype.localeCompare.call(42, array1) === 1);
36assert (String.prototype.localeCompare.call(array1, null) === -1);
37assert (String.prototype.localeCompare.call(array1, array1) === 0);
38assert (String.prototype.localeCompare.call(array1, array2) === -1);
39assert (String.prototype.localeCompare.call(array2, array1) === 1);
40
41try {
42  var res = String.prototype.localeCompare.call(null, 0);
43  assert (false);
44} catch (e) {
45  assert (e instanceof TypeError);
46}
47
48try {
49  var res = String.prototype.localeCompare.call();
50  assert (false);
51} catch (e) {
52  assert (e instanceof TypeError);
53}
54