File indexing completed on 2024-10-13 06:37:54
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2011-2018 Dominik Haumann <dhaumann@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "modificationsystem_test.h" 0009 #include "moc_modificationsystem_test.cpp" 0010 0011 #include <katebuffer.h> 0012 #include <katedocument.h> 0013 #include <kateglobal.h> 0014 #include <kateundomanager.h> 0015 0016 #include <QTest> 0017 0018 QTEST_MAIN(ModificationSystemTest) 0019 0020 using namespace KTextEditor; 0021 0022 void ModificationSystemTest::initTestCase() 0023 { 0024 KTextEditor::EditorPrivate::enableUnitTestMode(); 0025 } 0026 0027 void ModificationSystemTest::cleanupTestCase() 0028 { 0029 } 0030 0031 static void clearModificationFlags(KTextEditor::DocumentPrivate *doc) 0032 { 0033 for (int i = 0; i < doc->lines(); ++i) { 0034 Kate::TextLine line = doc->plainKateTextLine(i); 0035 line.markAsModified(false); 0036 line.markAsSavedOnDisk(false); 0037 doc->buffer().setLineMetaData(i, line); 0038 } 0039 } 0040 0041 static void markModifiedLinesAsSaved(KTextEditor::DocumentPrivate *doc) 0042 { 0043 for (int i = 0; i < doc->lines(); ++i) { 0044 Kate::TextLine textLine = doc->plainKateTextLine(i); 0045 if (textLine.markedAsModified()) { 0046 textLine.markAsSavedOnDisk(true); 0047 doc->buffer().setLineMetaData(i, textLine); 0048 } 0049 } 0050 } 0051 0052 void ModificationSystemTest::testInsertText() 0053 { 0054 KTextEditor::DocumentPrivate doc; 0055 0056 const QString content(QStringLiteral("first line\n")); 0057 doc.setText(content); 0058 0059 // now all lines should have state "Modified" 0060 QVERIFY(doc.isLineModified(0)); 0061 QVERIFY(!doc.isLineSaved(0)); 0062 0063 // clear all modification flags, forces no flags 0064 doc.setModified(false); 0065 doc.undoManager()->updateLineModifications(); 0066 clearModificationFlags(&doc); 0067 0068 QVERIFY(!doc.isLineModified(0)); 0069 QVERIFY(!doc.isLineSaved(0)); 0070 0071 // now we have an a unmodified file, start real tests 0072 // insert text in line 0, then undo and redo 0073 doc.insertText(Cursor(0, 2), QStringLiteral("_")); 0074 QVERIFY(doc.isLineModified(0)); 0075 QVERIFY(!doc.isLineSaved(0)); 0076 0077 doc.undo(); 0078 QVERIFY(!doc.isLineModified(0)); 0079 QVERIFY(doc.isLineSaved(0)); 0080 0081 doc.redo(); 0082 QVERIFY(doc.isLineModified(0)); 0083 QVERIFY(!doc.isLineSaved(0)); 0084 0085 // 0086 // now simulate "save", then do the undo/redo tests again 0087 // 0088 doc.setModified(false); 0089 markModifiedLinesAsSaved(&doc); 0090 doc.undoManager()->updateLineModifications(); 0091 0092 // now no line should have state "Modified" 0093 QVERIFY(!doc.isLineModified(0)); 0094 QVERIFY(doc.isLineSaved(0)); 0095 0096 // undo the text insertion 0097 doc.undo(); 0098 QVERIFY(doc.isLineModified(0)); 0099 QVERIFY(!doc.isLineSaved(0)); 0100 0101 doc.redo(); 0102 QVERIFY(!doc.isLineModified(0)); 0103 QVERIFY(doc.isLineSaved(0)); 0104 } 0105 0106 void ModificationSystemTest::testRemoveText() 0107 { 0108 KTextEditor::DocumentPrivate doc; 0109 0110 const QString content(QStringLiteral("first line\n")); 0111 doc.setText(content); 0112 0113 // now all lines should have state "Modified" 0114 QVERIFY(doc.isLineModified(0)); 0115 QVERIFY(!doc.isLineSaved(0)); 0116 0117 // clear all modification flags, forces no flags 0118 doc.setModified(false); 0119 doc.undoManager()->updateLineModifications(); 0120 clearModificationFlags(&doc); 0121 0122 QVERIFY(!doc.isLineModified(0)); 0123 QVERIFY(!doc.isLineSaved(0)); 0124 0125 // now we have an a unmodified file, start real tests 0126 // remove text in line 0, then undo and redo 0127 doc.removeText(Range(Cursor(0, 1), Cursor(0, 2))); 0128 QVERIFY(doc.isLineModified(0)); 0129 QVERIFY(!doc.isLineSaved(0)); 0130 0131 doc.undo(); 0132 QVERIFY(!doc.isLineModified(0)); 0133 QVERIFY(doc.isLineSaved(0)); 0134 0135 doc.redo(); 0136 QVERIFY(doc.isLineModified(0)); 0137 QVERIFY(!doc.isLineSaved(0)); 0138 0139 // 0140 // now simulate "save", then do the undo/redo tests again 0141 // 0142 doc.setModified(false); 0143 markModifiedLinesAsSaved(&doc); 0144 doc.undoManager()->updateLineModifications(); 0145 0146 // now no line should have state "Modified" 0147 QVERIFY(!doc.isLineModified(0)); 0148 QVERIFY(doc.isLineSaved(0)); 0149 0150 // undo the text insertion 0151 doc.undo(); 0152 QVERIFY(doc.isLineModified(0)); 0153 QVERIFY(!doc.isLineSaved(0)); 0154 0155 doc.redo(); 0156 QVERIFY(!doc.isLineModified(0)); 0157 QVERIFY(doc.isLineSaved(0)); 0158 } 0159 0160 void ModificationSystemTest::testInsertLine() 0161 { 0162 KTextEditor::DocumentPrivate doc; 0163 0164 const QString content( 0165 QStringLiteral("0\n" 0166 "2")); 0167 doc.setText(content); 0168 0169 // clear all modification flags, forces no flags 0170 doc.setModified(false); 0171 doc.undoManager()->updateLineModifications(); 0172 clearModificationFlags(&doc); 0173 0174 // insert at line 1 0175 doc.insertLine(1, QStringLiteral("1")); 0176 0177 QVERIFY(!doc.isLineModified(0)); 0178 QVERIFY(doc.isLineModified(1)); 0179 QVERIFY(!doc.isLineModified(2)); 0180 QVERIFY(!doc.isLineSaved(0)); 0181 QVERIFY(!doc.isLineSaved(1)); 0182 QVERIFY(!doc.isLineSaved(2)); 0183 0184 doc.undo(); 0185 QVERIFY(!doc.isLineModified(0)); 0186 QVERIFY(!doc.isLineModified(1)); 0187 QVERIFY(!doc.isLineSaved(0)); 0188 QVERIFY(!doc.isLineSaved(1)); 0189 0190 doc.redo(); 0191 QVERIFY(!doc.isLineModified(0)); 0192 QVERIFY(doc.isLineModified(1)); 0193 QVERIFY(!doc.isLineModified(2)); 0194 QVERIFY(!doc.isLineSaved(0)); 0195 QVERIFY(!doc.isLineSaved(1)); 0196 QVERIFY(!doc.isLineSaved(2)); 0197 0198 // 0199 // now simulate "save", then do the undo/redo tests again 0200 // 0201 doc.setModified(false); 0202 markModifiedLinesAsSaved(&doc); 0203 doc.undoManager()->updateLineModifications(); 0204 0205 // now no line should have state "Modified" 0206 QVERIFY(!doc.isLineModified(0)); 0207 QVERIFY(!doc.isLineModified(1)); 0208 QVERIFY(!doc.isLineModified(2)); 0209 QVERIFY(!doc.isLineSaved(0)); 0210 QVERIFY(doc.isLineSaved(1)); 0211 QVERIFY(!doc.isLineSaved(2)); 0212 0213 // undo the text insertion 0214 doc.undo(); 0215 QVERIFY(!doc.isLineModified(0)); 0216 QVERIFY(!doc.isLineModified(1)); 0217 QVERIFY(!doc.isLineSaved(0)); 0218 QVERIFY(!doc.isLineSaved(1)); 0219 0220 doc.redo(); 0221 QVERIFY(!doc.isLineModified(0)); 0222 QVERIFY(!doc.isLineModified(1)); 0223 QVERIFY(!doc.isLineModified(2)); 0224 QVERIFY(!doc.isLineSaved(0)); 0225 QVERIFY(doc.isLineSaved(1)); 0226 QVERIFY(!doc.isLineSaved(2)); 0227 } 0228 0229 void ModificationSystemTest::testRemoveLine() 0230 { 0231 KTextEditor::DocumentPrivate doc; 0232 0233 const QString content( 0234 QStringLiteral("0\n" 0235 "1\n" 0236 "2")); 0237 doc.setText(content); 0238 0239 // clear all modification flags, forces no flags 0240 doc.setModified(false); 0241 doc.undoManager()->updateLineModifications(); 0242 clearModificationFlags(&doc); 0243 0244 // remove at line 1 0245 doc.removeLine(1); 0246 0247 QVERIFY(!doc.isLineModified(0)); 0248 QVERIFY(!doc.isLineModified(1)); 0249 QVERIFY(!doc.isLineSaved(0)); 0250 QVERIFY(!doc.isLineSaved(1)); 0251 0252 doc.undo(); 0253 QVERIFY(!doc.isLineModified(0)); 0254 QVERIFY(!doc.isLineModified(1)); 0255 QVERIFY(!doc.isLineModified(2)); 0256 QVERIFY(!doc.isLineSaved(0)); 0257 QVERIFY(doc.isLineSaved(1)); 0258 QVERIFY(!doc.isLineSaved(2)); 0259 0260 doc.redo(); 0261 QVERIFY(!doc.isLineModified(0)); 0262 QVERIFY(!doc.isLineModified(1)); 0263 QVERIFY(!doc.isLineSaved(0)); 0264 QVERIFY(!doc.isLineSaved(1)); 0265 0266 // 0267 // now simulate "save", then do the undo/redo tests again 0268 // 0269 doc.setModified(false); 0270 markModifiedLinesAsSaved(&doc); 0271 doc.undoManager()->updateLineModifications(); 0272 0273 // now no line should have state "Modified" 0274 QVERIFY(!doc.isLineModified(0)); 0275 QVERIFY(!doc.isLineModified(1)); 0276 QVERIFY(!doc.isLineSaved(0)); 0277 QVERIFY(!doc.isLineSaved(1)); 0278 0279 // undo the text insertion 0280 doc.undo(); 0281 QVERIFY(!doc.isLineModified(0)); 0282 QVERIFY(doc.isLineModified(1)); 0283 QVERIFY(!doc.isLineModified(2)); 0284 QVERIFY(!doc.isLineSaved(0)); 0285 QVERIFY(!doc.isLineSaved(1)); 0286 QVERIFY(!doc.isLineSaved(2)); 0287 0288 doc.redo(); 0289 QVERIFY(!doc.isLineModified(0)); 0290 QVERIFY(!doc.isLineModified(1)); 0291 QVERIFY(!doc.isLineSaved(0)); 0292 QVERIFY(!doc.isLineSaved(1)); 0293 } 0294 0295 void ModificationSystemTest::testWrapLineMid() 0296 { 0297 for (int i = 0; i < 2; ++i) { 0298 bool insertNewLine = (i == 1); 0299 KTextEditor::DocumentPrivate doc; 0300 0301 const QString content( 0302 QStringLiteral("aaaa\n" 0303 "bbbb\n" 0304 "cccc")); 0305 doc.setText(content); 0306 0307 // clear all modification flags, forces no flags 0308 doc.setModified(false); 0309 doc.undoManager()->updateLineModifications(); 0310 clearModificationFlags(&doc); 0311 0312 // wrap line 1 at |: bb|bb 0313 doc.editWrapLine(1, 2, insertNewLine); 0314 0315 QVERIFY(!doc.isLineModified(0)); 0316 QVERIFY(doc.isLineModified(1)); 0317 QVERIFY(doc.isLineModified(2)); 0318 QVERIFY(!doc.isLineSaved(0)); 0319 QVERIFY(!doc.isLineSaved(1)); 0320 QVERIFY(!doc.isLineSaved(2)); 0321 0322 doc.undo(); 0323 QVERIFY(!doc.isLineModified(0)); 0324 QVERIFY(!doc.isLineModified(1)); 0325 QVERIFY(!doc.isLineSaved(0)); 0326 QVERIFY(doc.isLineSaved(1)); 0327 0328 doc.redo(); 0329 QVERIFY(!doc.isLineModified(0)); 0330 QVERIFY(doc.isLineModified(1)); 0331 QVERIFY(doc.isLineModified(2)); 0332 QVERIFY(!doc.isLineSaved(0)); 0333 QVERIFY(!doc.isLineSaved(1)); 0334 QVERIFY(!doc.isLineSaved(2)); 0335 0336 // 0337 // now simulate "save", then do the undo/redo tests again 0338 // 0339 doc.setModified(false); 0340 markModifiedLinesAsSaved(&doc); 0341 doc.undoManager()->updateLineModifications(); 0342 0343 // now no line should have state "Modified" 0344 QVERIFY(!doc.isLineModified(0)); 0345 QVERIFY(!doc.isLineModified(1)); 0346 QVERIFY(!doc.isLineModified(2)); 0347 QVERIFY(!doc.isLineSaved(0)); 0348 QVERIFY(doc.isLineSaved(1)); 0349 QVERIFY(doc.isLineSaved(2)); 0350 0351 // undo the text insertion 0352 doc.undo(); 0353 QVERIFY(!doc.isLineModified(0)); 0354 QVERIFY(doc.isLineModified(1)); 0355 QVERIFY(!doc.isLineSaved(0)); 0356 QVERIFY(!doc.isLineSaved(1)); 0357 0358 doc.redo(); 0359 QVERIFY(!doc.isLineModified(0)); 0360 QVERIFY(!doc.isLineModified(1)); 0361 QVERIFY(!doc.isLineModified(2)); 0362 QVERIFY(!doc.isLineSaved(0)); 0363 QVERIFY(doc.isLineSaved(1)); 0364 QVERIFY(doc.isLineSaved(2)); 0365 } 0366 } 0367 0368 void ModificationSystemTest::testWrapLineAtEnd() 0369 { 0370 KTextEditor::DocumentPrivate doc; 0371 0372 const QString content( 0373 QStringLiteral("aaaa\n" 0374 "bbbb")); 0375 doc.setText(content); 0376 0377 // clear all modification flags, forces no flags 0378 doc.setModified(false); 0379 doc.undoManager()->updateLineModifications(); 0380 clearModificationFlags(&doc); 0381 0382 // wrap line 0 at end 0383 doc.editWrapLine(0, 4); 0384 0385 QVERIFY(!doc.isLineModified(0)); 0386 QVERIFY(doc.isLineModified(1)); 0387 QVERIFY(!doc.isLineModified(2)); 0388 QVERIFY(!doc.isLineSaved(0)); 0389 QVERIFY(!doc.isLineSaved(1)); 0390 QVERIFY(!doc.isLineSaved(2)); 0391 0392 doc.undo(); 0393 QVERIFY(!doc.isLineModified(0)); 0394 QVERIFY(!doc.isLineModified(1)); 0395 QVERIFY(!doc.isLineSaved(0)); 0396 QVERIFY(!doc.isLineSaved(1)); 0397 0398 doc.redo(); 0399 QVERIFY(!doc.isLineModified(0)); 0400 QVERIFY(doc.isLineModified(1)); 0401 QVERIFY(!doc.isLineModified(2)); 0402 QVERIFY(!doc.isLineSaved(0)); 0403 QVERIFY(!doc.isLineSaved(1)); 0404 QVERIFY(!doc.isLineSaved(2)); 0405 0406 // 0407 // now simulate "save", then do the undo/redo tests again 0408 // 0409 doc.setModified(false); 0410 markModifiedLinesAsSaved(&doc); 0411 doc.undoManager()->updateLineModifications(); 0412 0413 // now no line should have state "Modified" 0414 QVERIFY(!doc.isLineModified(0)); 0415 QVERIFY(!doc.isLineModified(1)); 0416 QVERIFY(!doc.isLineModified(2)); 0417 QVERIFY(!doc.isLineSaved(0)); 0418 QVERIFY(doc.isLineSaved(1)); 0419 QVERIFY(!doc.isLineSaved(2)); 0420 0421 // undo the text insertion 0422 doc.undo(); 0423 QVERIFY(!doc.isLineModified(0)); 0424 QVERIFY(!doc.isLineModified(1)); 0425 QVERIFY(!doc.isLineSaved(0)); 0426 QVERIFY(!doc.isLineSaved(1)); 0427 0428 doc.redo(); 0429 QVERIFY(!doc.isLineModified(0)); 0430 QVERIFY(!doc.isLineModified(1)); 0431 QVERIFY(!doc.isLineModified(2)); 0432 QVERIFY(!doc.isLineSaved(0)); 0433 QVERIFY(doc.isLineSaved(1)); 0434 QVERIFY(!doc.isLineSaved(2)); 0435 } 0436 0437 void ModificationSystemTest::testWrapLineAtStart() 0438 { 0439 KTextEditor::DocumentPrivate doc; 0440 0441 const QString content( 0442 QStringLiteral("aaaa\n" 0443 "bbbb")); 0444 doc.setText(content); 0445 0446 // clear all modification flags, forces no flags 0447 doc.setModified(false); 0448 doc.undoManager()->updateLineModifications(); 0449 clearModificationFlags(&doc); 0450 0451 // wrap line 0 at end 0452 doc.editWrapLine(0, 0); 0453 0454 QVERIFY(doc.isLineModified(0)); 0455 QVERIFY(!doc.isLineModified(1)); 0456 QVERIFY(!doc.isLineModified(2)); 0457 QVERIFY(!doc.isLineSaved(0)); 0458 QVERIFY(!doc.isLineSaved(1)); 0459 QVERIFY(!doc.isLineSaved(2)); 0460 0461 doc.undo(); 0462 QVERIFY(!doc.isLineModified(0)); 0463 QVERIFY(!doc.isLineModified(1)); 0464 QVERIFY(!doc.isLineSaved(0)); 0465 QVERIFY(!doc.isLineSaved(1)); 0466 0467 doc.redo(); 0468 QVERIFY(doc.isLineModified(0)); 0469 QVERIFY(!doc.isLineModified(1)); 0470 QVERIFY(!doc.isLineModified(2)); 0471 QVERIFY(!doc.isLineSaved(0)); 0472 QVERIFY(!doc.isLineSaved(1)); 0473 QVERIFY(!doc.isLineSaved(2)); 0474 0475 // 0476 // now simulate "save", then do the undo/redo tests again 0477 // 0478 doc.setModified(false); 0479 markModifiedLinesAsSaved(&doc); 0480 doc.undoManager()->updateLineModifications(); 0481 0482 // now no line should have state "Modified" 0483 QVERIFY(!doc.isLineModified(0)); 0484 QVERIFY(!doc.isLineModified(1)); 0485 QVERIFY(!doc.isLineModified(2)); 0486 QVERIFY(doc.isLineSaved(0)); 0487 QVERIFY(!doc.isLineSaved(1)); 0488 QVERIFY(!doc.isLineSaved(2)); 0489 0490 // undo the text insertion 0491 doc.undo(); 0492 QVERIFY(!doc.isLineModified(0)); 0493 QVERIFY(!doc.isLineModified(1)); 0494 QVERIFY(!doc.isLineSaved(0)); 0495 QVERIFY(!doc.isLineSaved(1)); 0496 0497 doc.redo(); 0498 QVERIFY(!doc.isLineModified(0)); 0499 QVERIFY(!doc.isLineModified(1)); 0500 QVERIFY(!doc.isLineModified(2)); 0501 QVERIFY(doc.isLineSaved(0)); 0502 QVERIFY(!doc.isLineSaved(1)); 0503 QVERIFY(!doc.isLineSaved(2)); 0504 } 0505 0506 void ModificationSystemTest::testUnWrapLine() 0507 { 0508 KTextEditor::DocumentPrivate doc; 0509 0510 const QString content( 0511 QStringLiteral("aaaa\n" 0512 "bbbb\n" 0513 "cccc")); 0514 doc.setText(content); 0515 0516 // clear all modification flags, forces no flags 0517 doc.setModified(false); 0518 doc.undoManager()->updateLineModifications(); 0519 clearModificationFlags(&doc); 0520 0521 // join line 0 and 1 0522 doc.editUnWrapLine(0); 0523 0524 QVERIFY(doc.isLineModified(0)); 0525 QVERIFY(!doc.isLineModified(1)); 0526 QVERIFY(!doc.isLineSaved(0)); 0527 QVERIFY(!doc.isLineSaved(1)); 0528 0529 doc.undo(); 0530 QVERIFY(!doc.isLineModified(0)); 0531 QVERIFY(!doc.isLineModified(1)); 0532 QVERIFY(!doc.isLineModified(2)); 0533 QVERIFY(doc.isLineSaved(0)); 0534 QVERIFY(doc.isLineSaved(1)); 0535 QVERIFY(!doc.isLineSaved(2)); 0536 0537 doc.redo(); 0538 QVERIFY(doc.isLineModified(0)); 0539 QVERIFY(!doc.isLineModified(1)); 0540 QVERIFY(!doc.isLineSaved(0)); 0541 QVERIFY(!doc.isLineSaved(1)); 0542 0543 // 0544 // now simulate "save", then do the undo/redo tests again 0545 // 0546 doc.setModified(false); 0547 markModifiedLinesAsSaved(&doc); 0548 doc.undoManager()->updateLineModifications(); 0549 0550 // now no line should have state "Modified" 0551 QVERIFY(!doc.isLineModified(0)); 0552 QVERIFY(!doc.isLineModified(1)); 0553 QVERIFY(doc.isLineSaved(0)); 0554 QVERIFY(!doc.isLineSaved(1)); 0555 0556 // undo the text insertion 0557 doc.undo(); 0558 QVERIFY(doc.isLineModified(0)); 0559 QVERIFY(doc.isLineModified(1)); 0560 QVERIFY(!doc.isLineModified(2)); 0561 QVERIFY(!doc.isLineSaved(0)); 0562 QVERIFY(!doc.isLineSaved(1)); 0563 QVERIFY(!doc.isLineSaved(2)); 0564 0565 doc.redo(); 0566 QVERIFY(!doc.isLineModified(0)); 0567 QVERIFY(!doc.isLineModified(1)); 0568 QVERIFY(doc.isLineSaved(0)); 0569 QVERIFY(!doc.isLineSaved(1)); 0570 } 0571 0572 void ModificationSystemTest::testUnWrapLine1Empty() 0573 { 0574 KTextEditor::DocumentPrivate doc; 0575 0576 const QString content( 0577 QStringLiteral("aaaa\n" 0578 "\n" 0579 "bbbb")); 0580 doc.setText(content); 0581 0582 // clear all modification flags, forces no flags 0583 doc.setModified(false); 0584 doc.undoManager()->updateLineModifications(); 0585 clearModificationFlags(&doc); 0586 0587 // join line 1 and 2 0588 doc.editUnWrapLine(1); 0589 0590 QVERIFY(!doc.isLineModified(0)); 0591 QVERIFY(!doc.isLineModified(1)); 0592 QVERIFY(!doc.isLineSaved(0)); 0593 QVERIFY(!doc.isLineSaved(1)); 0594 0595 doc.undo(); 0596 QVERIFY(!doc.isLineModified(0)); 0597 QVERIFY(!doc.isLineModified(1)); 0598 QVERIFY(!doc.isLineModified(2)); 0599 QVERIFY(!doc.isLineSaved(0)); 0600 QVERIFY(doc.isLineSaved(1)); 0601 QVERIFY(!doc.isLineSaved(2)); 0602 0603 doc.redo(); 0604 QVERIFY(!doc.isLineModified(0)); 0605 QVERIFY(!doc.isLineModified(1)); 0606 QVERIFY(!doc.isLineSaved(0)); 0607 QVERIFY(!doc.isLineSaved(1)); 0608 0609 // 0610 // now simulate "save", then do the undo/redo tests again 0611 // 0612 doc.setModified(false); 0613 markModifiedLinesAsSaved(&doc); 0614 doc.undoManager()->updateLineModifications(); 0615 0616 // now no line should have state "Modified" 0617 QVERIFY(!doc.isLineModified(0)); 0618 QVERIFY(!doc.isLineModified(1)); 0619 QVERIFY(!doc.isLineSaved(0)); 0620 QVERIFY(!doc.isLineSaved(1)); 0621 0622 // undo the text insertion 0623 doc.undo(); 0624 QVERIFY(!doc.isLineModified(0)); 0625 QVERIFY(doc.isLineModified(1)); 0626 QVERIFY(!doc.isLineModified(2)); 0627 QVERIFY(!doc.isLineSaved(0)); 0628 QVERIFY(!doc.isLineSaved(1)); 0629 QVERIFY(!doc.isLineSaved(2)); 0630 0631 doc.redo(); 0632 QVERIFY(!doc.isLineModified(0)); 0633 QVERIFY(!doc.isLineModified(1)); 0634 QVERIFY(!doc.isLineSaved(0)); 0635 QVERIFY(!doc.isLineSaved(1)); 0636 } 0637 0638 void ModificationSystemTest::testUnWrapLine2Empty() 0639 { 0640 KTextEditor::DocumentPrivate doc; 0641 0642 const QString content( 0643 QStringLiteral("aaaa\n" 0644 "\n" 0645 "bbbb")); 0646 doc.setText(content); 0647 0648 // clear all modification flags, forces no flags 0649 doc.setModified(false); 0650 doc.undoManager()->updateLineModifications(); 0651 clearModificationFlags(&doc); 0652 0653 // join line 0 and 1 0654 doc.editUnWrapLine(0); 0655 0656 QVERIFY(!doc.isLineModified(0)); 0657 QVERIFY(!doc.isLineModified(1)); 0658 QVERIFY(!doc.isLineSaved(0)); 0659 QVERIFY(!doc.isLineSaved(1)); 0660 0661 doc.undo(); 0662 QVERIFY(!doc.isLineModified(0)); 0663 QVERIFY(!doc.isLineModified(1)); 0664 QVERIFY(!doc.isLineModified(2)); 0665 QVERIFY(!doc.isLineSaved(0)); 0666 QVERIFY(doc.isLineSaved(1)); 0667 QVERIFY(!doc.isLineSaved(2)); 0668 0669 doc.redo(); 0670 QVERIFY(!doc.isLineModified(0)); 0671 QVERIFY(!doc.isLineModified(1)); 0672 QVERIFY(!doc.isLineSaved(0)); 0673 QVERIFY(!doc.isLineSaved(1)); 0674 0675 // 0676 // now simulate "save", then do the undo/redo tests again 0677 // 0678 doc.setModified(false); 0679 markModifiedLinesAsSaved(&doc); 0680 doc.undoManager()->updateLineModifications(); 0681 0682 // now no line should have state "Modified" 0683 QVERIFY(!doc.isLineModified(0)); 0684 QVERIFY(!doc.isLineModified(1)); 0685 QVERIFY(!doc.isLineSaved(0)); 0686 QVERIFY(!doc.isLineSaved(1)); 0687 0688 // undo the text insertion 0689 doc.undo(); 0690 QVERIFY(!doc.isLineModified(0)); 0691 QVERIFY(doc.isLineModified(1)); 0692 QVERIFY(!doc.isLineModified(2)); 0693 QVERIFY(!doc.isLineSaved(0)); 0694 QVERIFY(!doc.isLineSaved(1)); 0695 QVERIFY(!doc.isLineSaved(2)); 0696 0697 doc.redo(); 0698 QVERIFY(!doc.isLineModified(0)); 0699 QVERIFY(!doc.isLineModified(1)); 0700 QVERIFY(!doc.isLineSaved(0)); 0701 QVERIFY(!doc.isLineSaved(1)); 0702 } 0703 0704 void ModificationSystemTest::testNavigation() 0705 { 0706 KTextEditor::DocumentPrivate doc; 0707 0708 const QString content( 0709 QStringLiteral("0\n" 0710 "1\n" 0711 "2")); 0712 doc.setText(content); 0713 0714 // clear all modification flags, forces no flags 0715 doc.setModified(false); 0716 doc.undoManager()->updateLineModifications(); 0717 clearModificationFlags(&doc); 0718 0719 // touch line 0 and line 2: 0720 doc.insertText(Cursor(0, 1), QStringLiteral("-")); 0721 doc.insertText(Cursor(2, 1), QStringLiteral("-")); 0722 0723 // test down navigation: 0724 const bool down = true; 0725 QCOMPARE(doc.findTouchedLine(-1, down), -1); 0726 QCOMPARE(doc.findTouchedLine(0, down), 0); 0727 QCOMPARE(doc.findTouchedLine(1, down), 2); 0728 QCOMPARE(doc.findTouchedLine(2, down), 2); 0729 QCOMPARE(doc.findTouchedLine(3, down), -1); 0730 0731 // test up navigation 0732 const bool up = false; 0733 QCOMPARE(doc.findTouchedLine(-1, up), -1); 0734 QCOMPARE(doc.findTouchedLine(0, up), 0); 0735 QCOMPARE(doc.findTouchedLine(1, up), 0); 0736 QCOMPARE(doc.findTouchedLine(2, up), 2); 0737 QCOMPARE(doc.findTouchedLine(3, up), -1); 0738 }