blob: 6fdc8afeeabe4de844a581eadbdbe759fd1d5db3 (
plain)
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
|
#include <catch2/catch_test_macros.hpp>
#include <string_view> // IWYU pragma: keep
#include <variant>
#include <vector>
import ttwhy.scanners;
using namespace std::string_view_literals;
[[nodiscard]] constexpr auto static is_character(ttwhy::scanners::input_event & event, char expected) -> bool
{
auto const * data = std::get_if<ttwhy::scanners::character_event>(&event);
return data != nullptr && data->value == expected;
}
SCENARIO("The ANSI scanner processes printable ASCII and standard C0 control characters", "[scanner][ansi]")
{
GIVEN("An initialized scanner and event sink")
{
auto queue = std::vector<ttwhy::scanners::input_event>{};
auto sink = [&queue](auto const & event) {
queue.push_back(event);
};
auto scanner = ttwhy::scanners::ansi{sink};
WHEN("Processing a standard printable character")
{
scanner.process("A");
THEN("It yields a single character event")
{
REQUIRE(queue.size() == 1);
CHECK(is_character(queue.at(0), 'A'));
}
}
}
}
|