2024-08-16 11:19:51 +02:00
|
|
|
// Copyright 2023 Arthur Sonzogni. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
|
// the LICENSE file.
|
|
|
|
|
|
2024-05-15 18:23:59 +02:00
|
|
|
#include "ftxui/util/ref.hpp"
|
|
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
#include "ftxui/component/component.hpp"
|
|
|
|
|
|
|
|
|
|
namespace ftxui {
|
|
|
|
|
namespace {
|
|
|
|
|
class Adapter : public ConstStringListRef::Adapter {
|
|
|
|
|
public:
|
|
|
|
|
Adapter(std::vector<std::string>& entries) : entries(entries) {}
|
|
|
|
|
size_t size() const override { return entries.size() * 2; }
|
2025-12-13 11:22:11 -08:00
|
|
|
std::string_view operator[](size_t index) const override {
|
2024-05-15 18:23:59 +02:00
|
|
|
return entries[index / 2];
|
|
|
|
|
}
|
|
|
|
|
std::vector<std::string>& entries;
|
|
|
|
|
};
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
TEST(ConstStringListRef, Copy) {
|
|
|
|
|
std::vector<std::string> entries = {
|
|
|
|
|
"entry 1",
|
|
|
|
|
"entry 2",
|
|
|
|
|
"entry 3",
|
|
|
|
|
};
|
|
|
|
|
int selected = 0;
|
|
|
|
|
auto menu = Menu(entries, &selected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ConstStringListRef, Ref) {
|
|
|
|
|
std::vector<std::string> entries = {
|
|
|
|
|
"entry 1",
|
|
|
|
|
"entry 2",
|
|
|
|
|
"entry 3",
|
|
|
|
|
};
|
|
|
|
|
int selected = 0;
|
|
|
|
|
auto menu = Menu(&entries, &selected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ConstStringListRef, Adapter) {
|
|
|
|
|
std::vector<std::string> entries = {
|
|
|
|
|
"entry 1",
|
|
|
|
|
"entry 2",
|
|
|
|
|
"entry 3",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int selected = 0;
|
|
|
|
|
Adapter a(entries);
|
|
|
|
|
auto menu = Menu(&a, &selected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ConstStringListRef, UniquePtrAdapter) {
|
|
|
|
|
std::vector<std::string> entries = {
|
|
|
|
|
"entry 1",
|
|
|
|
|
"entry 2",
|
|
|
|
|
"entry 3",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int selected = 0;
|
|
|
|
|
auto a = std::make_unique<Adapter>(entries);
|
|
|
|
|
auto menu = Menu(std::move(a), &selected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ftxui
|