<commit_before>/**
 * @file llurlentry_test.cpp
 * @author <NAME>
 * @brief Unit tests for LLUrlEntry objects
 *
 * $LicenseInfo:firstyear=2009&license=viewergpl$
 * 
 * Copyright (c) 2009, Linden Research, Inc.
 * 
 * The following source code is PROPRIETARY AND CONFIDENTIAL. Use of
 * this source code is governed by the Linden Lab Source Code Disclosure
 * Agreement ("Agreement") previously entered between you and Linden
 * Lab. By accessing, using, copying, modifying or distributing this
 * software, you acknowledge that you have been informed of your
 * obligations under the Agreement and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#include "linden_common.h"
#include "../llurlentry.h"
#include "llurlentry_stub.cpp"
#include "lltut.h"

#include <boost/regex.hpp>

namespace tut
{
	struct LLUrlEntryData
	{
	};

	typedef test_group<LLUrlEntryData> factory;
	typedef factory::object object;
}

namespace
{
	tut::factory tf("LLUrlEntry");
}

namespace tut
{
	void testRegex(const std::string &testname, boost::wregex regex,
				   const char *text, const std::string &expected)
	{
		std::string url = "";
		boost::wcmatch result;
		LLWString wtext = utf8str_to_wstring(text);
		const wchar_t *wctext = wtext.c_str();
		bool found = boost::regex_search(wctext, result, regex);
		if (found)
		{
			S32 start = static_cast<U32>(result[0].first - wctext);
			S32 end = static_cast<U32>(result[0].second - wctext);
			url = wstring_to_utf8str(wtext.substr(start, end-start));
		}
		ensure_equals(testname, url, expected);
	}

	template<> template<>
	void object::test<1>()
	{
		//
		// test LLUrlEntryHTTP - standard http Urls
		//
		LLUrlEntryHTTP url;
		boost::wregex r = url.getPattern();

		testRegex("no valid url", r,
				  "htp://slurl.com/",
				  "");

		testRegex("simple http (1)", r,<commit_msg>a stab at fixing this test.<commit_after>/**
 * @file llurlentry_test.cpp
 * @author <NAME>
 * @brief Unit tests for LLUrlEntry objects
 *
 * $LicenseInfo:firstyear=2009&license=viewergpl$
 * 
 * Copyright (c) 2009, Linden Research, Inc.
 * 
 * The following source code is PROPRIETARY AND CONFIDENTIAL. Use of
 * this source code is governed by the Linden Lab Source Code Disclosure
 * Agreement ("Agreement") previously entered between you and Linden
 * Lab. By accessing, using, copying, modifying or distributing this
 * software, you acknowledge that you have been informed of your
 * obligations under the Agreement and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#include "linden_common.h"
#include "../llurlentry.h"
#include "llurlentry_stub.cpp"
#include "lltut.h"

#include <boost/regex.hpp>

namespace tut
{
	struct LLUrlEntryData
	{
	};

	typedef test_group<LLUrlEntryData> factory;
	typedef factory::object object;
}

namespace
{
	tut::factory tf("LLUrlEntry");
}

namespace tut
{
	void testRegex(const std::string &testname, boost::wregex regex,
				   const char *text, const std::string &expected)
	{
		std::string url = "";
		boost::wcmatch result;
		LLWString wtext = utf8str_to_wstring(text);
		const wchar_t *wctext = (const wchar_t *)(wtext.c_str());
		bool found = boost::regex_search(wctext, result, regex);
		if (found)
		{
			S32 start = static_cast<U32>(result[0].first - wctext);
			S32 end = static_cast<U32>(result[0].second - wctext);
			url = wstring_to_utf8str(wtext.substr(start, end-start));
		}
		ensure_equals(testname, url, expected);
	}

	template<> template<>
	void object::test<1>()
	{
		//
		// test LLUrlEntryHTTP - standard http Urls
		//
		LLUrlEntryHTTP url;
		boost::wregex r = url.getPattern();

		testRegex("no valid url", r,
				  "htp://slurl.com/",
				  "");

		testRegex("simple http (1)", r,
{'fraction_non_alphanumeric': 0.12119713084343309, 'fraction_numerical': 0.010883007667573583, 'mean_word_length': 4.204633204633205, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7540595', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1339, 'n_words': 396}