summaryrefslogtreecommitdiff
path: root/test/listformatter.cpp
blob: 3e58e6158677af5a6d1ba6da07b24f754ec0bb81 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "listformatter.h"

#include "3rd-party/catch.hpp"

using namespace newsboat;

TEST_CASE("add_line(), get_lines_count() and clear()",
	"[ListFormatter]")
{
	ListFormatter fmt;

	REQUIRE(fmt.get_lines_count() == 0);

	SECTION("add_line() adds a line") {
		fmt.add_line("one");
		REQUIRE(fmt.get_lines_count() == 1);

		fmt.add_line("two");
		REQUIRE(fmt.get_lines_count() == 2);

		SECTION("clear() removes all lines") {
			fmt.clear();
			REQUIRE(fmt.get_lines_count() == 0);
		}
	}
}

TEST_CASE("set_line() replaces the item in a list", "[ListFormatter]")
{
	ListFormatter fmt;

	fmt.add_line("hello");
	fmt.add_line("goodb");
	fmt.add_line("ye");

	std::string expected =
		"{list"
		"{listitem text:\"hello\"}"
		"{listitem text:\"goodb\"}"
		"{listitem text:\"ye\"}"
		"}";
	REQUIRE(fmt.format_list() == expected);

	fmt.set_line(1, "oh");

	expected =
		"{list"
		"{listitem text:\"hello\"}"
		"{listitem text:\"oh\"}"
		"{listitem text:\"ye\"}"
		"}";
	REQUIRE(fmt.format_list() == expected);
}

TEST_CASE("format_list() uses regex manager if one is passed",
	"[ListFormatter]")
{
	RegexManager rxmgr;
	ListFormatter fmt(&rxmgr, "article");

	fmt.add_line("Highlight me please!");

	// the choice of green text on red background does not reflect my
	// personal taste (or lack thereof) :)
	rxmgr.handle_action(
		"highlight", {"article", "please", "green", "default"});

	std::string expected =
		"{list"
		"{listitem text:\"Highlight me <0>please</>!\"}"
		"}";

	REQUIRE(fmt.format_list() == expected);
}