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 / abbrevs / addition.c (039db81f1580ec10456e203e53b56dde575d20cd) (2,306B) (mode 100644) [raw]
#include <stic.h>

#include <stddef.h> /* NULL wchar_t */

#include "../../src/engine/abbrevs.h"
#include "../../src/utils/str.h"

static wchar_t * handler(void *user_data);

TEST(adds_fine_first_time)
{
	int no_remap;

	assert_success(vle_abbr_add(L"lhs", L"rhs"));
	assert_wstring_equal(L"rhs", vle_abbr_expand(L"lhs", &no_remap));

	assert_success(vle_abbr_add_no_remap(L"lhs", L"rhs"));
	assert_wstring_equal(L"rhs", vle_abbr_expand(L"lhs", &no_remap));
}

TEST(overwriten_on_second_addition)
{
	int no_remap;

	assert_success(vle_abbr_add(L"lhs1", L"rhs1_1"));
	assert_wstring_equal(L"rhs1_1", vle_abbr_expand(L"lhs1", &no_remap));
	assert_success(vle_abbr_add(L"lhs1", L"rhs1_2"));
	assert_wstring_equal(L"rhs1_2", vle_abbr_expand(L"lhs1", &no_remap));
	assert_success(vle_abbr_add_no_remap(L"lhs1", L"rhs1_3"));
	assert_wstring_equal(L"rhs1_3", vle_abbr_expand(L"lhs1", &no_remap));

	assert_success(vle_abbr_add_no_remap(L"lhs2", L"rhs2_1"));
	assert_wstring_equal(L"rhs2_1", vle_abbr_expand(L"lhs2", &no_remap));
	assert_success(vle_abbr_add(L"lhs2", L"rhs2_2"));
	assert_wstring_equal(L"rhs2_2", vle_abbr_expand(L"lhs2", &no_remap));
	assert_success(vle_abbr_add_no_remap(L"lhs2", L"rhs2_3"));
	assert_wstring_equal(L"rhs2_3", vle_abbr_expand(L"lhs2", &no_remap));
}

TEST(overwrite_changes_mapping_type)
{
	int no_remap;

	assert_success(vle_abbr_add(L"lhs", L"rhs"));
	assert_non_null(vle_abbr_expand(L"lhs", &no_remap));
	assert_false(no_remap);

	assert_success(vle_abbr_add_no_remap(L"lhs", L"rhs"));
	assert_non_null(vle_abbr_expand(L"lhs", &no_remap));
	assert_true(no_remap);

	assert_success(vle_abbr_add(L"lhs", L"rhs"));
	assert_non_null(vle_abbr_expand(L"lhs", &no_remap));
	assert_false(no_remap);
}

TEST(overwrite_foreign)
{
	int no_remap;

	assert_success(vle_abbr_add_foreign(L"lhs", "descr", /*no_remap=*/1, handler,
				/*user_data=*/NULL));
	assert_wstring_equal(L"hrhs", vle_abbr_expand(L"lhs", &no_remap));
	assert_true(no_remap);
	assert_success(vle_abbr_add(L"lhs", L"rhs"));
	assert_wstring_equal(L"rhs", vle_abbr_expand(L"lhs", &no_remap));
	assert_false(no_remap);
}

static wchar_t *
handler(void *user_data)
{
	return vifm_wcsdup(L"hrhs");
}

/* 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