view tests/js-unicode/main.cpp @ 17:73b7d6dbe576

Irccd: missing WITH_SSL in irccd-config.h, #414
author David Demelier <markand@malikania.fr>
date Fri, 12 Feb 2016 12:40:01 +0100
parents 1158cffe5a5e
children f8160d515a76
line wrap: on
line source

/*
 * main.cpp -- test Irccd.Unicode API
 *
 * Copyright (c) 2013-2016 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 /!\
 */

#include <gtest/gtest.h>

#include <js-irccd.h>
#include <js-unicode.h>

using namespace irccd;

TEST(TestJsUnicode, isLetter)
{
	js::Context ctx;

	loadJsIrccd(ctx);
	loadJsUnicode(ctx);

	try {
		ctx.peval(js::Script{"result = Irccd.Unicode.isLetter(String('é').charCodeAt(0));"});
		ASSERT_TRUE(ctx.getGlobal<bool>("result"));

		ctx.peval(js::Script{"result = Irccd.Unicode.isLetter(String('€').charCodeAt(0));"});
		ASSERT_FALSE(ctx.getGlobal<bool>("result"));
	} catch (const std::exception &ex) {
		FAIL() << ex.what();
	}
}

TEST(TestJsUnicode, isLower)
{
	js::Context ctx;

	loadJsIrccd(ctx);
	loadJsUnicode(ctx);

	try {
		ctx.peval(js::Script{"result = Irccd.Unicode.isLower(String('é').charCodeAt(0));"});
		ASSERT_TRUE(ctx.getGlobal<bool>("result"));

		ctx.peval(js::Script{"result = Irccd.Unicode.isLower(String('É').charCodeAt(0));"});
		ASSERT_FALSE(ctx.getGlobal<bool>("result"));
	} catch (const std::exception &ex) {
		FAIL() << ex.what();
	}
}

TEST(TestJsUnicode, isUpper)
{
	js::Context ctx;

	loadJsIrccd(ctx);
	loadJsUnicode(ctx);

	try {
		ctx.peval(js::Script{"result = Irccd.Unicode.isUpper(String('É').charCodeAt(0));"});
		ASSERT_TRUE(ctx.getGlobal<bool>("result"));

		ctx.peval(js::Script{"result = Irccd.Unicode.isUpper(String('é').charCodeAt(0));"});
		ASSERT_FALSE(ctx.getGlobal<bool>("result"));
	} catch (const std::exception &ex) {
		FAIL() << ex.what();
	}
}

int main(int argc, char **argv)
{
	testing::InitGoogleTest(&argc, argv);

	return RUN_ALL_TESTS();
}