Add regression test for issue 31.

See https://github.com/ArthurSonzogni/FTXUI/issues/31

Due to a bug fixed by:
https://github.com/ArthurSonzogni/FTXUI/pull/32
the character 'P' was not correctly converted into event.
This commit is contained in:
ArthurSonzogni 2020-07-23 20:41:25 +02:00 committed by Arthur Sonzogni
parent d1d7a73b2d
commit 8f87fc96ac
2 changed files with 52 additions and 2 deletions

View File

@ -174,10 +174,11 @@ if (FTXUI_BUILD_TESTS AND ${CMAKE_VERSION} VERSION_GREATER "3.11.4")
endif()
add_executable(tests
src/ftxui/component/toggle_test.cpp
src/ftxui/component/radiobox_test.cpp
src/ftxui/component/container_test.cpp
src/ftxui/component/event_test.cpp
src/ftxui/component/radiobox_test.cpp
src/ftxui/component/receiver_test.cpp
src/ftxui/component/toggle_test.cpp
src/ftxui/dom/gauge_test.cpp
src/ftxui/dom/hbox_test.cpp
src/ftxui/dom/text_test.cpp

View File

@ -0,0 +1,49 @@
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include "ftxui/component/event.hpp"
#include "ftxui/component/receiver.hpp"
#include "gtest/gtest.h"
using namespace ftxui;
namespace {
// Produce a stream of Event from a stream of char.
void CharToEventStream(Receiver<char> receiver, Sender<Event> sender) {
char c;
while (receiver->Receive(&c))
Event::Convert(receiver, sender, c);
}
} // namespace
// Test char |c| to are trivially converted into |Event::Character(c)|.
TEST(Event, Character) {
std::vector<char> basic_char;
for (char c = 'a'; c < 'z'; ++c)
basic_char.push_back(c);
for (char c = 'A'; c < 'Z'; ++c)
basic_char.push_back(c);
auto char_receiver = MakeReceiver<char>();
auto char_sender = char_receiver->MakeSender();
auto event_receiver = MakeReceiver<Event>();
auto event_sender = event_receiver->MakeSender();
for (char c : basic_char)
char_sender->Send(c);
char_sender.reset();
CharToEventStream(std::move(char_receiver), std::move(event_sender));
Event received;
for (char c : basic_char) {
EXPECT_TRUE(event_receiver->Receive(&received));
EXPECT_TRUE(received.is_character());
EXPECT_EQ(c, received.character());
}
EXPECT_FALSE(event_receiver->Receive(&received));
}