void QDocumentSearchTest::searchAndFolding(){ QFETCH(QString, editorText); QFETCH(QList<int>, foldAt); QFETCH(QList<int>, hiddenLines); QFETCH(int, searchFrom); QFETCH(QString, searchText); QFETCH(int, options); QFETCH(CM, movement); QFETCH(QList<int>, hiddenLinesAfterwards); for (int loop=0;loop<2;loop++){ ed->document()->setText(editorText); foreach (const int i, foldAt) ed->document()->collapse(i); for (int i=0;i<ed->document()->lines();i++) QVERIFY(ed->document()->line(i).isHidden()==hiddenLines.contains(i)); ds->setCursor(ed->document()->cursor(searchFrom)); ds->setOptions((QDocumentSearch::Options)(options|(loop?QDocumentSearch::HighlightAll:0))); //highlighting shouldn't change anything ds->setSearchText(searchText); int foundCount=ds->next(movement.dir); QEQUAL(ds->cursor().lineNumber(),movement.l); QEQUAL(ds->cursor().columnNumber(),movement.cx); QEQUAL(ds->cursor().anchorColumnNumber(),movement.ax); for (int i=0;i<ed->document()->lines();i++) QVERIFY2(ed->document()->line(i).isHidden()==hiddenLinesAfterwards.contains(i),qPrintable(QString::number(i))); QEQUAL(foundCount, 1); } }
void QEditorTest::setText(){ Q_ASSERT(editor); QFETCH(QString, text); editor->setText(text, false); QString restext = editor->text(); QEQUAL(restext,text); }
void QDocumentSearchTest::replaceAll(){ QFETCH(QString, editorText); QFETCH(QString, searchText); QFETCH(QString, replaceText); QFETCH(int, options); options |= QDocumentSearch::Silent ; options |= QDocumentSearch::Replace; QFETCH(bool, dir); QFETCH(bool, wrapAround); QFETCH(int, scopey); QFETCH(int, scopex); QFETCH(int, scopey2); QFETCH(int, scopex2); QFETCH(int, sy); QFETCH(int, sx); QFETCH(QString, newtext); QFETCH(int, foundCount); for (int loop=0; loop<2; loop++){ ed->document()->setText(editorText); ds->setSearchText(searchText); ds->setReplaceText(replaceText); if (loop) options|=QDocumentSearch::HighlightAll; //highlighting shouldn't change anything ds->setOptions((QDocumentSearch::Options)options); ds->setCursor(ed->document()->cursor(sy,sx)); ds->setScope(ed->document()->cursor(scopey,scopex,scopey2,scopex2)); int count=ds->next(dir, true, false, wrapAround); QVERIFY2(ed->document()->text()== newtext,qPrintable(QString("%1 != %2 loop: %3, dir: %4").arg(ed->document()->text()).arg(newtext).arg(loop).arg(dir))); QEQUAL(count, foundCount); } }
//tests if folded text can be edited void QEditorTest::activeFolding(){ QFETCH(QString, editorText); QFETCH(QList<int>, foldAt); QFETCH(QList<int>, hiddenLines); QFETCH(int, cursorAL); QFETCH(int, cursorAC); QFETCH(int, cursorL); QFETCH(int, cursorC); QFETCH(QString, textToInsert); QFETCH(QString, newEditorText); QFETCH(QList<int>, newHiddenLines); editor->setText(editorText, false); foreach(const int &i, foldAt) editor->document()->collapse(i); for (int i=0;i<editor->document()->lines();i++) QVERIFY2(editor->document()->line(i).isHidden() == hiddenLines.contains(i),qPrintable(QString::number(i))); compareLists(editor->document()->impl()->testGetHiddenLines(), hiddenLines); QDocumentCursor editCursor = editor->document()->cursor(cursorAL,cursorAC,cursorL,cursorC); editCursor.insertText(textToInsert); QEQUAL(editor->document()->text(), newEditorText); for (int i=0;i<editor->document()->lines();i++) QVERIFY2(editor->document()->line(i).isHidden() == newHiddenLines.contains(i),qPrintable(QString::number(i))); compareLists(editor->document()->impl()->testGetHiddenLines(), newHiddenLines); }
void SyntaxCheckTest::checktabular(){ QFETCH(QString, text); QFETCH(int, row); QFETCH(int, col); QFETCH(QString, expectedMessage); expectedMessage = QApplication::translate("SyntaxCheck", qPrintable(expectedMessage)); bool inlineSyntaxChecking = edView->getConfig()->inlineSyntaxChecking; bool realtimeChecking = edView->getConfig()->realtimeChecking; edView->getConfig()->inlineSyntaxChecking = edView->getConfig()->realtimeChecking = true; edView->editor->setText(text, false); do{ edView->SynChecker.waitForQueueProcess(); // wait for syntax checker to finish (as it runs in a parallel thread) QApplication::processEvents(QEventLoop::AllEvents,10); // SyntaxChecker posts events for rechecking other lines }while(edView->SynChecker.queuedLines()); StackEnvironment env; edView->getEnv(row,env); QString message=edView->SynChecker.getErrorAt(edView->document->line(row).handle(),col,env); QEQUAL(message, expectedMessage); edView->getConfig()->inlineSyntaxChecking = inlineSyntaxChecking; edView->getConfig()->realtimeChecking = realtimeChecking; }
//checks if block-commands (e.g indent, comment) work with folded text void QEditorTest::foldedText(){ QFETCH(QString, editorText); QFETCH(QList<int>, foldAt); QFETCH(QList<int>, hiddenLines); QFETCH(int, froml); QFETCH(int, fromc); QFETCH(int, tol); QFETCH(int, toc); QFETCH(QString, operation); QFETCH(QString, newEditorText); QFETCH(QList<int>, newHiddenLines); editor->setText(editorText, false); foreach(const int &i, foldAt) editor->document()->collapse(i); for (int i=0;i<editor->document()->lines();i++) QVERIFY2(editor->document()->line(i).isHidden() == hiddenLines.contains(i),qPrintable(QString::number(i))); compareLists(editor->document()->impl()->testGetHiddenLines(), hiddenLines); editor->setCursor(editor->document()->cursor(froml,fromc,tol,toc)); if (operation=="indent") editor->indentSelection(); else if (operation=="unindent") editor->unindentSelection(); else if (operation=="comment") editor->commentSelection(); else if (operation=="uncomment") editor->uncommentSelection(); else qFatal("invalid operation"); QEQUAL(editor->document()->text(), newEditorText); for (int i=0;i<editor->document()->lines();i++) QVERIFY2(editor->document()->line(i).isHidden() == newHiddenLines.contains(i),qPrintable(QString::number(i))); compareLists(editor->document()->impl()->testGetHiddenLines(), newHiddenLines); }
void compareLists(const QList<int> actual, const QList<int> exp){ if (actual.length() != exp.length()) { QFAIL(qPrintable(QString("length %1 != %2 ").arg(actual.length()).arg(exp.length()))); return; } for (int i=0;i<actual.length();i++) QEQUAL(actual[i],exp[i]); }
void QDocumentCursorTest::const2Methods(){ QFETCH(QString, tc1); QFETCH(QString, tc2); QFETCH(bool,eq); QFETCH(bool,neq); QFETCH(bool,lt); QFETCH(bool,gt); QFETCH(bool,lteq); QFETCH(bool,gteq); QFETCH(bool,c1withinc2); QFETCH(QString,intersection); QDocumentCursor c1=str2cur(tc1); QDocumentCursor c2=str2cur(tc2); QVERIFY(!c1.isNull()); QVERIFY(c1.isValid()); QVERIFY(!c2.isNull()); QVERIFY(c2.isValid()); QVERIFY(c1==c1); QVERIFY(c2==c2); QVERIFY(c1<=c1); QVERIFY(c2<=c2); QVERIFY(c1>=c1); QVERIFY(c2>=c2); QEQUAL(c1==c2, eq); QEQUAL(c1!=c2, neq); QEQUAL(c1<c2, lt); QEQUAL(c1>c2, gt); QEQUAL(c1<=c2, lteq); QEQUAL(c1>=c2, gteq); QEQUAL(c1.isWithinSelection(c2), c1withinc2); QCEEQUAL(c1.intersect(c2),str2cur(intersection)); }
void ScriptEngineTest::script(){ QFETCH(QString, script); QFETCH(QString, newText); scriptengine eng(0); eng.setEditorView(edView); eng.setScript(script); eng.run(); QEQUAL(edView->editor->document()->text(), newText); }
void QEditorTest::autoClosing(){ QFETCH(QString, baseText); QFETCH(int, line); QFETCH(int, col); QFETCH(QString, insert); QFETCH(QString, result); editor->setText(baseText, false); QDocumentCursor c=editor->document()->cursor(line,col); editor->insertText(c, insert); QEQUAL(editor->document()->text(), result); }
void QDocumentLineTest::updateWrap(){ QFETCH(QString, line); QFETCH(int, width); QString temp=line; temp.replace("|",""); doc->setText(temp+"\n\n\n"); doc->setWidthConstraint(width); QString fExp, fGot; QList<int> frontiers; for (int i=0;i<line.size();i++) if (line.at(i)=='|') frontiers << (i - frontiers.size()); foreach(const int p, frontiers) fExp += QString("<%1:%2>").arg(p).arg(p*5); foreach(const IntPair& p, doc->line(0).handle()->m_frontiers) fGot += QString("<%1:%2>").arg(p.first).arg(p.second); QEQUAL(fGot, fExp); //-------test hard line wrap---- QList<QDocumentLineHandle*> handles; for (int i=0;i<doc->lines();i++) handles << doc->line(i).handle(); doc->applyHardLineWrap(handles); QStringList hlw = line.split('|'); QString indent; for (int i=0;i<hlw.first().length();i++) if (hlw.first()[i].isSpace()) indent += hlw.first()[i]; else break; if (indent == hlw.first()) indent = ""; for (int i=1;i<hlw.size();i++) hlw[i] = indent + hlw[i]; hlw << "" << "" << ""; QEQUAL(doc->text(), hlw.join("\n")); }
void QEditorTest::indentation(){ QFETCH(QString, baseText); QFETCH(bool, weak); QFETCH(int, line); QFETCH(int, col); QFETCH(QString, insert); QFETCH(QString, result); editor->setFlag(QEditor::WeakIndent,weak); editor->setText(baseText, false); QDocumentCursor c=editor->document()->cursor(line,col); editor->insertText(c, insert); QEQUAL(editor->document()->text(), result); }
void QDocumentLineTest::updateWrap(){ QFETCH(QString, line); QFETCH(int, width); QString temp=line; temp.replace("|",""); doc->setText(temp+"\n\n\n"); doc->setWidthConstraint(width); QString fExp, fGot; QList<int> frontiers; for (int i=0;i<line.size();i++) if (line.at(i)=='|') frontiers << (i - frontiers.size()); foreach(const int p, frontiers) fExp += QString("<%1:%2>").arg(p).arg(p*5); foreach(const IntPair& p, doc->line(0).handle()->m_frontiers) fGot += QString("<%1:%2>").arg(p.first).arg(p.second); QEQUAL(fGot, fExp); }
void LatexCompleterTest::simple(){ QFETCH(QString, text); QFETCH(bool, eowCompletes); QFETCH(int, line); QFETCH(int, offset); QFETCH(QStringList, log); config->eowCompletes = eowCompletes; edView->editor->document()->setText(text); edView->editor->setCursor(edView->editor->document()->cursor(line,offset)); edView->complete(false); foreach (const QString& s, log){ char key = s.at(0).toAscii(); QTest::keyClick(edView->editor, key); QString text = s.mid(2); QEQUAL(edView->editor->text(), text); }
//checks if load/saving preserves encoding and line endings void QEditorTest::loadSave(){ QFETCH(QString, outCodecName); QFETCH(QString, outLineEnding); QFETCH(bool, autodetect); QTextCodec* outCodec=QTextCodec::codecForName(qPrintable(outCodecName)); if (outCodecName=="latin1") outCodec = defaultCodec; if (!allTests) { qDebug("skipped load save test"); return; } const QString testText = QString::fromLatin1("hallo\n\xE4\xF6\xFC\n"); QString testTextWithLineEndings=testText; testTextWithLineEndings.replace("\n",outLineEnding); QTemporaryFile tf;//uncomment if you need to look at the files &tf=*(new QTemporaryFile); tf.open(); QString tfn=tf.fileName(); tf.write(outCodec->fromUnicode(testTextWithLineEndings)); tf.close(); //Load editor->setFileCodec(QTextCodec::codecForName("iso-8859-5")); editor->load(tfn,autodetect?0:outCodec); editor->document()->setLineEnding(editor->document()->originalLineEnding()); //TODO: find out why this line is only needed iff the editor passed by the testmanager is used and not if a new QEditor(0) is created QEQUAL2(editor->document()->text(),testTextWithLineEndings,QString("File: %1 Got file codec: %2 ").arg(tfn).arg(editor->getFileCodec()?QString::fromAscii(editor->getFileCodec()->name()):"<null>")); QVERIFY2(editor->getFileCodec()==outCodec,qPrintable(QString("wrong encoding: got %1 wanted %2 by the sheriff %3").arg(QString::fromAscii(editor->getFileCodec()->name())).arg(QString::fromAscii(outCodec->name())).arg(autodetect))); QEQUAL(editor->document()->lineEndingString(),outLineEnding); //Save editor->setText(editor->document()->text()+"Save test", false); editor->save(); tf.open(); QString writtenText=outCodec->toUnicode( tf.readAll()); tf.close(); QEQUAL2(writtenText, testTextWithLineEndings+"Save test", "file text check, file:"+tfn); QVERIFY2(writtenText.contains(outLineEnding), qPrintable("file don't contain right line ending, file"+tfn)); editor->setFileName(""); //reset filename so it won't get panically if the file is deleted editor->document()->setLineEnding(QDocument::Conservative); //reset line ending so we won't screw up the other tests }
void SyntaxCheckTest::checkkeyval(){ QFETCH(QString, text); QFETCH(bool, error); bool inlineSyntaxChecking = edView->getConfig()->inlineSyntaxChecking; bool realtimeChecking = edView->getConfig()->realtimeChecking; edView->getConfig()->inlineSyntaxChecking = edView->getConfig()->realtimeChecking = true; text="\\usepackage{siunitx}\n"+text; edView->editor->setText(text, false); do{ edView->SynChecker.waitForQueueProcess(); // wait for syntax checker to finish (as it runs in a parallel thread) QApplication::processEvents(QEventLoop::AllEvents,10); // SyntaxChecker posts events for rechecking other lines }while(edView->SynChecker.queuedLines()); LatexDocument *doc=edView->getDocument(); QDocumentLineHandle *dlh=doc->line(1).handle(); QList<QFormatRange> formats=dlh->getOverlays(LatexEditorView::syntaxErrorFormat); QEQUAL(!formats.isEmpty(),error); edView->getConfig()->inlineSyntaxChecking = inlineSyntaxChecking; edView->getConfig()->realtimeChecking = realtimeChecking; }
void QDocumentCursorTest::constMethods(){ QFETCH(QString, cursor); QFETCH(bool, atStart); QFETCH(bool, atEnd); QFETCH(bool, atLineStart); QFETCH(bool, atLineEnd); QFETCH(int, position); QFETCH(int, anchorLineNumber); QFETCH(int, anchorColumnNumber); QFETCH(int, lineNumber); QFETCH(int, columnNumber); QFETCH(QString, selectionStart); QFETCH(QString, selectionEnd); QFETCH(bool, hasSelection); QFETCH(QString, selectedText); QFETCH(char, previousChar); QFETCH(char, nextChar); Q_UNUSED(position) QDocumentCursor c=str2cur(cursor); QVERIFY(c.isValid()); QVERIFY(!c.isNull()); QVERIFY(c==c); QVERIFY(!(c!=c)); QVERIFY(c<=c); QVERIFY(c>=c); QVERIFY(!(c<c)); QVERIFY(!(c>c)); QEQUAL(c.atStart(), atStart); QEQUAL(c.atEnd(), atEnd); QEQUAL(c.atLineStart(), atLineStart); QEQUAL(c.atLineEnd(), atLineEnd); //QEQUAL(c.position(), position); QEQUAL(c.anchorLineNumber(), anchorLineNumber); QEQUAL(c.anchorColumnNumber(), anchorColumnNumber); QEQUAL(c.lineNumber(), lineNumber); QEQUAL(c.columnNumber(), columnNumber); QVERIFY(c.line()==doc->line(lineNumber)); QVERIFY(c.anchorLine()==doc->line(anchorLineNumber)); if (selectionStart == "") QVERIFY(c.selectionStart().isNull()); else QSVERIFY2(c.selectionStart() == str2cur(selectionStart),QString("%1:%2").arg(c.selectionStart().lineNumber()).arg(c.selectionStart().columnNumber())); if (selectionEnd == "") QVERIFY(c.selectionEnd().isNull()); else QSVERIFY2(c.selectionEnd() == str2cur(selectionEnd),QString("%1:%2").arg(c.selectionEnd().lineNumber()).arg(c.selectionEnd().columnNumber())); QEQUAL(c.hasSelection(), hasSelection); QEQUAL(c.selectedText(), selectedText); QEQUAL(c.previousChar(), previousChar); QEQUAL(c.nextChar(), nextChar); }
void QDocumentSearchTest::next_sameText(){ QFETCH(QString, editorText); QFETCH(QString, searchText); QFETCH(int, options); options |= QDocumentSearch::Silent ; QFETCH(int, sy); QFETCH(int, sx); QFETCH(QList<CM>, cms); QDocumentSearch* ds=this->ds; for (int loop=0; loop<4; loop++){ //QWARN(qPrintable(QString("%1").arg(loop))); ed->document()->setText(editorText); if (loop<2) { ds->setSearchText(searchText); if (loop) options|=QDocumentSearch::HighlightAll; //highlighting shouldn't change anything ds->setOptions((QDocumentSearch::Options)options); } else if (loop==2)//creating a new search shouldn't change anything ds=new QDocumentSearch(ed,searchText,(QDocumentSearch::Options)options); else ds=new QDocumentSearch(ed,searchText,(QDocumentSearch::Options)options|QDocumentSearch::HighlightAll); ds->setCursor(ed->document()->cursor(sy,sx)); for (int i=0;i< cms.size();i++){ QString sel; if (cms[i].l>=0) { if (cms[i].rep) { QStringList temp=cms[i].nt.split("\n"); QVERIFY(temp.size()>cms[i].l); sel=temp[cms[i].l]; } else sel=ed->document()->line(cms[i].l).text(); if (cms[i].ax<cms[i].cx) sel = sel.mid(cms[i].ax,cms[i].cx-cms[i].ax); else sel =sel.mid(cms[i].cx,cms[i].ax-cms[i].cx); } if (!cms[i].rep) ds->setOptions((QDocumentSearch::Options)options & (~QDocumentSearch::Replace)); else { ds->setOptions((QDocumentSearch::Options)options | QDocumentSearch::Replace); ds->setReplaceText(cms[i].rt); } int foundCount = ds->next(cms[i].dir,false,cms[i].rep); QByteArray emba=QString("%1: %2 %3 %4 \"%5\" \"%6\" expected %7 %8 %9 %10 %11 %12").arg(i).arg(ds->cursor().lineNumber()).arg(ds->cursor().anchorColumnNumber()).arg(ds->cursor().columnNumber()).arg(ds->cursor().selectedText()).arg(ed->document()->text()).arg(cms[i].l).arg(cms[i].ax).arg(cms[i].cx).arg(sel).arg(cms[i].nt).arg(loop?"(highlight-run)":"").toLatin1();//make sure the message stays in memory for the next few lines const char* errorMessage=emba.constData(); QVERIFY2(ds->cursor().selectedText()== sel,errorMessage); QVERIFY2(ds->cursor().lineNumber()== cms[i].l,errorMessage); QVERIFY2(ds->cursor().columnNumber()== cms[i].cx,errorMessage); QVERIFY2(ds->cursor().anchorLineNumber()== cms[i].l,errorMessage); QVERIFY2(ds->cursor().anchorColumnNumber()== cms[i].ax,errorMessage); if (cms[i].rep){ QVERIFY2(ed->document()->text()== cms[i].nt,errorMessage); } if (cms[i].l==-1) QEQUAL(foundCount, 0); else QEQUAL(foundCount, 1); /*if (options & QDocumentSearch::Replace) QVERIFY(ed->document()->text()== newText[i]);*/ } if (loop>=2) delete ds; } }