Skip to content
Snippets Groups Projects
Select Git revision
  • eed7e2ea7046fcef2de15e18a24735d8adc46c4a
  • main default protected
2 results

scroll_indicator_test.cpp

Blame
  • scroll_indicator_test.cpp 6.14 KiB
    #include <gtest/gtest.h>
    #include <memory>   // for shared_ptr
    #include <string>   // for allocator, to_string, string
    #include <utility>  // for move
    
    #include "ftxui/dom/elements.hpp"  // for operator|, Element, operator|=, text, vbox, Elements, border, focus, frame, vscroll_indicator
    #include "ftxui/dom/node.hpp"      // for Render
    #include "ftxui/screen/screen.hpp"  // for Screen
    
    // NOLINTBEGIN
    namespace ftxui {
    
    namespace {
    Element MakeVerticalList(int focused_index, int n) {
      Elements list;
      for (int i = 0; i < n; ++i) {
        auto element = text(std::to_string(i));
        if (i == focused_index) {
          element |= focus;
        }
        list.push_back(element);
      }
      return vbox(std::move(list)) | vscroll_indicator | frame | border;
    }
    
    std::string PrintVerticalList(int focused_index, int n) {
      auto element = MakeVerticalList(focused_index, n);
      Screen screen(6, 6);
      Render(screen, element);
      return screen.ToString();
    }
    
    }  // namespace
    
    TEST(ScrollIndicator, Basic) {
      EXPECT_EQ(PrintVerticalList(0, 10),
                "╭────╮\r\n"
                "│0  ┃│\r\n"
                "│1  ┃│\r\n"
                "│2   │\r\n"
                "│3   │\r\n"
                "╰────╯");
      EXPECT_EQ(PrintVerticalList(1, 10),
                "╭────╮\r\n"
                "│0  ┃│\r\n"
                "│1  ┃│\r\n"
                "│2   │\r\n"
                "│3   │\r\n"
                "╰────╯");
      EXPECT_EQ(PrintVerticalList(2, 10),
                "╭────╮\r\n"
                "│1  ┃│\r\n"
                "│2  ┃│\r\n"
                "│3   │\r\n"
                "│4   │\r\n"
                "╰────╯");
      EXPECT_EQ(PrintVerticalList(3, 10),
                "╭────╮\r\n"
                "│2  ╻│\r\n"
                "│3  ┃│\r\n"
                "│4  ╹│\r\n"
                "│5   │\r\n"
                "╰────╯");
      EXPECT_EQ(PrintVerticalList(4, 10),
                "╭────╮\r\n"
                "│3   │\r\n"
                "│4  ┃│\r\n"
                "│5  ┃│\r\n"
                "│6   │\r\n"
                "╰────╯");