diff tests/test-jsapi-unicode.c @ 963:371e1cc2c697

tests: add 80% of the Javascript API
author David Demelier <markand@malikania.fr>
date Thu, 28 Jan 2021 14:20:58 +0100
parents
children a518664b20a0
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-jsapi-unicode.c	Thu Jan 28 14:20:58 2021 +0100
@@ -0,0 +1,116 @@
+/*
+ * test-jsapi-unicode.c -- test Irccd.Unicode API
+ *
+ * Copyright (c) 2013-2021 David Demelier <markand@malikania.fr>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * /!\ Be sure that this file is kept saved in UTF-8 /!\
+ */
+
+#define GREATEST_USE_ABBREVS 0
+#include <greatest.h>
+
+// TODO: irccd/
+#include <config.h>
+
+#include <irccd/js-plugin.h>
+#include <irccd/plugin.h>
+
+static struct irc_plugin *plugin;
+static struct irc_js_plugin_data *data;
+
+static void
+setup(void *udata)
+{
+	(void)udata;
+
+	plugin = irc_js_plugin_open(SOURCE "/data/example-plugin.js");
+	data = plugin->data;
+}
+
+static void
+teardown(void *udata)
+{
+	(void)udata;
+
+	irc_plugin_finish(plugin);
+
+	plugin = NULL;
+	data = NULL;
+}
+
+GREATEST_TEST
+basics_is_letter(void)
+{
+	duk_peval_string_noresult(data->ctx, "result = Irccd.Unicode.isLetter(String('é').charCodeAt(0));");
+	GREATEST_ASSERT(duk_get_global_string(data->ctx, "result"));
+	GREATEST_ASSERT(duk_get_boolean(data->ctx, -1));
+
+	duk_peval_string_noresult(data->ctx, "result = Irccd.Unicode.isLetter(String('€').charCodeAt(0));");
+	GREATEST_ASSERT(duk_get_global_string(data->ctx, "result"));
+	GREATEST_ASSERT(!duk_get_boolean(data->ctx, -1));
+
+	GREATEST_PASS();
+}
+
+GREATEST_TEST
+basics_is_lower(void)
+{
+	duk_peval_string_noresult(data->ctx, "result = Irccd.Unicode.isLower(String('é').charCodeAt(0));");
+	GREATEST_ASSERT(duk_get_global_string(data->ctx, "result"));
+	GREATEST_ASSERT(duk_get_boolean(data->ctx, -1));
+
+	duk_peval_string_noresult(data->ctx, "result = Irccd.Unicode.isLower(String('É').charCodeAt(0));");
+	GREATEST_ASSERT(duk_get_global_string(data->ctx, "result"));
+	GREATEST_ASSERT(!duk_get_boolean(data->ctx, -1));
+
+	GREATEST_PASS();
+}
+
+GREATEST_TEST
+basics_is_upper(void)
+{
+	duk_peval_string_noresult(data->ctx, "result = Irccd.Unicode.isUpper(String('É').charCodeAt(0));");
+	GREATEST_ASSERT(duk_get_global_string(data->ctx, "result"));
+	GREATEST_ASSERT(duk_get_boolean(data->ctx, -1));
+
+	duk_peval_string_noresult(data->ctx, "result = Irccd.Unicode.isUpper(String('é').charCodeAt(0));");
+	GREATEST_ASSERT(duk_get_global_string(data->ctx, "result"));
+	GREATEST_ASSERT(!duk_get_boolean(data->ctx, -1));
+
+	GREATEST_PASS();
+}
+
+GREATEST_SUITE(suite_basics)
+{
+	GREATEST_SET_SETUP_CB(setup, NULL);
+	GREATEST_SET_TEARDOWN_CB(teardown, NULL);
+	GREATEST_RUN_TEST(basics_is_letter);
+	GREATEST_RUN_TEST(basics_is_lower);
+	GREATEST_RUN_TEST(basics_is_upper);
+}
+
+GREATEST_MAIN_DEFS();
+
+int
+main(int argc, char **argv)
+{
+	GREATEST_MAIN_BEGIN();
+	GREATEST_RUN_SUITE(suite_basics);
+	GREATEST_MAIN_END();
+
+	return 0;
+}