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