start adding legacy tests for paragraph

This commit is contained in:
Enno Rehling 2018-12-01 21:56:21 +01:00
parent 924ce441dd
commit 025cf18ab2
3 changed files with 37 additions and 3 deletions

View file

@ -169,9 +169,8 @@ static void centre(struct stream *out, const char *s, bool breaking)
} }
} }
static void void paragraph(struct stream *out, const char *str, ptrdiff_t indent,
paragraph(struct stream *out, const char *str, ptrdiff_t indent, int hanging_indent, int hanging_indent, char marker)
char marker)
{ {
size_t length = REPORTWIDTH; size_t length = REPORTWIDTH;
const char *handle_end, *begin, *mark = 0; const char *handle_end, *begin, *mark = 0;

View file

@ -35,6 +35,7 @@ extern "C" {
void report_region(struct stream *out, const struct region * r, struct faction * f); void report_region(struct stream *out, const struct region * r, struct faction * f);
void report_allies(struct stream *out, size_t maxlen, const struct faction * f, struct allies * allies, const char *prefix); void report_allies(struct stream *out, size_t maxlen, const struct faction * f, struct allies * allies, const char *prefix);
void pump_paragraph(struct sbstring *sbp, struct stream *out, size_t maxlen, bool isfinal); void pump_paragraph(struct sbstring *sbp, struct stream *out, size_t maxlen, bool isfinal);
void paragraph(struct stream *out, const char *str, ptrdiff_t indent, int hanging_indent, char marker);
void nr_spell_syntax(char *buf, size_t size, struct spellbook_entry * sbe, const struct locale *lang); void nr_spell_syntax(char *buf, size_t size, struct spellbook_entry * sbe, const struct locale *lang);
void nr_spell(struct stream *out, struct spellbook_entry * sbe, const struct locale *lang); void nr_spell(struct stream *out, struct spellbook_entry * sbe, const struct locale *lang);

View file

@ -379,6 +379,38 @@ static void test_write_spell_syntax(CuTest *tc) {
test_teardown(); test_teardown();
} }
static void test_paragraph(CuTest *tc) {
const char *toolong = "im Westen das Hochland von Geraldin (93,-303).";
const char *expect = "im Westen das Hochland von Geraldin (93,-303).\n";
char buf[256];
stream out = { 0 };
size_t len;
mstream_init(&out);
paragraph(&out, toolong, 0, 0, 0);
out.api->rewind(out.handle);
len = out.api->read(out.handle, buf, sizeof(buf));
buf[len] = '\0';
CuAssertStrEquals(tc, expect, buf);
}
static void test_paragraph_break(CuTest *tc) {
const char *toolong = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin (93,-303).";
const char *expect = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin\n(93,-303).\n";
char buf[256];
stream out = { 0 };
size_t len;
mstream_init(&out);
paragraph(&out, toolong, 0, 0, 0);
out.api->rewind(out.handle);
len = out.api->read(out.handle, buf, sizeof(buf));
buf[len] = '\0';
CuAssertStrEquals(tc, expect, buf);
}
static void test_pump_paragraph_toolong(CuTest *tc) { static void test_pump_paragraph_toolong(CuTest *tc) {
const char *toolong = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin (93,-303)."; const char *toolong = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin (93,-303).";
const char *expect = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin\n(93,-303).\n"; const char *expect = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin\n(93,-303).\n";
@ -404,6 +436,8 @@ CuSuite *get_report_suite(void)
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_write_spaces); SUITE_ADD_TEST(suite, test_write_spaces);
SUITE_ADD_TEST(suite, test_write_many_spaces); SUITE_ADD_TEST(suite, test_write_many_spaces);
SUITE_ADD_TEST(suite, test_paragraph);
SUITE_ADD_TEST(suite, test_paragraph_break);
SUITE_ADD_TEST(suite, test_pump_paragraph_toolong); SUITE_ADD_TEST(suite, test_pump_paragraph_toolong);
SUITE_ADD_TEST(suite, test_report_travelthru); SUITE_ADD_TEST(suite, test_report_travelthru);
SUITE_ADD_TEST(suite, test_report_region); SUITE_ADD_TEST(suite, test_report_region);