<commit_before>/*
 * uriparser - RFC 3986 URI parsing library
 *
 * Copyright (C) 2007, <NAME> <<EMAIL>>
 * Copyright (C) 2007, <NAME> <<EMAIL>>
 *
 * 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.1 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "FourSuite.h"
#include <uriparser/Uri.h>



// All testcases in this file are coming from
// http://cvs.4suite.org/viewcvs/4Suite/test/Lib/test_uri.py



bool FourSuite::testAddOrRemoveBaseHelper(const char * ref, const char * base,
	const char * expected, bool add, bool domainRootMode) {
	UriParserStateA stateA;

	// Base
	UriUriA baseUri;
	stateA.uri = &baseUri;
	int res = uriParseUriA(&stateA, base);
	if (res != 0) {
		return false;
	}

	// Rel
	UriUriA relUri;
	stateA.uri = &relUri;
	res = uriParseUriA(&stateA, ref);
	if (res != 0) {
		uriFreeUriMembersA(&baseUri);
		return false;
	}

	// Expected result
	UriUriA expectedUri;
	stateA.uri = &expectedUri;
	res = uriParseUriA(&stateA, expected);
	if (res != 0) {
		uriFreeUriMembersA(&baseUri);
		uriFreeUriMembersA(&relUri);
		return false;
	}

	// Transform
	UriUriA transformedUri;
	if (add) {
		res = uriAddBaseUriA(&transformedUri, &relUri, &baseUri);
	} else {
		res = uriRemoveBaseUriA(&transformedUri, &relUri, &baseUri,
				domainRootMode ? URI_TRUE : URI_FALSE);
	}
	if (res != 0) {
		uriFreeUriMembersA(&baseUri);
		uriFreeUriMembersA(&relUri);
		return false;
	}

	const bool equal = (URI_TRUE == uriEqualsUriA(&transformedUri, &expectedUri));
	if (!equal) {
		char transformedUriText[1024 * 8];
		char expectedUriText[1024 * 8];
		uriToStringA(transformedUriText, &transformedUri, 1024 * 8, NULL);
		uriToStringA(expectedUriText, &expectedUri, 1024 * 8, NULL);
		printf("\n\n\nExpected: \"%s\"\nReceived: \"%s\"\n\n\n", expectedUriText, transformedUriText);
	}

	uriFreeUriMembersA(&baseUri);
	uriFreeUriMembersA(&relUri);
	uriFreeUriMembersA(&expectedUri);
	return equal;
}



void FourSuite::absolutize_test_cases() {
	char * BASE_URI[] = {
			"http://a/b/c/d;p?q",
			"http://a/b/c/d;p?q=1/2",
			"http://a/b/c/d;p=1/2?q",
			"fred:///s//a/b/c",
			"http:///s//a/b/c"};

	// ref, base, exptected
<commit_msg>Add two const modifiers<commit_after>/*
 * uriparser - RFC 3986 URI parsing library
 *
 * Copyright (C) 2007, <NAME> <<EMAIL>>
 * Copyright (C) 2007, <NAME> <<EMAIL>>
 *
 * 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.1 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "FourSuite.h"
#include <uriparser/Uri.h>



// All testcases in this file are coming from
// http://cvs.4suite.org/viewcvs/4Suite/test/Lib/test_uri.py



bool FourSuite::testAddOrRemoveBaseHelper(const char * ref, const char * base,
	const char * expected, bool add, bool domainRootMode) {
	UriParserStateA stateA;

	// Base
	UriUriA baseUri;
	stateA.uri = &baseUri;
	int res = uriParseUriA(&stateA, base);
	if (res != 0) {
		return false;
	}

	// Rel
	UriUriA relUri;
	stateA.uri = &relUri;
	res = uriParseUriA(&stateA, ref);
	if (res != 0) {
		uriFreeUriMembersA(&baseUri);
		return false;
	}

	// Expected result
	UriUriA expectedUri;
	stateA.uri = &expectedUri;
	res = uriParseUriA(&stateA, expected);
	if (res != 0) {
		uriFreeUriMembersA(&baseUri);
		uriFreeUriMembersA(&relUri);
		return false;
	}

	// Transform
	UriUriA transformedUri;
	if (add) {
		res = uriAddBaseUriA(&transformedUri, &relUri, &baseUri);
	} else {
		res = uriRemoveBaseUriA(&transformedUri, &relUri, &baseUri,
				domainRootMode ? URI_TRUE : URI_FALSE);
	}
	if (res != 0) {
		uriFreeUriMembersA(&baseUri);
		uriFreeUriMembersA(&relUri);
		return false;
	}

	const bool equal = (URI_TRUE == uriEqualsUriA(&transformedUri, &expectedUri));
	if (!equal) {
		char transformedUriText[1024 * 8];
		char expectedUriText[1024 * 8];
		uriToStringA(transformedUriText, &transformedUri, 1024 * 8, NULL);
		uriToStringA(expectedUriText, &expectedUri, 1024 * 8, NULL);
		printf("\n\n\nExpected: \"%s\"\nReceived: \"%s\"\n\n\n", expectedUriText, transformedUriText);
	}

	uriFreeUriMembersA(&baseUri);
	uriFreeUriMembersA(&relUri);
	uriFreeUriMembersA(&expectedUri);
	return equal;
}



void FourSuite::absolutize_test_cases() {
	const char * const BASE_URI[] = {
			"http://a/b/c/d;p?q",
			"http://a/b/c/d;p?q=1/2",
			"http://a/b/c/d;p=1/2?q",
			"fred:///s//a/b/c",
			"http:///s//a/b/c"};

	// ref, base, exptected

{'fraction_non_alphanumeric': 0.1333095067905647, 'fraction_numerical': 0.019656897784131523, 'mean_word_length': 4.024236983842011, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4967337', 'n_tokens_mistral': 2105, 'n_tokens_neox': 1916, 'n_words': 557}