Commit 24b0365c authored by Alexander Semke's avatar Alexander Semke
Browse files

[octave] fixed multi-line expressions containing lines with comments only and...

[octave] fixed multi-line expressions containing lines with comments only and some other failing tests because of additional blanks that wrongly expected.
parent 04dda885
Pipeline #62792 passed with stage
in 24 minutes and 56 seconds
......@@ -126,6 +126,11 @@ QString OctaveExpression::internalCommand()
if (status != 3)
tmp += cmd[i];
}
//Remove "\n" in the beginning of the command, if present
while(tmp[0] == QLatin1Char('\n'))
tmp.remove(0, 1);
cmd = tmp;
cmd.replace(QLatin1String(";\n"), QLatin1String(";"));
cmd.replace(QLatin1Char('\n'), QLatin1Char(','));
......
......@@ -34,7 +34,7 @@ void TestOctave::testSimpleCommand()
QVERIFY( e!=nullptr );
QVERIFY( e->result()!=nullptr );
QCOMPARE( cleanOutput( e->result()->data().toString() ), QLatin1String("ans = 4") );
QCOMPARE( cleanOutput( e->result()->data().toString() ), QLatin1String("ans = 4") );
}
void TestOctave::testMultilineCommand()
{
......@@ -45,7 +45,7 @@ void TestOctave::testMultilineCommand()
QString result=e->result()->data().toString();
QCOMPARE( cleanOutput(result ), QLatin1String("a = 4\nb = 6") );
QCOMPARE( cleanOutput(result ), QLatin1String("a = 4\nb = 6") );
}
void TestOctave::testCommandQueue()
......@@ -62,9 +62,9 @@ void TestOctave::testCommandQueue()
QVERIFY(e2->result());
QVERIFY(e3->result());
QCOMPARE(cleanOutput(e1->result()->data().toString()), QLatin1String("ans = 1"));
QCOMPARE(cleanOutput(e2->result()->data().toString()), QLatin1String("ans = 2"));
QCOMPARE(cleanOutput(e3->result()->data().toString()), QLatin1String("ans = 3"));
QCOMPARE(cleanOutput(e1->result()->data().toString()), QLatin1String("ans = 1"));
QCOMPARE(cleanOutput(e2->result()->data().toString()), QLatin1String("ans = 2"));
QCOMPARE(cleanOutput(e3->result()->data().toString()), QLatin1String("ans = 3"));
}
void TestOctave::testVariableDefinition()
......@@ -98,16 +98,20 @@ void TestOctave::testMatrixDefinition()
));
}
void TestOctave::testSimpleExpressionWithComment()
//Comments
void TestOctave::testComment00()
{
Cantor::Expression* e = evalExp(QLatin1String("s = 1234 #This is comment"));
QVERIFY(e != nullptr);
QVERIFY(e->result() != nullptr);
QCOMPARE(cleanOutput(e->result()->data().toString()), QLatin1String("s = 1234"));
QCOMPARE(cleanOutput(e->result()->data().toString()), QLatin1String("s = 1234"));
}
void TestOctave::testCommentExpression()
/*!
* simple command containing one single comment only
*/
void TestOctave::testComment01()
{
Cantor::Expression* e = evalExp(QLatin1String("#Only comment"));
......@@ -116,7 +120,34 @@ void TestOctave::testCommentExpression()
QCOMPARE(e->results().size(), 0);
}
void TestOctave::testMultilineCommandWithComment()
/*!
* multi-line command with lines containing comments only
*/
void TestOctave::testComment02()
{
Cantor::Expression* e = evalExp(QLatin1String(
"# comment 1 \n"
"5 + 5\n"
"# comment 2\n"
"a = 10"
));
QVERIFY(e != nullptr);
QCOMPARE(e->status(), Cantor::Expression::Status::Done);
QVERIFY(e->result() != nullptr);
Cantor::TextResult* result = static_cast<Cantor::TextResult*>(e->result());
QVERIFY(result != nullptr);
QCOMPARE(cleanOutput(result->plain()), QLatin1String(
"ans = 10\n"
"a = 10"
));
}
/*!
* multi-line command with comments within the line containing also the actual expression
* */
void TestOctave::testComment03()
{
Cantor::Expression* e = evalExp(QLatin1String(
"a = 2+4 \n"
......@@ -132,10 +163,10 @@ void TestOctave::testMultilineCommandWithComment()
Cantor::TextResult* result = static_cast<Cantor::TextResult*>(e->result());
QVERIFY(result != nullptr);
QCOMPARE(cleanOutput(result->plain()), QLatin1String(
"a = 6\n"
"ans = 3\n"
"a = 6\n"
"ans = 3\n"
"q = Str\n"
"b = 4"
"b = 4"
));
}
......@@ -147,7 +178,6 @@ void TestOctave::testCompletion()
// Checks some completions for this request (but not all)
// This correct for Octave 4.2.2 at least (and another versions, I think)
const QStringList& completions = help->completions();
qDebug() << completions;
QVERIFY(completions.contains(QLatin1String("asin")));
QVERIFY(completions.contains(QLatin1String("asctime")));
QVERIFY(completions.contains(QLatin1String("asec")));
......@@ -302,7 +332,7 @@ void TestOctave::testRestartWhileRunning()
QVERIFY(e2 != nullptr);
QVERIFY(e2->result() != nullptr);
QCOMPARE(cleanOutput(e2->result()->data().toString() ), QLatin1String("ans = 4"));
QCOMPARE(cleanOutput(e2->result()->data().toString() ), QLatin1String("ans = 4"));
}
QTEST_MAIN( TestOctave )
......
......@@ -28,10 +28,11 @@ private Q_SLOTS:
void testVariableDefinition();
void testMatrixDefinition();
//some tests to see if comments are working correctly
void testSimpleExpressionWithComment();
void testCommentExpression();
void testMultilineCommandWithComment();
//comments
void testComment00();
void testComment01();
void testComment02();
void testComment03();
//tests a syntax error (not closing bracket)
void testInvalidSyntax();
......
Markdown is supported
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