isvalidname.c 1.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#include "clar_libgit2.h"

void test_refs_isvalidname__can_detect_invalid_formats(void)
{
	cl_assert_equal_i(false, git_reference_is_valid_name("refs/tags/0.17.0^{}"));
	cl_assert_equal_i(false, git_reference_is_valid_name("TWO/LEVELS"));
	cl_assert_equal_i(false, git_reference_is_valid_name("ONE.LEVEL"));
	cl_assert_equal_i(false, git_reference_is_valid_name("HEAD/"));
	cl_assert_equal_i(false, git_reference_is_valid_name("NO_TRAILING_UNDERSCORE_"));
	cl_assert_equal_i(false, git_reference_is_valid_name("_NO_LEADING_UNDERSCORE"));
	cl_assert_equal_i(false, git_reference_is_valid_name("HEAD/aa"));
	cl_assert_equal_i(false, git_reference_is_valid_name("lower_case"));
13 14
	cl_assert_equal_i(false, git_reference_is_valid_name("/stupid/name/master"));
	cl_assert_equal_i(false, git_reference_is_valid_name("/"));
15
	cl_assert_equal_i(false, git_reference_is_valid_name("//"));
16
	cl_assert_equal_i(false, git_reference_is_valid_name(""));
17
	cl_assert_equal_i(false, git_reference_is_valid_name("refs/heads/sub.lock/webmatrix"));
18 19 20 21 22 23 24 25 26
}

void test_refs_isvalidname__wont_hopefully_choke_on_valid_formats(void)
{
	cl_assert_equal_i(true, git_reference_is_valid_name("refs/tags/0.17.0"));
	cl_assert_equal_i(true, git_reference_is_valid_name("refs/LEVELS"));
	cl_assert_equal_i(true, git_reference_is_valid_name("HEAD"));
	cl_assert_equal_i(true, git_reference_is_valid_name("ONE_LEVEL"));
	cl_assert_equal_i(true, git_reference_is_valid_name("refs/stash"));
27
	cl_assert_equal_i(true, git_reference_is_valid_name("refs/remotes/origin/bim_with_3d@11296"));
28 29 30
	cl_assert_equal_i(true, git_reference_is_valid_name("refs/master{yesterday"));
	cl_assert_equal_i(true, git_reference_is_valid_name("refs/master}yesterday"));
	cl_assert_equal_i(true, git_reference_is_valid_name("refs/master{yesterday}"));
31
}