Commit ec04d952 authored by Alexander Semke's avatar Alexander Semke
Browse files

[maxima] remove the obsolete quotes in string variable values and properly...

[maxima] remove the obsolete quotes in string variable values and properly handle quoted sub-strings in string variables.
parent 02889ab3
Pipeline #211009 passed with stage
in 10 minutes and 35 seconds
......@@ -457,6 +457,16 @@ void MaximaExpression::parseResult(const QString& resultContent)
else
{
//no latex output is available, the actual result is part of the textContent string
// text output is quoted by Maxima, remove the quotes. No need to do it for internal
// commands to fetch the list of current variables, the proper parsing is done in MaximaVariableModel::parse().
if (!isInternal() && textContent.startsWith(QLatin1String("\"")))
{
textContent.remove(0, 1);
textContent.chop(1);
textContent.replace(QLatin1String("\\\""), QLatin1String("\""));
}
result = new Cantor::TextResult(textContent);
}
......
......@@ -117,6 +117,14 @@ QList<Cantor::DefaultVariableModel::Variable> parse(MaximaExpression* expr)
{
var.value=variableValues.at(i).trimmed();
var.value=var.value.remove(QLatin1String("\n")); //lists with many elements have line breaks, remove them
// text output is quoted by Maxima, remove the quotes
if (var.value.startsWith(QLatin1String("\"")))
{
var.value.remove(0, 1);
var.value.chop(1);
var.value.replace(QLatin1String("\\\""), QLatin1String("\""));
}
}
else
var.value=QLatin1String("unknown");
......
......@@ -398,22 +398,49 @@ void TestMaxima::testHelpRequest()
QVERIFY(e->results().size() == 2); //two results, the warning and the actual result of the calculation
}
void TestMaxima::testTextQuotes()
{
// check simple sting
auto* e1 = evalExp(QLatin1String("t1: \"test string\""));
QVERIFY(e1 != nullptr);
if(session()->status()==Cantor::Session::Running)
waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status)));
QVERIFY(e1->result() != nullptr);
QCOMPARE(e1->result()->type(), (int)Cantor::TextResult::Type );
QCOMPARE(e1->result()->data().toString(), QLatin1String("test string"));
// check string with quotes inside
auto* e2 = evalExp(QLatin1String("t2: \"this is a \\\"quoted string\\\"\""));
QVERIFY(e2 != nullptr);
if(session()->status()==Cantor::Session::Running)
waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status)));
QVERIFY(e2->result() != nullptr);
QCOMPARE(e2->result()->type(), (int)Cantor::TextResult::Type );
QCOMPARE(e2->result()->data().toString(), QLatin1String("this is a \"quoted string\""));
}
void TestMaxima::testVariableModel()
{
QAbstractItemModel* model = session()->variableModel();
QVERIFY(model != nullptr);
auto* e1=evalExp(QLatin1String("a: 15"));
auto* e2=evalExp(QLatin1String("a: 15; b: \"Hello, world!\""));
auto* e3=evalExp(QLatin1String("l: [1,2,3]"));
QVERIFY(e1!=nullptr);
QVERIFY(e2!=nullptr);
QVERIFY(e3!=nullptr);
auto* e1 = evalExp(QLatin1String("a: 15"));
auto* e2 = evalExp(QLatin1String("a: 15; b: \"Hello, world!\""));
auto* e3 = evalExp(QLatin1String("l: [1,2,3]"));
auto* e4 = evalExp(QLatin1String("t: \"this is a \\\"quoted string\\\"\""));
QVERIFY(e1 != nullptr);
QVERIFY(e2 != nullptr);
QVERIFY(e3 != nullptr);
QVERIFY(e4 != nullptr);
if(session()->status()==Cantor::Session::Running)
waitForSignal(session(), SIGNAL(statusChanged(Cantor::Session::Status)));
QCOMPARE(3, model->rowCount());
QCOMPARE(4, model->rowCount());
QVariant name = model->index(0,0).data();
QCOMPARE(name.toString(),QLatin1String("a"));
......@@ -425,13 +452,19 @@ void TestMaxima::testVariableModel()
QCOMPARE(name1.toString(),QLatin1String("b"));
QVariant value1 = model->index(1,1).data();
QCOMPARE(value1.toString(),QLatin1String("\"Hello, world!\""));
QCOMPARE(value1.toString(),QLatin1String("Hello, world!"));
QVariant name2 = model->index(2,0).data();
QCOMPARE(name2.toString(),QLatin1String("l"));
QVariant value2 = model->index(2,1).data();
QCOMPARE(value2.toString(),QLatin1String("[1,2,3]"));
QVariant name3 = model->index(3,0).data();
QCOMPARE(name3.toString(),QLatin1String("t"));
QVariant value3 = model->index(3,1).data();
QCOMPARE(value3.toString(),QLatin1String("this is a \"quoted string\""));
}
void TestMaxima::testLispMode01()
......
......@@ -61,6 +61,8 @@ private Q_SLOTS:
void testLispMode01();
void testTextQuotes();
void testLoginLogout();
void testRestartWhileRunning();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment