openMSX
StringReplacer_test.cc
Go to the documentation of this file.
1#include "catch.hpp"
2#include "StringReplacer.hh"
3
4TEST_CASE("StringReplacer")
5{
6 // up-to-4 strings is a special case
7 SECTION("no replacements") {
8 static constexpr auto replacer = StringReplacer::create();
9 CHECK(replacer("") == "");
10 CHECK(replacer("foo") == "foo");
11 CHECK(replacer("1234") == "1234");
12 }
13 SECTION("1 replacement") {
14 static constexpr auto replacer = StringReplacer::create(
15 "foo", "bar");
16 CHECK(replacer("") == "");
17 CHECK(replacer("foo") == "bar");
18 CHECK(replacer("1234") == "1234");
19 }
20 SECTION("2 replacements") {
21 static constexpr auto replacer = StringReplacer::create(
22 "foo", "bar",
23 "qux", "baz");
24 CHECK(replacer("") == "");
25 CHECK(replacer("foo") == "bar");
26 CHECK(replacer("qux") == "baz");
27 CHECK(replacer("Qux") == "Qux"); // case sensitive
28 CHECK(replacer("1234") == "1234");
29 }
30 SECTION("3 replacements") {
31 static constexpr auto replacer = StringReplacer::create(
32 "foo", "bar",
33 "qux", "baz",
34 "a", "b");
35 CHECK(replacer("") == "");
36 CHECK(replacer("foo") == "bar");
37 CHECK(replacer("qux") == "baz");
38 CHECK(replacer("a") == "b");
39 CHECK(replacer("1234") == "1234");
40 }
41 SECTION("4 replacements") {
42 static constexpr auto replacer = StringReplacer::create(
43 "foo", "bar",
44 "qux", "baz",
45 "a", "b",
46 "1", "one");
47 CHECK(replacer("") == "");
48 CHECK(replacer("foo") == "bar");
49 CHECK(replacer("qux") == "baz");
50 CHECK(replacer("a") == "b");
51 CHECK(replacer("1") == "one");
52 CHECK(replacer("1234") == "1234");
53 }
54 // more than 4 switches to a different internal implementation
55 SECTION("many replacements") {
56 static constexpr auto replacer = StringReplacer::create(
57 "1", "one",
58 "22", "two",
59 "333", "three",
60 "4444", "four",
61 "5", "five",
62 "6", "six",
63 "777", "seven",
64 "8", "eight",
65 "9", "nine",
66 "10101010", "ten");
67 CHECK(replacer("1") == "one");
68 CHECK(replacer("22") == "two");
69 CHECK(replacer("333") == "three");
70 CHECK(replacer("4444") == "four");
71 CHECK(replacer("5") == "five");
72 CHECK(replacer("6") == "six");
73 CHECK(replacer("777") == "seven");
74 CHECK(replacer("8") == "eight");
75 CHECK(replacer("9") == "nine");
76 CHECK(replacer("10101010") == "ten");
77
78 CHECK(replacer("") == "");
79 CHECK(replacer("foo") == "foo");
80 CHECK(replacer("11") == "11");
81 CHECK(replacer("7") == "7");
82 }
83}
TEST_CASE("StringReplacer")
CHECK(m3==m3)
constexpr auto create(Args ...args)