mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-12-16 01:48:56 +08:00
Some checks failed
Build / Bazel, cl, windows-latest (push) Has been cancelled
Build / Bazel, clang++, macos-latest (push) Has been cancelled
Build / Bazel, clang++, ubuntu-latest (push) Has been cancelled
Build / Bazel, g++, macos-latest (push) Has been cancelled
Build / Bazel, g++, ubuntu-latest (push) Has been cancelled
Build / CMake, cl, windows-latest (push) Has been cancelled
Build / CMake, gcc, ubuntu-latest (push) Has been cancelled
Build / CMake, llvm, ubuntu-latest (push) Has been cancelled
Build / CMake, llvm, macos-latest (push) Has been cancelled
Build / Test modules (llvm, ubuntu-latest) (push) Has been cancelled
Documentation / documentation (push) Has been cancelled
This is better ergonomic, as `std::string_view` is lightweight and accept more conversion than `const std::string&`. Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
68 lines
1.5 KiB
C++
68 lines
1.5 KiB
C++
// 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.
|
|
|
|
#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; }
|
|
std::string_view operator[](size_t index) const override {
|
|
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
|