diff --git a/CMakeLists.txt b/CMakeLists.txt index 18c0689..c78f1ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/ftxui/component/event_test.cpp b/src/ftxui/component/event_test.cpp new file mode 100644 index 0000000..d17866c --- /dev/null +++ b/src/ftxui/component/event_test.cpp @@ -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 receiver, Sender 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 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(); + auto char_sender = char_receiver->MakeSender(); + + auto event_receiver = MakeReceiver(); + 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)); +}