[gnome-maps/wip/mlundblad/unit-tests: 4/4] WIP: Add unit tests for the utils module



commit 8abdbfefdd1e333aa7a51ad998f916496fa4d959
Author: Marcus Lundblad <ml update uu se>
Date:   Tue Apr 28 23:39:58 2020 +0200

    WIP: Add unit tests for the utils module

 tests/meson.build  |  2 +-
 tests/utilsTest.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 1 deletion(-)
---
diff --git a/tests/meson.build b/tests/meson.build
index d3cf74e9..6276117f 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -4,7 +4,7 @@ script_conf.set('PACKAGE_VERSION', version)
 script_conf.set('libdir', libdir)
 script_conf.set('prefix', prefix)
 
-tests = []
+tests = ['utilsTest']
 
 foreach test : tests
   script_conf.set('name', test)
diff --git a/tests/utilsTest.js b/tests/utilsTest.js
new file mode 100644
index 00000000..3cf3b798
--- /dev/null
+++ b/tests/utilsTest.js
@@ -0,0 +1,66 @@
+/* -*- 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' });
+pkg.initFormat();
+
+const Geocode = imports.gi.GeocodeGlib;
+const GLib = imports.gi.GLib;
+
+// set default C locale for the tests before initing the Utils module
+GLib.setenv('LANG', 'C', true);
+GLib.setenv('LC_ALL', 'C', true);
+
+const JsUnit = imports.jsUnit;
+
+const Utils = imports.utils;
+
+function main() {
+    osmTypeToStringTest();
+    dashedToCamelCaseTest();
+    getAccuracyDescriptionTest();
+}
+
+function osmTypeToStringTest() {
+    JsUnit.assertEquals('OSM type node', 'node',
+                        Utils.osmTypeToString(Geocode.PlaceOsmType.NODE));
+    JsUnit.assertEquals('OSM type way', 'way',
+                        Utils.osmTypeToString(Geocode.PlaceOsmType.WAY));
+    JsUnit.assertEquals('OSM type node', 'relation',
+                        Utils.osmTypeToString(Geocode.PlaceOsmType.RELATION));
+}
+
+function dashedToCamelCaseTest() {
+    JsUnit.assertEquals('foo', Utils.dashedToCamelCase('foo'));
+    JsUnit.assertEquals('fooBar', Utils.dashedToCamelCase('foo-bar'));
+}
+
+function getAccuracyDescriptionTest() {
+    JsUnit.assertEquals('Unknown',
+                        Utils.getAccuracyDescription(Geocode.LOCATION_ACCURACY_UNKNOWN));
+    JsUnit.assertEquals('Exact', Utils.getAccuracyDescription(0));
+    // for other distances, the same as prettyDistance()
+    JsUnit.assertEquals(Utils.prettyDistance(100),
+                        Utils.getAccuracyDescription(100));
+    JsUnit.assertEquals(Utils.prettyDistance(10000),
+                        Utils.getAccuracyDescription(10000));
+} 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]