Files
Upsilon/escher/test/clipboard.cpp
Arthur Camouseigt ea36c6e5d7 [Clipboard] Changed the general copy/paste
Fixed issues due to copy/paste of empty formulas. When pasted, empty
formulas are now recognized by the parser and apear with the
correct layout

Without this process, copying an empty integral then pasting it gives :
int((), x, (), ()) instead of drawing an empty integral

Change-Id: I680aaf4eea953149e2d57efa8153ab4d3f93e2a7
2020-11-04 15:32:59 +01:00

49 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <quiz.h>
#include <string.h>
#include <poincare_layouts.h>
#include <poincare/expression.h>
#include <escher/clipboard.h>
void assert_clipboard_enters_and_exits_python(const char * string, const char * stringResult) {
Clipboard * clipboard = Clipboard::sharedClipboard();
clipboard->store(string);
clipboard->enterPython();
quiz_assert(strcmp(clipboard->storedText(), stringResult) == 0);
clipboard->exitPython();
quiz_assert(strcmp(clipboard->storedText(), string) == 0);
}
QUIZ_CASE(escher_clipboard_enters_and_exits_python) {
assert_clipboard_enters_and_exits_python("4×4", "4*4");
assert_clipboard_enters_and_exits_python("^(ln(4))", "exp(log(4))");
assert_clipboard_enters_and_exits_python("ln(log(ln(π)))^𝐢", "log(log10(log(pi)))**1j");
assert_clipboard_enters_and_exits_python("√(1ᴇ10)", "sqrt(1e10)");
assert_clipboard_enters_and_exits_python("1×𝐢^2", "1*1j**2");
assert_clipboard_enters_and_exits_python("12^(1/4)×(π/6)×(12×π)^(1/4)", "12**(1/4)*(pi/6)*(12*pi)**(1/4)");
}
using namespace Poincare;
void assert_stored_text_is_parseable(Poincare::Layout layout) {
constexpr int bufferSize = 500;
char buffer[bufferSize];
layout.serializeForParsing(buffer, bufferSize);
Clipboard * clipboard = Clipboard::sharedClipboard();
clipboard->store(buffer);
Expression e = Expression::Parse(clipboard->storedText(), nullptr, false);
Layout result = e.createLayout(Preferences::sharedPreferences()->displayMode(), Poincare::PrintFloat::k_numberOfStoredSignificantDigits);
quiz_assert(layout.isIdenticalTo(result));
}
QUIZ_CASE(escher_clipboard_stored_text_is_parseable) {
Layout l = IntegralLayout::Builder(EmptyLayout::Builder(), CodePointLayout::Builder('x'), EmptyLayout::Builder(), EmptyLayout::Builder());
assert_stored_text_is_parseable(l);
l = NthRootLayout::Builder(EmptyLayout::Builder());
assert_stored_text_is_parseable(l);
l = MatrixLayout::Builder(CodePointLayout::Builder('1'), EmptyLayout::Builder(), EmptyLayout::Builder(), CodePointLayout::Builder('2'));
assert_stored_text_is_parseable(l);
l = SumLayout::Builder(EmptyLayout::Builder(), CodePointLayout::Builder('n'), EmptyLayout::Builder(), EmptyLayout::Builder());
assert_stored_text_is_parseable(l);
l = SumLayout::Builder(EmptyLayout::Builder(), CodePointLayout::Builder('n'), EmptyLayout::Builder(), EmptyLayout::Builder());
assert_stored_text_is_parseable(l);;
}