[gjs] tests: Don't assume localeCompare() returns +/-1
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] tests: Don't assume localeCompare() returns +/-1
- Date: Wed, 10 Feb 2016 04:27:47 +0000 (UTC)
commit 1b418af4a18ae0b4d1432311701cfd6e60525bda
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Jan 24 13:47:26 2016 -0800
tests: Don't assume localeCompare() returns +/-1
Per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare,
"DO NOT rely on exact return values of -1 or 1. Negative and positive
integer results vary between browsers (as well as between browser
versions) because the W3C specification only mandates negative and
positive values. Some browsers may return -2 or 2 or even some other
negative or positive value."
And indeed I observed this test fail with a value of -2.
https://bugzilla.gnome.org/show_bug.cgi?id=761072
installed-tests/js/testLocale.js | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/installed-tests/js/testLocale.js b/installed-tests/js/testLocale.js
index b086a66..e50d0c2 100644
--- a/installed-tests/js/testLocale.js
+++ b/installed-tests/js/testLocale.js
@@ -29,9 +29,9 @@ function testToLocaleCompare() {
// GLib calls out to libc for collation, so we can't really
// assume anything - we could even be running in the
// C locale. The below is pretty safe.
- JSUnit.assertEquals(-1, "a".localeCompare("b"));
+ JSUnit.assertTrue("a".localeCompare("b") < 0);
JSUnit.assertEquals( 0, "a".localeCompare("a"));
- JSUnit.assertEquals( 1, "b".localeCompare("a"));
+ JSUnit.assertTrue("b".localeCompare("a") > 0);
// Again test error handling when conversion fails
//assertRaises(function() { "\ud800".localeCompare("a"); });
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]