summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@update.uu.se>2020-11-16 23:38:05 +0100
committerMarcus Lundblad <ml@update.uu.se>2020-11-26 22:04:06 +0100
commit35f1fae01869e0a0da30d3981738a51b891a7791 (patch)
treea6edbc310dc6f47db55bbd4c0e79ffc6f9dc2eb7 /tests
parent4056f0d913708f69a9d4f2b2cd943290d6c9d9e6 (diff)
downloadgnome-maps-35f1fae01869e0a0da30d3981738a51b891a7791.tar.gz
Add unit tests for the OSMNames module
Diffstat (limited to 'tests')
-rw-r--r--tests/meson.build2
-rw-r--r--tests/osmNamesTest.js76
2 files changed, 77 insertions, 1 deletions
diff --git a/tests/meson.build b/tests/meson.build
index 78b7d77e..86475d09 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,4 +1,4 @@
-tests = ['addressTest', 'colorTest', 'utilsTest']
+tests = ['addressTest', 'colorTest', 'osmNamesTest', 'utilsTest']
foreach test : tests
script_conf = configuration_data()
diff --git a/tests/osmNamesTest.js b/tests/osmNamesTest.js
new file mode 100644
index 00000000..172688e8
--- /dev/null
+++ b/tests/osmNamesTest.js
@@ -0,0 +1,76 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2020 Marcus Lundblad
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Marcus Lundblad <ml@update.uu.se>
+ */
+
+pkg.require({ 'Gdk': '3.0',
+ 'Gtk': '3.0' });
+
+const OSMNames = imports.osmNames;
+
+const JsUnit = imports.jsUnit;
+
+const TAGS1 = { 'name': 'Name',
+ 'name:en': 'Name',
+ 'name:de': 'Name',
+ 'name:sv': 'Namn' };
+
+const TAGS2 = { 'int_name': 'Shin-Ōsaka',
+ 'name': '新大阪',
+ 'name:en': 'Shin-Osaka',
+ 'name:ja': '新大阪',
+ 'name:ja_rm': 'Shin Ōsaka',
+ 'name:ko': '신오사카' };
+
+const TAGS3 = { 'int_name': 'Shin-Ōsaka',
+ 'name': '新大阪',
+ 'name:en': 'Shin-Osaka',
+ 'name:ja': '新大阪',
+ 'name:ja-Latn': 'Shin Ōsaka',
+ 'name:ko': '신오사카' };
+
+const TAGS4 = { 'name': 'Uppsala',
+ 'name:de': 'Uppsala',
+ 'name:eo': 'Upsalo',
+ 'name:fi': 'Uppsala',
+ 'name:he': 'אופסלה',
+ 'name:hu': 'Uppsala',
+ 'name:is': 'Uppsalir',
+ 'name:ko': '웁살라',
+ 'name:lt': 'Upsala',
+ 'name:nds': 'Uppsala',
+ 'name:ru': 'Уппсала',
+ 'name:sv': 'Uppsala',
+ 'name:yi': 'אופסאלא'};
+
+function main() {
+ JsUnit.assertEquals('Name in language', 'Namn',
+ OSMNames.getNameForLanguageAndCountry(TAGS1, 'sv', 'GB'));
+ JsUnit.assertEquals('Fallback when language not localized', 'Name',
+ OSMNames.getNameForLanguageAndCountry(TAGS1, 'fi', 'GB'));
+ JsUnit.assertEquals('Legacy Japanese romanization tag', 'Shin Ōsaka',
+ OSMNames.getNameForLanguageAndCountry(TAGS2, 'sv', 'JP'));
+ JsUnit.assertEquals('Japanese romanization tag', 'Shin Ōsaka',
+ OSMNames.getNameForLanguageAndCountry(TAGS3, 'sv', 'JP'));
+ JsUnit.assertEquals('Explicit English', 'Shin-Osaka',
+ OSMNames.getNameForLanguageAndCountry(TAGS3, 'en', 'JP'));
+ JsUnit.assertEquals('Available tag in similar alphabeth', 'Уппсала',
+ OSMNames.getNameForLanguageAndCountry(TAGS4, 'uk', 'SE'));
+}
+