blob: 6c8b89e328f0912bbf8d5f22a708d957437e2857 (
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
|
#include "catch.hpp"
#include <formatstring.h>
using namespace newsboat;
TEST_CASE("do_format replaces variables with values", "[fmtstr_formatter]") {
fmtstr_formatter fmt;
SECTION("One format variable") {
fmt.register_fmt('a',"AAA");
SECTION("Conditional format strings") {
REQUIRE(fmt.do_format("%?a?%a&no?") == "AAA");
REQUIRE(fmt.do_format("%?b?%b&no?") == "no");
REQUIRE(fmt.do_format("%?a?[%-4a]&no?") == "[AAA ]");
}
SECTION("Two format variables") {
fmt.register_fmt('b',"BBB");
REQUIRE(fmt.do_format("asdf | %a | %?c?%a%b&%b%a? | qwert") == "asdf | AAA | BBBAAA | qwert");
REQUIRE(fmt.do_format("%?c?asdf?") == "");
SECTION("Three format variables") {
fmt.register_fmt('c',"CCC");
SECTION("Simple cases") {
REQUIRE(fmt.do_format("") == "");
// illegal single %
REQUIRE(fmt.do_format("%") == "");
REQUIRE(fmt.do_format("%%") == "%");
REQUIRE(fmt.do_format("%a%b%c") == "AAABBBCCC");
REQUIRE(fmt.do_format("%%%a%%%b%%%c%%") == "%AAA%BBB%CCC%");
}
SECTION("Alignment") {
REQUIRE(fmt.do_format("%4a") == " AAA");
REQUIRE(fmt.do_format("%-4a") == "AAA ");
SECTION("Alignment limits") {
REQUIRE(fmt.do_format("%2a") == "AA");
REQUIRE(fmt.do_format("%-2a") == "AA");
}
}
SECTION("Complex format string") {
REQUIRE(fmt.do_format("<%a> <%5b> | %-5c%%") == "<AAA> < BBB> | CCC %");
REQUIRE(fmt.do_format("asdf | %a | %?c?%a%b&%b%a? | qwert") == "asdf | AAA | AAABBB | qwert");
}
SECTION("Format string fillers") {
REQUIRE(fmt.do_format("%>X", 3) == "XXX");
REQUIRE(fmt.do_format("%a%> %b", 10) == "AAA BBB");
REQUIRE(fmt.do_format("%a%> %b", 0) == "AAA BBB");
}
SECTION("Conditional format string") {
REQUIRE(fmt.do_format("%?c?asdf?") == "asdf");
}
}
}
}
}
|