Пример #1
0
static void
test_two_matches(void)
{
    char *buf;

    assert_int_equal(0, add_completion("mountpoint"));
    completion_group_end();
    assert_int_equal(0, add_completion("mount"));
    completion_group_end();

    assert_int_equal(0, add_completion("mount"));

    buf = next_completion();
    assert_string_equal("mountpoint", buf);
    free(buf);

    buf = next_completion();
    assert_string_equal("mount", buf);
    free(buf);

    buf = next_completion();
    assert_string_equal("mount", buf);
    free(buf);

    buf = next_completion();
    assert_string_equal("mountpoint", buf);
    free(buf);
}
Пример #2
0
void
complete_variables(const char *cmd, const char **start)
{
	int i;
	size_t len;
	assert(initialized);

	/* currently we support only environment variables */
	if(*cmd != '$')
	{
		*start = cmd;
		add_completion(cmd);
		return;
	}
	cmd++;
	*start = cmd;

	/* add all variables that start with given beginning */
	len = strlen(cmd);
	for(i = 0; i < nvars; i++)
	{
		if(vars[i].name == NULL)
			continue;
		if(vars[i].removed)
			continue;
		if(strnoscmp(vars[i].name, cmd, len) == 0)
			add_completion(vars[i].name);
	}
	completion_group_end();
	add_completion(cmd);
}
Пример #3
0
void
complete_colorschemes(const char *name)
{
	char colors_dir[PATH_MAX];
	DIR *dir;
	struct dirent *d;
	size_t len;

	snprintf(colors_dir, sizeof(colors_dir), "%s/colors", cfg.config_dir);

	dir = opendir(colors_dir);
	if(dir == NULL)
		return;

	len = strlen(name);

	while((d = readdir(dir)) != NULL)
	{
#ifndef _WIN32
		if(d->d_type != DT_REG && d->d_type != DT_LNK)
			continue;
#endif

		if(d->d_name[0] == '.')
			continue;

		if(strncmp(name, d->d_name, len) == 0)
			add_completion(d->d_name);
	}
	closedir(dir);

	completion_group_end();
	add_completion(name);
}
Пример #4
0
static void
test_general(void)
{
    char *buf;

    assert_int_equal(0, add_completion("abc"));
    assert_int_equal(0, add_completion("acd"));
    completion_group_end();

    assert_int_equal(0, add_completion("a"));

    buf = next_completion();
    assert_string_equal("abc", buf);
    free(buf);
    buf = next_completion();
    assert_string_equal("acd", buf);
    free(buf);
    buf = next_completion();
    assert_string_equal("a", buf);
    free(buf);
    buf = next_completion();
    assert_string_equal("abc", buf);
    free(buf);
    buf = next_completion();
    assert_string_equal("acd", buf);
    free(buf);
}
Пример #5
0
static void
test_removes_duplicates(void)
{
    char *buf;

    assert_int_equal(0, add_completion("mou"));
    assert_int_equal(0, add_completion("mount"));
    assert_int_equal(0, add_completion("mount"));
    completion_group_end();

    assert_int_equal(0, add_completion("m"));

    buf = next_completion();
    assert_string_equal("mou", buf);
    free(buf);

    buf = next_completion();
    assert_string_equal("mount", buf);
    free(buf);

    buf = next_completion();
    assert_string_equal("m", buf);
    free(buf);

    buf = next_completion();
    assert_string_equal("mou", buf);
    free(buf);
}
Пример #6
0
static void
test_umbiguous_begin(void)
{
    char *buf;

    assert_int_equal(0, add_completion("sort"));
    assert_int_equal(0, add_completion("sortorder"));
    assert_int_equal(0, add_completion("sortnumbers"));
    completion_group_end();

    assert_int_equal(0, add_completion("sort"));

    buf = next_completion();
    assert_string_equal("sort", buf);
    free(buf);

    buf = next_completion();
    assert_string_equal("sortnumbers", buf);
    free(buf);

    buf = next_completion();
    assert_string_equal("sortorder", buf);
    free(buf);

    buf = next_completion();
    assert_string_equal("sort", buf);
    free(buf);

    buf = next_completion();
    assert_string_equal("sort", buf);
    free(buf);
}
Пример #7
0
static void
test_order(void)
{
    char *buf;

    assert_int_equal(0, add_completion("aa"));
    assert_int_equal(0, add_completion("az"));
    completion_group_end();

    assert_int_equal(0, add_completion("a"));

    set_completion_order(1);

    buf = next_completion();
    assert_string_equal("az", buf);
    free(buf);

    buf = next_completion();
    assert_string_equal("aa", buf);
    free(buf);

    buf = next_completion();
    assert_string_equal("a", buf);
    free(buf);
}
Пример #8
0
static void
test_rewind_one_unambiguous_completion(void)
{
    char *buf;

    assert_int_equal(0, add_completion("abcd"));
    completion_group_end();

    assert_int_equal(0, add_completion("a"));

    buf = next_completion();
    assert_string_equal("abcd", buf);
    free(buf);
    buf = next_completion();
    assert_string_equal("abcd", buf);
    free(buf);

    rewind_completion();

    buf = next_completion();
    assert_string_equal("a", buf);
    free(buf);
    buf = next_completion();
    assert_string_equal("abcd", buf);
    free(buf);
}
Пример #9
0
static int
complete_args(int id, const char *args, int argc, char **argv, int arg_pos)
{
	const char *arg;

	reset_completion();
	add_completion("followlinks");
	add_completion("fastrun");
	completion_group_end();
	add_completion("f");

	arg = strrchr(args, ' ');
	if(arg == NULL)
		arg = args;
	else
		arg++;
	return arg - args;
}
Пример #10
0
static void
test_one_element_completion(void)
{
    char *buf;

    completion_group_end();

    assert_int_equal(0, add_completion("a"));

    buf = next_completion();
    assert_string_equal("a", buf);
    free(buf);
    buf = next_completion();
    assert_string_equal("a", buf);
    free(buf);
    buf = next_completion();
    assert_string_equal("a", buf);
    free(buf);
    buf = next_completion();
    assert_string_equal("a", buf);
    free(buf);
}