xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
<root> / tests / cmds / count.c (8c4aad922dfd775ccb44d21815e07261820f4b3d) (1,570B) (mode 100644) [raw]
#include <stic.h>

#include <string.h>

#include "../../src/engine/cmds.h"
#include "../../src/utils/macros.h"
#include "../../src/cmd_core.h"

extern cmds_conf_t cmds_conf;

static int wincmd_cmd(const cmd_info_t* cmd_info);

static cmd_info_t cmdi;

static const cmd_add_t commands[] = {
	{ .name = "wincmd",       .abbr = "winc", .id = -1,      .descr = "descr",
	  .flags = HAS_RANGE,
	  .handler = &wincmd_cmd, .min_args = 1,  .max_args = 1, },
};

SETUP()
{
	cmds_conf.begin = 0;
	cmds_conf.current = 10;
	cmds_conf.end = 20;

	cmdi.count = ~NOT_DEF;
	assert_false(cmdi.count == NOT_DEF);

	vle_cmds_add(commands, ARRAY_LEN(commands));
}

static int
wincmd_cmd(const cmd_info_t* cmd_info)
{
	cmdi = *cmd_info;
	return 0;
}

TEST(count_is_undef_if_not_present)
{
	assert_success(vle_cmds_run("wincmd a"));
	assert_int_equal(NOT_DEF, cmdi.count);
}

TEST(count_can_be_larger_than_end)
{
	assert_success(vle_cmds_run("40wincmd a"));
	assert_int_equal(40, cmdi.count);
}

TEST(count_can_be_negative)
{
	assert_success(vle_cmds_run("-11wincmd a"));
	assert_int_equal(0, cmdi.count);

	assert_success(vle_cmds_run("-40wincmd a"));
	assert_int_equal(cmds_conf.current - 40 + 1, cmdi.count);
}

TEST(special_values_are_valid_count)
{
	assert_success(vle_cmds_run(".wincmd a"));
	assert_int_equal(cmds_conf.current + 1, cmdi.count);

	assert_success(vle_cmds_run("$wincmd a"));
	assert_int_equal(cmds_conf.end - cmds_conf.begin + 1, cmdi.count);
}

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 filetype=c : */
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master