Blame tests/filter/ident.c

Packit Service 20376f
#include "clar_libgit2.h"
Packit Service 20376f
#include "git2/sys/filter.h"
Packit Service 20376f
Packit Service 20376f
static git_repository *g_repo = NULL;
Packit Service 20376f
Packit Service 20376f
void test_filter_ident__initialize(void)
Packit Service 20376f
{
Packit Service 20376f
	g_repo = cl_git_sandbox_init("crlf");
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_filter_ident__cleanup(void)
Packit Service 20376f
{
Packit Service 20376f
	cl_git_sandbox_cleanup();
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static void add_blob_and_filter(
Packit Service 20376f
	const char *data,
Packit Service 20376f
	git_filter_list *fl,
Packit Service 20376f
	const char *expected)
Packit Service 20376f
{
Packit Service 20376f
	git_oid id;
Packit Service 20376f
	git_blob *blob;
Packit Service 20376f
	git_buf out = { 0 };
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile("crlf/identtest", data);
Packit Service 20376f
	cl_git_pass(git_blob_create_fromworkdir(&id, g_repo, "identtest"));
Packit Service 20376f
	cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_filter_list_apply_to_blob(&out, fl, blob));
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_s(expected, out.ptr);
Packit Service 20376f
Packit Service 20376f
	git_blob_free(blob);
Packit Service 20376f
	git_buf_free(&out;;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_filter_ident__to_worktree(void)
Packit Service 20376f
{
Packit Service 20376f
	git_filter_list *fl;
Packit Service 20376f
	git_filter *ident;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_filter_list_new(
Packit Service 20376f
		&fl, g_repo, GIT_FILTER_TO_WORKTREE, 0));
Packit Service 20376f
Packit Service 20376f
	ident = git_filter_lookup(GIT_FILTER_IDENT);
Packit Service 20376f
	cl_assert(ident != NULL);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_filter_list_push(fl, ident, NULL));
Packit Service 20376f
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"Hello\n$Id$\nFun stuff\n", fl,
Packit Service 20376f
		"Hello\n$Id: b69e2387aafcaf73c4de5b9ab59abe27fdadee30 $\nFun stuff\n");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"Hello\n$Id: Junky$\nFun stuff\n", fl,
Packit Service 20376f
		"Hello\n$Id: 45cd107a7102911cb2a7df08404674327fa050b9 $\nFun stuff\n");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"$Id$\nAt the start\n", fl,
Packit Service 20376f
		"$Id: b13415c767abc196fb95bd17070e8c1113e32160 $\nAt the start\n");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"At the end\n$Id$", fl,
Packit Service 20376f
		"At the end\n$Id: 1344925c6bc65b34c5a7b50f86bf688e48e9a272 $");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"$Id$", fl,
Packit Service 20376f
		"$Id: b3f5ebfb5843bc43ceecff6d4f26bb37c615beb1 $");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"$Id: Some sort of junk goes here$", fl,
Packit Service 20376f
		"$Id: ab2dd3853c7c9a4bff55aca2bea077a73c32ac06 $");
Packit Service 20376f
Packit Service 20376f
	add_blob_and_filter("$Id: ", fl, "$Id: ");
Packit Service 20376f
	add_blob_and_filter("$Id", fl, "$Id");
Packit Service 20376f
	add_blob_and_filter("$I", fl, "$I");
Packit Service 20376f
	add_blob_and_filter("Id$", fl, "Id$");
Packit Service 20376f
Packit Service 20376f
	git_filter_list_free(fl);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_filter_ident__to_odb(void)
Packit Service 20376f
{
Packit Service 20376f
	git_filter_list *fl;
Packit Service 20376f
	git_filter *ident;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_filter_list_new(
Packit Service 20376f
		&fl, g_repo, GIT_FILTER_TO_ODB, 0));
Packit Service 20376f
Packit Service 20376f
	ident = git_filter_lookup(GIT_FILTER_IDENT);
Packit Service 20376f
	cl_assert(ident != NULL);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_filter_list_push(fl, ident, NULL));
Packit Service 20376f
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"Hello\n$Id$\nFun stuff\n",
Packit Service 20376f
		fl, "Hello\n$Id$\nFun stuff\n");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"Hello\n$Id: b69e2387aafcaf73c4de5b9ab59abe27fdadee30$\nFun stuff\n",
Packit Service 20376f
		fl, "Hello\n$Id$\nFun stuff\n");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"Hello\n$Id: Any junk you may have left here$\nFun stuff\n",
Packit Service 20376f
		fl, "Hello\n$Id$\nFun stuff\n");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"Hello\n$Id:$\nFun stuff\n",
Packit Service 20376f
		fl, "Hello\n$Id$\nFun stuff\n");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"Hello\n$Id:x$\nFun stuff\n",
Packit Service 20376f
		fl, "Hello\n$Id$\nFun stuff\n");
Packit Service 20376f
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"$Id$\nAt the start\n", fl, "$Id$\nAt the start\n");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"$Id: lots of random text that should be removed from here$\nAt the start\n", fl, "$Id$\nAt the start\n");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"$Id: lots of random text that should not be removed without a terminator\nAt the start\n", fl, "$Id: lots of random text that should not be removed without a terminator\nAt the start\n");
Packit Service 20376f
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"At the end\n$Id$", fl, "At the end\n$Id$");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"At the end\n$Id:$", fl, "At the end\n$Id$");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"At the end\n$Id:asdfasdf$", fl, "At the end\n$Id$");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"At the end\n$Id", fl, "At the end\n$Id");
Packit Service 20376f
	add_blob_and_filter(
Packit Service 20376f
		"At the end\n$IddI", fl, "At the end\n$IddI");
Packit Service 20376f
Packit Service 20376f
	add_blob_and_filter("$Id$", fl, "$Id$");
Packit Service 20376f
	add_blob_and_filter("$Id: any$", fl, "$Id$");
Packit Service 20376f
	add_blob_and_filter("$Id: any long stuff goes here you see$", fl, "$Id$");
Packit Service 20376f
	add_blob_and_filter("$Id: ", fl, "$Id: ");
Packit Service 20376f
	add_blob_and_filter("$Id", fl, "$Id");
Packit Service 20376f
	add_blob_and_filter("$I", fl, "$I");
Packit Service 20376f
	add_blob_and_filter("Id$", fl, "Id$");
Packit Service 20376f
Packit Service 20376f
	git_filter_list_free(fl);
Packit Service 20376f
}