Add coverage and remove deprecated WideInput.

This commit is contained in:
ArthurSonzogni 2022-04-27 11:33:42 +02:00
parent 5ba301d316
commit 114cbfcffd
7 changed files with 61 additions and 99 deletions

View File

@ -38,6 +38,8 @@ current (development)
- Add the `Maybe` decorator.
- Add the `CatchEvent` decorator.
- Add the `Renderer` decorator.
- **breaking** remove the "deprectated.hpp" header and Input support for wide
string.
### DOM:
- **breaking**: The `inverted` decorator now toggle in the inverted attribute.

View File

@ -23,6 +23,8 @@ if(NOT googletest_POPULATED)
endif()
add_executable(tests
src/ftxui/component/animation_test.cpp
src/ftxui/component/component_test.cpp
src/ftxui/component/component_test.cpp
src/ftxui/component/container_test.cpp
src/ftxui/component/input_test.cpp

View File

@ -93,9 +93,6 @@ Component Collapsible(ConstStringRef label,
Ref<bool> show = false);
} // namespace ftxui
// Include component using the old deprecated wstring.
#include "ftxui/component/deprecated.hpp"
#endif /* end of include guard: FTXUI_COMPONENT_HPP */
// Copyright 2021 Arthur Sonzogni. All rights reserved.

View File

@ -1,18 +0,0 @@
#ifndef FTXUI_COMPONENT_DEPRECATED_HPP
#define FTXUI_COMPONENT_DEPRECATED_HPP
#include "ftxui/component/component.hpp"
namespace ftxui {
[[deprecated("use Input with normal std::string instead.")]] Component Input(
WideStringRef content,
ConstStringRef placeholder,
Ref<InputOption> option = {});
} // namespace ftxui
#endif /* FTXUI_COMPONENT_DEPRECATED_HPP */
// Copyright 2021 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.

View File

@ -55,23 +55,6 @@ class StringRef {
std::string* address_ = nullptr;
};
/// @brief An adapter. Own or reference a constant string. For convenience, this
/// class convert multiple mutable string toward a shared representation.
class WideStringRef {
public:
WideStringRef(std::wstring* ref) : address_(ref) {}
WideStringRef(std::wstring ref) : owned_(std::move(ref)) {}
WideStringRef(const wchar_t* ref) : WideStringRef(std::wstring(ref)) {}
WideStringRef(const char* ref)
: WideStringRef(to_wstring(std::string(ref))) {}
std::wstring& operator*() { return address_ ? *address_ : owned_; }
std::wstring* operator->() { return address_ ? address_ : &owned_; }
private:
std::wstring owned_;
std::wstring* address_ = nullptr;
};
/// @brief An adapter. Own or reference a constant string. For convenience, this
/// class convert multiple immutable string toward a shared representation.
class ConstStringRef {

View File

@ -0,0 +1,56 @@
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult
#include <memory> // for shared_ptr, __shared_ptr_access, allocator, make_shared
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Make
#include "ftxui/component/component_base.hpp" // for ComponentBase, Component
#include "gtest/gtest_pred_impl.h" // for EXPECT_EQ, Test, SuiteApiResolver, TEST, TestFactoryImpl
namespace ftxui {
TEST(AnimationTest, StartAndEnd) {
std::vector<animation::easing::Function> functions = {
animation::easing::Linear,
animation::easing::QuadraticIn,
animation::easing::QuadraticOut,
animation::easing::QuadraticInOut,
animation::easing::CubicIn,
animation::easing::CubicOut,
animation::easing::CubicInOut,
animation::easing::QuarticIn,
animation::easing::QuarticOut,
animation::easing::QuarticInOut,
animation::easing::QuinticIn,
animation::easing::QuinticOut,
animation::easing::QuinticInOut,
animation::easing::SineIn,
animation::easing::SineOut,
animation::easing::SineInOut,
animation::easing::CircularIn,
animation::easing::CircularOut,
animation::easing::CircularInOut,
animation::easing::ExponentialIn,
animation::easing::ExponentialOut,
animation::easing::ExponentialInOut,
animation::easing::ElasticIn,
animation::easing::ElasticOut,
animation::easing::ElasticInOut,
animation::easing::BackIn,
animation::easing::BackOut,
animation::easing::BackInOut,
animation::easing::BounceIn,
animation::easing::BounceOut,
animation::easing::BounceInOut,
};
for (auto& it : functions) {
EXPECT_NEAR(0.f, it(0.f), 1.0e-4);
EXPECT_NEAR(1.f, it(1.f), 1.0e-4);
}
}
} // namespace ftxui
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.

View File

@ -10,7 +10,6 @@
#include "ftxui/component/component.hpp" // for Make, Input
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for InputOption
#include "ftxui/component/deprecated.hpp" // for Input
#include "ftxui/component/event.hpp" // for Event, Event::ArrowLeft, Event::ArrowRight, Event::Backspace, Event::Custom, Event::Delete, Event::End, Event::Home, Event::Return
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Pressed
#include "ftxui/component/screen_interactive.hpp" // for Component
@ -18,7 +17,7 @@
#include "ftxui/screen/box.hpp" // for Box
#include "ftxui/screen/string.hpp" // for GlyphPosition, GlyphCount, to_string, CellToGlyphIndex, to_wstring
#include "ftxui/screen/util.hpp" // for clamp
#include "ftxui/util/ref.hpp" // for StringRef, Ref, WideStringRef, ConstStringRef
#include "ftxui/util/ref.hpp" // for StringRef, Ref, ConstStringRef
namespace ftxui {
@ -236,36 +235,6 @@ class InputBase : public ComponentBase {
Ref<InputOption> option_;
};
// An input box. The user can type text into it.
// For convenience, the std::wstring version of Input simply wrap a
// InputBase.
class WideInputBase : public InputBase {
public:
WideInputBase(WideStringRef content,
ConstStringRef placeholder,
Ref<InputOption> option)
: InputBase(&wrapped_content_, std::move(placeholder), std::move(option)),
content_(std::move(content)),
wrapped_content_(to_string(*content_)) {}
Element Render() override {
wrapped_content_ = to_string(*content_);
return InputBase::Render();
}
bool OnEvent(Event event) override {
wrapped_content_ = to_string(*content_);
if (InputBase::OnEvent(event)) {
*content_ = to_wstring(wrapped_content_);
return true;
}
return false;
}
WideStringRef content_;
std::string wrapped_content_;
};
} // namespace
/// @brief An input box for editing text.
@ -297,35 +266,6 @@ Component Input(StringRef content,
std::move(option));
}
/// @brief . An input box for editing text.
/// @param content The editable content.
/// @param placeholder The text displayed when content is still empty.
/// @param option Additional optional parameters.
/// @ingroup component
/// @see InputBase
///
/// ### Example
///
/// ```cpp
/// auto screen = ScreenInteractive::FitComponent();
/// std::string content= "";
/// std::string placeholder = "placeholder";
/// Component input = Input(&content, &placeholder);
/// screen.Loop(input);
/// ```
///
/// ### Output
///
/// ```bash
/// placeholder
/// ```
Component Input(WideStringRef content,
ConstStringRef placeholder,
Ref<InputOption> option) {
return Make<WideInputBase>(std::move(content), std::move(placeholder),
std::move(option));
}
} // namespace ftxui
// Copyright 2020 Arthur Sonzogni. All rights reserved.