From d03927f373b62fffe5e4e94780888174205c0964 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Wed, 6 Aug 2014 15:03:26 +0300 Subject: DiffEditor: Fix no newline handling Change-Id: I3278ae80d7ee010942122723b3e8bb8c729e7182 Reviewed-by: Orgad Shaneh --- src/plugins/diffeditor/diffeditorplugin.cpp | 70 +++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'src/plugins/diffeditor/diffeditorplugin.cpp') diff --git a/src/plugins/diffeditor/diffeditorplugin.cpp b/src/plugins/diffeditor/diffeditorplugin.cpp index 6c6346998a..655f39bff1 100644 --- a/src/plugins/diffeditor/diffeditorplugin.cpp +++ b/src/plugins/diffeditor/diffeditorplugin.cpp @@ -297,6 +297,25 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data() /////////// + rows.clear(); + rows << RowData(_("ABCD")); + rows << RowData(_(""), TextLineData::Separator); + rows << RowData(_(""), TextLineData::Separator); + chunk.rows = rows; + patchText = header + _("@@ -1,2 +1,1 @@\n" + "-ABCD\n" + "-\n" + "+ABCD\n" + "\\ No newline at end of file\n"); + + QTest::newRow("Two last EOLs removed") << chunk + << fileName + << fileName + << true + << patchText; + + /////////// + rows.clear(); rows << RowData(_("ABCD")); rows << RowData(TextLineData::Separator, _("")); @@ -418,6 +437,26 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch_data() << fileName << false << patchText; + + /////////// + + rows.clear(); + rows << RowData(_("ABCD")); + rows << RowData(TextLineData::Separator, _("")); + rows << RowData(_(""), _("EFGH")); + chunk.rows = rows; + patchText = header + _("@@ -1,1 +1,3 @@\n" + " ABCD\n" + "+\n" + "+EFGH\n" + "\\ No newline at end of file\n"); + + QTest::newRow("Blank line followed by No newline") + << chunk + << fileName + << fileName + << true + << patchText; } void DiffEditor::Internal::DiffEditorPlugin::testMakePatch() @@ -748,6 +787,37 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data() QTest::newRow("2 chunks - first ends with blank line") << patch << fileDataList4; + + ////////////// + + patch = _("diff --git a/file foo.txt b/file foo.txt\n" + "index 1234567..9876543 100644\n" + "--- a/file foo.txt\n" + "+++ b/file foo.txt\n" + "@@ -1,1 +1,3 @@ void DiffEditor::ctor()\n" + " ABCD\n" + "+\n" + "+EFGH\n" + "\\ No newline at end of file\n"); + + fileData1.leftFileInfo = DiffFileInfo(_("file foo.txt"), _("1234567")); + fileData1.rightFileInfo = DiffFileInfo(_("file foo.txt"), _("9876543")); + fileData1.fileOperation = FileData::ChangeFile; + chunkData1.leftStartingLineNumber = 0; + chunkData1.rightStartingLineNumber = 0; + rows1.clear(); + rows1 << RowData(_("ABCD")); + rows1 << RowData(TextLineData::Separator, _("")); + rows1 << RowData(_(""), _("EFGH")); + chunkData1.rows = rows1; + fileData1.chunks.clear(); + fileData1.chunks << chunkData1; + + QList fileDataList5; + fileDataList5 << fileData1; + + QTest::newRow("Blank line followed by No newline") << patch + << fileDataList5; } void DiffEditor::Internal::DiffEditorPlugin::testReadPatch() -- cgit v1.2.1