1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00
profanity/test_history.c

131 lines
3.0 KiB
C
Raw Normal View History

2012-03-01 20:51:40 -05:00
#include <stdlib.h>
#include <head-unit.h>
#include "history.h"
static void beforetest(void)
{
history_init();
}
static void previous_returns_null_after_init(void)
{
char *prev = history_previous();
2012-03-01 20:59:36 -05:00
assert_is_null(prev);
2012-03-01 20:51:40 -05:00
}
static void next_returns_null_after_init(void)
{
char *next = history_next();
2012-03-01 20:59:36 -05:00
assert_is_null(next);
2012-03-01 20:51:40 -05:00
}
static void append_after_init_doesnt_fail(void)
{
history_append("try append");
assert_true(1);
}
static void append_then_previous_returns_appended(void)
{
history_append("try append");
char *prev = history_previous();
2012-03-07 19:46:24 -05:00
assert_string_equals("try append", prev);
2012-03-01 20:51:40 -05:00
}
static void append_then_next_returns_null(void)
{
history_append("try append");
char *next = history_next();
2012-03-01 20:59:36 -05:00
assert_is_null(next);
2012-03-01 20:51:40 -05:00
}
static void hits_null_at_top(void)
{
history_append("cmd1");
history_append("cmd2");
history_previous(); // cmd2
history_previous(); // cmd1
char *prev = history_previous();
2012-03-01 20:59:36 -05:00
assert_is_null(prev);
2012-03-01 20:51:40 -05:00
}
static void navigate_to_correct_item(void)
{
history_append("cmd1");
history_append("cmd2");
history_append("cmd3");
history_append("cmd4");
history_append("cmd5");
history_append("cmd6");
history_previous(); // cmd6
history_previous(); // cmd5
history_previous(); // cmd4
history_previous(); // cmd3
history_next(); // cmd4
history_previous(); // cmd3
history_previous(); // cmd2
char *str = history_next(); // cmd3
2012-03-07 19:46:24 -05:00
assert_string_equals("cmd3", str);
2012-03-01 20:51:40 -05:00
}
static void append_previous_item(void)
{
history_append("cmd1");
history_append("cmd2");
history_append("cmd3");
history_append("cmd4");
history_append("cmd5");
history_append("cmd6");
history_previous(); // cmd6
history_previous(); // cmd5
history_previous(); // cmd4
history_previous(); // cmd3
history_next(); // cmd4
history_previous(); // cmd3
history_previous(); // cmd2
char *str = history_next(); // cmd3
history_append(str);
char *cmd3_1 = history_previous();
2012-03-07 19:46:24 -05:00
assert_string_equals("cmd3", cmd3_1);
2012-03-01 20:51:40 -05:00
char *cmd6 = history_previous();
2012-03-07 19:46:24 -05:00
assert_string_equals("cmd6", cmd6);
2012-03-01 20:51:40 -05:00
char *cmd5 = history_previous();
2012-03-07 19:46:24 -05:00
assert_string_equals("cmd5", cmd5);
2012-03-01 20:51:40 -05:00
char *cmd4 = history_previous();
2012-03-07 19:46:24 -05:00
assert_string_equals("cmd4", cmd4);
2012-03-01 20:51:40 -05:00
char *cmd3 = history_previous();
2012-03-07 19:46:24 -05:00
assert_string_equals("cmd3", cmd3);
2012-03-01 20:51:40 -05:00
char *cmd2 = history_previous();
2012-03-07 19:46:24 -05:00
assert_string_equals("cmd2", cmd2);
2012-03-01 20:51:40 -05:00
char *cmd1 = history_previous();
2012-03-07 19:46:24 -05:00
assert_string_equals("cmd1", cmd1);
2012-03-01 20:51:40 -05:00
char *end = history_previous();
2012-03-01 20:59:36 -05:00
assert_is_null(end);
2012-03-01 20:51:40 -05:00
}
void register_history_tests(void)
{
TEST_MODULE("history tests");
BEFORETEST(beforetest);
TEST(previous_returns_null_after_init);
TEST(next_returns_null_after_init);
TEST(append_after_init_doesnt_fail);
TEST(append_then_previous_returns_appended);
TEST(append_then_next_returns_null);
TEST(hits_null_at_top);
TEST(navigate_to_correct_item);
TEST(append_previous_item);
}