summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Carl <danielcarl@gmx.de>2015-02-04 23:26:44 +0100
committerDaniel Carl <danielcarl@gmx.de>2015-02-04 23:26:44 +0100
commit5e2d8118299bbfa87c9ea9ee9c221abde2dfadcd (patch)
tree85fd286487122766f441253d1f41514daa1e8681 /tests
parente2a01bf08a4fd2f8ace945320a6f0f014e8b18f5 (diff)
Use more g_string_* function in map processing (#160).
The use of these function makes it easier to see what's done compared to the character moving in the loops.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-map.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/tests/test-map.c b/tests/test-map.c
index e2cb3c3..2333d54 100644
--- a/tests/test-map.c
+++ b/tests/test-map.c
@@ -23,7 +23,7 @@
#include <src/map.h>
#include <src/mode.h>
-static char queue[10]; /* receives the keypresses */
+static char queue[20]; /* receives the keypresses */
static int qpos = 0; /* points to the queue entry for the next keypress */
#define QUEUE_APPEND(c) { \
@@ -55,12 +55,16 @@ static void test_handle_string_simple(void)
/* test simple mappings */
ASSERT_MAPPING("a", "[a]");
ASSERT_MAPPING("b", "[b]");
+ ASSERT_MAPPING("[c]", "c");
ASSERT_MAPPING("<Tab>", "[tab]");
ASSERT_MAPPING("<S-Tab>", "[shift-tab]");
ASSERT_MAPPING("<C-F>", "[ctrl-f]");
ASSERT_MAPPING("<C-f>", "[ctrl-f]");
ASSERT_MAPPING("<CR>", "[cr]");
ASSERT_MAPPING("foobar", "[baz]");
+
+ /* key sequences that are not changed by mappings */
+ ASSERT_MAPPING("fghi", "fghi");
}
static void test_handle_string_alias(void)
@@ -70,20 +74,11 @@ static void test_handle_string_alias(void)
ASSERT_MAPPING("<C-M>", "[cr]");
}
-static void test_handle_string_multiple(void)
-{
- /* test multiple mappings together */
- ASSERT_MAPPING("ba", "[b][a]");
-
- /* incomplete ambiguous sequences are not matched jet */
- ASSERT_MAPPING("foob", "");
- ASSERT_MAPPING("ar", "[baz]");
-}
-
static void test_handle_string_remapped(void)
{
/* test multiple mappings together */
ASSERT_MAPPING("ba", "[b][a]");
+ ASSERT_MAPPING("ab12345[c]", "[a][b]12345c");
/* incomplete ambiguous sequences are not matched jet */
ASSERT_MAPPING("foob", "");
@@ -94,6 +89,17 @@ static void test_handle_string_remapped(void)
ASSERT_MAPPING("c", "[b][a]z[a]");
map_insert("d", "cki", 't', true);
ASSERT_MAPPING("d", "[b][a]z[a]ki");
+
+ /* remove the no more needed mappings */
+ map_delete("c", 't');
+ map_delete("d", 't');
+}
+
+static void test_handle_string_overrule(void)
+{
+ /* add another map for 'a' and check if this overrules the previous set */
+ map_insert("a", "overruled", 't', false);
+ ASSERT_MAPPING("a", "overruled");
}
static void test_remove(void)
@@ -147,21 +153,21 @@ int main(int argc, char *argv[])
g_test_add_func("/test-map/handle_string/simple", test_handle_string_simple);
g_test_add_func("/test-map/handle_string/alias", test_handle_string_alias);
- g_test_add_func("/test-map/handle_string/multi", test_handle_string_multiple);
g_test_add_func("/test-map/handle_string/remapped", test_handle_string_remapped);
+ g_test_add_func("/test-map/handle_string/overrule", test_handle_string_overrule);
g_test_add_func("/test-map/remove", test_remove);
g_test_add_func("/test-map/keypress/single-char", test_keypress_single);
g_test_add_func("/test-map/keypress/sequence", test_keypress_sequence);
/* add some mappings to test */
- map_insert("a", "[a]", 't', false);
+ map_insert("a", "[a]", 't', false); /* inlen < mappedlen */
map_insert("b", "[b]", 't', false);
+ map_insert("[c]", "c", 't', false); /* inlen > mappedlen */
+ map_insert("foobar", "[baz]", 't', false);
map_insert("<Tab>", "[tab]", 't', false);
map_insert("<S-Tab>", "[shift-tab]", 't', false);
map_insert("<C-F>", "[ctrl-f]", 't', false);
map_insert("<CR>", "[cr]", 't', false);
- /* map long sequence to shorter result */
- map_insert("foobar", "[baz]", 't', false);
result = g_test_run();
map_cleanup();