diff tests/src/libirccd-js/js-api-util/main.cpp @ 773:8c44bbcbbab9

Misc: style, cleanup and update
author David Demelier <markand@malikania.fr>
date Fri, 26 Oct 2018 13:01:00 +0200
parents 35c1517d705d
children 06cc2f95f479
line wrap: on
line diff
--- a/tests/src/libirccd-js/js-api-util/main.cpp	Wed Oct 24 13:24:03 2018 +0200
+++ b/tests/src/libirccd-js/js-api-util/main.cpp	Fri Oct 26 13:01:00 2018 +0200
@@ -37,33 +37,33 @@
 
 BOOST_AUTO_TEST_CASE(format_simple)
 {
-    const auto ret = duk_peval_string(plugin_->get_context(),
-        "result = Irccd.Util.format(\"#{target}\", { target: \"markand\" })"
-    );
+	const auto ret = duk_peval_string(plugin_->get_context(),
+		"result = Irccd.Util.format(\"#{target}\", { target: \"markand\" })"
+	);
 
-    if (ret != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (ret != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "result"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "markand");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "result"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "markand");
 }
 
 BOOST_AUTO_TEST_CASE(splituser)
 {
-    if (duk_peval_string(plugin_->get_context(), "result = Irccd.Util.splituser(\"user!~user@hyper/super/host\");") != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (duk_peval_string(plugin_->get_context(), "result = Irccd.Util.splituser(\"user!~user@hyper/super/host\");") != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "result"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "user");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "result"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "user");
 }
 
 BOOST_AUTO_TEST_CASE(splithost)
 {
-    if (duk_peval_string(plugin_->get_context(), "result = Irccd.Util.splithost(\"user!~user@hyper/super/host\");") != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (duk_peval_string(plugin_->get_context(), "result = Irccd.Util.splithost(\"user!~user@hyper/super/host\");") != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "result"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "~user@hyper/super/host");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "result"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "~user@hyper/super/host");
 }
 
 /*
@@ -73,189 +73,189 @@
 
 BOOST_AUTO_TEST_CASE(cut_string_simple)
 {
-    const auto ret = duk_peval_string(plugin_->get_context(),
-        "lines = Irccd.Util.cut('hello world');\n"
-        "line0 = lines[0];\n"
-    );
+	const auto ret = duk_peval_string(plugin_->get_context(),
+		"lines = Irccd.Util.cut('hello world');\n"
+		"line0 = lines[0];\n"
+	);
 
-    if (ret != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (ret != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line0"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "hello world");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line0"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "hello world");
 }
 
 BOOST_AUTO_TEST_CASE(cut_string_double)
 {
-    const auto ret = duk_peval_string(plugin_->get_context(),
-        "lines = Irccd.Util.cut('hello world', 5);\n"
-        "line0 = lines[0];\n"
-        "line1 = lines[1];\n"
-    );
+	const auto ret = duk_peval_string(plugin_->get_context(),
+		"lines = Irccd.Util.cut('hello world', 5);\n"
+		"line0 = lines[0];\n"
+		"line1 = lines[1];\n"
+	);
 
-    if (ret != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (ret != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line0"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "hello");
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line1"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "world");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line0"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "hello");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line1"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "world");
 }
 
 BOOST_AUTO_TEST_CASE(cut_string_dirty)
 {
-    const auto ret = duk_peval_string(plugin_->get_context(),
-        "lines = Irccd.Util.cut('     hello    world     ', 5);\n"
-        "line0 = lines[0];\n"
-        "line1 = lines[1];\n"
-    );
+	const auto ret = duk_peval_string(plugin_->get_context(),
+		"lines = Irccd.Util.cut('	 hello	world	 ', 5);\n"
+		"line0 = lines[0];\n"
+		"line1 = lines[1];\n"
+	);
 
-    if (ret != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (ret != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line0"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "hello");
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line1"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "world");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line0"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "hello");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line1"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "world");
 }
 
 BOOST_AUTO_TEST_CASE(cut_string_too_much_lines)
 {
-    const auto ret = duk_peval_string(plugin_->get_context(),
-        "lines = Irccd.Util.cut('abc def ghi jkl', 3, 3);\n"
-    );
+	const auto ret = duk_peval_string(plugin_->get_context(),
+		"lines = Irccd.Util.cut('abc def ghi jkl', 3, 3);\n"
+	);
 
-    if (ret != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (ret != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "lines"));
-    BOOST_TEST(duk_is_undefined(plugin_->get_context(), -1));
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "lines"));
+	BOOST_TEST(duk_is_undefined(plugin_->get_context(), -1));
 }
 
 BOOST_AUTO_TEST_CASE(cut_string_token_too_big)
 {
-    const auto ret = duk_peval_string(plugin_->get_context(),
-        "try {\n"
-        "  lines = Irccd.Util.cut('hello world', 3);\n"
-        "} catch (e) {\n"
-        "  name = e.name;\n"
-        "  message = e.message;\n"
-        "}\n"
-    );
+	const auto ret = duk_peval_string(plugin_->get_context(),
+		"try {\n"
+		"  lines = Irccd.Util.cut('hello world', 3);\n"
+		"} catch (e) {\n"
+		"  name = e.name;\n"
+		"  message = e.message;\n"
+		"}\n"
+	);
 
-    if (ret != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (ret != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "name"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "RangeError");
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "message"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "word 'hello' could not fit in maxc limit (3)");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "name"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "RangeError");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "message"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "word 'hello' could not fit in maxc limit (3)");
 }
 
 BOOST_AUTO_TEST_CASE(cut_string_negative_maxc)
 {
-    const auto ret = duk_peval_string(plugin_->get_context(),
-        "try {\n"
-        "  lines = Irccd.Util.cut('hello world', -3);\n"
-        "} catch (e) {\n"
-        "  name = e.name;\n"
-        "  message = e.message;\n"
-        "}\n"
-    );
+	const auto ret = duk_peval_string(plugin_->get_context(),
+		"try {\n"
+		"  lines = Irccd.Util.cut('hello world', -3);\n"
+		"} catch (e) {\n"
+		"  name = e.name;\n"
+		"  message = e.message;\n"
+		"}\n"
+	);
 
-    if (ret != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (ret != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "name"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "RangeError");
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "message"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "argument 1 (maxc) must be positive");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "name"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "RangeError");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "message"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "argument 1 (maxc) must be positive");
 }
 
 BOOST_AUTO_TEST_CASE(cut_string_negative_maxl)
 {
-    const auto ret = duk_peval_string(plugin_->get_context(),
-        "try {\n"
-        "  lines = Irccd.Util.cut('hello world', undefined, -1);\n"
-        "} catch (e) {\n"
-        "  name = e.name;\n"
-        "  message = e.message;\n"
-        "}\n"
-    );
+	const auto ret = duk_peval_string(plugin_->get_context(),
+		"try {\n"
+		"  lines = Irccd.Util.cut('hello world', undefined, -1);\n"
+		"} catch (e) {\n"
+		"  name = e.name;\n"
+		"  message = e.message;\n"
+		"}\n"
+	);
 
-    if (ret != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (ret != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "name"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "RangeError");
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "message"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "argument 2 (maxl) must be positive");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "name"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "RangeError");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "message"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "argument 2 (maxl) must be positive");
 }
 
 BOOST_AUTO_TEST_CASE(cut_array_simple)
 {
-    const auto ret = duk_peval_string(plugin_->get_context(),
-        "lines = Irccd.Util.cut([ 'hello', 'world' ]);\n"
-        "line0 = lines[0];\n"
-    );
+	const auto ret = duk_peval_string(plugin_->get_context(),
+		"lines = Irccd.Util.cut([ 'hello', 'world' ]);\n"
+		"line0 = lines[0];\n"
+	);
 
-    if (ret != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (ret != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line0"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "hello world");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line0"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "hello world");
 }
 
 BOOST_AUTO_TEST_CASE(cut_array_double)
 {
-    const auto ret = duk_peval_string(plugin_->get_context(),
-        "lines = Irccd.Util.cut([ 'hello', 'world' ], 5);\n"
-        "line0 = lines[0];\n"
-        "line1 = lines[1];\n"
-    );
+	const auto ret = duk_peval_string(plugin_->get_context(),
+		"lines = Irccd.Util.cut([ 'hello', 'world' ], 5);\n"
+		"line0 = lines[0];\n"
+		"line1 = lines[1];\n"
+	);
 
-    if (ret != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (ret != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line0"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "hello");
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line1"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "world");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line0"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "hello");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line1"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "world");
 }
 
 BOOST_AUTO_TEST_CASE(cut_array_dirty)
 {
-    const auto ret = duk_peval_string(plugin_->get_context(),
-        "lines = Irccd.Util.cut([ '   ', ' hello  ', '  world ', '    '], 5);\n"
-        "line0 = lines[0];\n"
-        "line1 = lines[1];\n"
-    );
+	const auto ret = duk_peval_string(plugin_->get_context(),
+		"lines = Irccd.Util.cut([ '   ', ' hello  ', '  world ', '	'], 5);\n"
+		"line0 = lines[0];\n"
+		"line1 = lines[1];\n"
+	);
 
-    if (ret != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (ret != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line0"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "hello");
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line1"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "world");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line0"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "hello");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "line1"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "world");
 }
 
 BOOST_AUTO_TEST_CASE(cut_invalid_data)
 {
-    const auto ret = duk_peval_string(plugin_->get_context(),
-        "try {\n"
-        "  lines = Irccd.Util.cut(123);\n"
-        "} catch (e) {\n"
-        "  name = e.name;\n"
-        "  message = e.message;\n"
-        "}\n"
-    );
+	const auto ret = duk_peval_string(plugin_->get_context(),
+		"try {\n"
+		"  lines = Irccd.Util.cut(123);\n"
+		"} catch (e) {\n"
+		"  name = e.name;\n"
+		"  message = e.message;\n"
+		"}\n"
+	);
 
-    if (ret != 0)
-        throw duk::get_stack(plugin_->get_context(), -1);
+	if (ret != 0)
+		throw duk::get_stack(plugin_->get_context(), -1);
 
-    BOOST_TEST(duk_get_global_string(plugin_->get_context(), "name"));
-    BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "TypeError");
+	BOOST_TEST(duk_get_global_string(plugin_->get_context(), "name"));
+	BOOST_TEST(duk_get_string(plugin_->get_context(), -1) == "TypeError");
 }
 
 BOOST_AUTO_TEST_SUITE_END()