/*
 * Ibis - IRCv3 Library
 * Copyright (C) 2022-2024 Ibis Developers
 *
 * Ibis is the legal property of its developers, whose names are too numerous
 * to list here.  Please refer to the COPYRIGHT file distributed with this
 * source distribution.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
 */

#include <glib.h>

#include <ibis.h>

static void
test_ibis_normalize_ascii(void) {
	char *normalized = NULL;

	/* Check NULL input */
	normalized = ibis_normalize_ascii(NULL);
	g_assert_cmpstr(normalized, ==, "");
	g_free(normalized);

	/* Only letters should be normalized, '[', ']', '\\', and '~' should be left
	 * alone.
	 */
	normalized = ibis_normalize_ascii("Foo[]🐻\\Baz~");
	g_assert_cmpstr(normalized, ==, "foo[]🐻\\baz~");
	g_free(normalized);
}

static void
test_ibis_normalize_rfc1459(void) {
	char *normalized = NULL;

	/* Check NULL input */
	normalized = ibis_normalize_rfc1459(NULL);
	g_assert_cmpstr(normalized, ==, "");
	g_free(normalized);

	/* Letters, '[', ']', '\\', and '~' should be normalized.
	 */
	normalized = ibis_normalize_rfc1459("Foo[]🐻\\Baz~");
	g_assert_cmpstr(normalized, ==, "foo{}🐻|baz^");
	g_free(normalized);
}

static void
test_ibis_normalize_rfc1459_strict(void) {
	char *normalized = NULL;

	/* Check NULL input */
	normalized = ibis_normalize_rfc1459_strict(NULL);
	g_assert_cmpstr(normalized, ==, "");
	g_free(normalized);

	/* Letters, '[', ']', and '\\' should be normalized, but not '~'.
	 */
	normalized = ibis_normalize_rfc1459_strict("Foo[]🐻\\Baz~");
	g_assert_cmpstr(normalized, ==, "foo{}🐻|baz~");
	g_free(normalized);
}

/******************************************************************************
 * Main
 *****************************************************************************/
int
main(int argc, char *argv[]) {
	g_test_init(&argc, &argv, NULL);
	g_test_set_nonfatal_assertions();

	g_test_add_func("/ibis/normalize/ascii",
	                test_ibis_normalize_ascii);
	g_test_add_func("/ibis/normalize/rfc1459",
	                test_ibis_normalize_rfc1459);
	g_test_add_func("/ibis/normalize/rfc1459_strict",
	                test_ibis_normalize_rfc1459_strict);

	return g_test_run();
}
