View | Details | Raw Unified | Return to bug 71374 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/compare/tests/PatchTest.java (-108 / +7 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.compare.tests;
11
package org.eclipse.compare.tests;
12
12
13
import java.io.BufferedInputStream;
14
import java.io.BufferedReader;
13
import java.io.BufferedReader;
15
import java.io.ByteArrayInputStream;
14
import java.io.ByteArrayInputStream;
16
import java.io.File;
15
import java.io.File;
Lines 36-54 Link Here
36
35
37
import junit.framework.Assert;
36
import junit.framework.Assert;
38
import junit.framework.AssertionFailedError;
37
import junit.framework.AssertionFailedError;
39
import junit.framework.TestCase;
40
38
41
import org.eclipse.compare.internal.Utilities;
42
import org.eclipse.compare.internal.core.patch.FileDiff;
39
import org.eclipse.compare.internal.core.patch.FileDiff;
43
import org.eclipse.compare.internal.core.patch.FileDiffResult;
40
import org.eclipse.compare.internal.core.patch.FileDiffResult;
44
import org.eclipse.compare.internal.core.patch.LineReader;
41
import org.eclipse.compare.internal.core.patch.LineReader;
45
import org.eclipse.compare.internal.patch.WorkspacePatcher;
42
import org.eclipse.compare.internal.patch.WorkspacePatcher;
46
import org.eclipse.compare.patch.ApplyPatchOperation;
43
import org.eclipse.compare.patch.ApplyPatchOperation;
47
import org.eclipse.compare.patch.IFilePatch;
44
import org.eclipse.compare.patch.IFilePatch;
48
import org.eclipse.compare.patch.IFilePatchResult;
49
import org.eclipse.compare.patch.PatchConfiguration;
45
import org.eclipse.compare.patch.PatchConfiguration;
50
import org.eclipse.core.resources.IStorage;
46
import org.eclipse.core.resources.IStorage;
51
import org.eclipse.core.resources.ResourcesPlugin;
52
import org.eclipse.core.runtime.CoreException;
47
import org.eclipse.core.runtime.CoreException;
53
import org.eclipse.core.runtime.FileLocator;
48
import org.eclipse.core.runtime.FileLocator;
54
import org.eclipse.core.runtime.IPath;
49
import org.eclipse.core.runtime.IPath;
Lines 56-92 Link Here
56
import org.eclipse.core.runtime.Path;
51
import org.eclipse.core.runtime.Path;
57
import org.eclipse.core.runtime.Platform;
52
import org.eclipse.core.runtime.Platform;
58
import org.eclipse.core.runtime.Status;
53
import org.eclipse.core.runtime.Status;
59
import org.osgi.framework.Bundle;
60
61
public class PatchTest extends TestCase {
62
54
55
public class PatchTest extends AbstractPatchTest {
56
	
63
	private static final String PATCHDATA = "patchdata";
57
	private static final String PATCHDATA = "patchdata";
64
	private static final String PATCH_CONFIGURATION = "patchConfiguration.properties";
58
	private static final String PATCH_CONFIGURATION = "patchConfiguration.properties";
65
	
59
	
66
	Properties defaultPatchProperties;
60
	Properties defaultPatchProperties;
67
	
61
	
68
	class StringStorage implements IStorage {
69
		String fileName;
70
		public StringStorage(String old) {
71
			fileName = old;
72
		}
73
		public Object getAdapter(Class adapter) {
74
			return null;
75
		}
76
		public boolean isReadOnly() {
77
			return false;
78
		}
79
		public String getName() {
80
			return fileName;
81
		}
82
		public IPath getFullPath() {
83
			return null;
84
		}
85
		public InputStream getContents() throws CoreException {
86
			return new BufferedInputStream(asInputStream(fileName));
87
		}
88
	}
89
	
90
	class FileStorage implements IStorage {
62
	class FileStorage implements IStorage {
91
		File file;
63
		File file;
92
		public FileStorage(File file) {
64
		public FileStorage(File file) {
Lines 161-167 Link Here
161
		defaultPatchProperties.setProperty("expectedResultFile", "exp_context.txt");
133
		defaultPatchProperties.setProperty("expectedResultFile", "exp_context.txt");
162
		defaultPatchProperties.setProperty("fuzzFactor", "-1");
134
		defaultPatchProperties.setProperty("fuzzFactor", "-1");
163
	}
135
	}
164
136
	
137
	protected String getWorkingFolder() {
138
		return PATCHDATA;
139
	}
140
	
165
	protected void setUp() throws Exception {
141
	protected void setUp() throws Exception {
166
		// empty
142
		// empty
167
	}
143
	}
Lines 479-557 Link Here
479
	}
455
	}
480
456
481
457
482
	// Test changing
483
	private BufferedReader getReader(String name) {
484
		InputStream resourceAsStream = asInputStream(name);
485
		InputStreamReader reader2= new InputStreamReader(resourceAsStream);
486
		return new BufferedReader(reader2);
487
	}
488
489
	private InputStream asInputStream(String name) {
490
		IPath path= new Path(PATCHDATA).append(name);
491
		try {
492
			URL url= new URL(getBundle().getEntry("/"), path.toString());
493
			return url.openStream();
494
		} catch (IOException e) {
495
			fail("Failed while reading " + name);
496
			return null; // never reached
497
		}
498
	}
499
500
	private void patch(final String old, String patch, String expt) throws CoreException, IOException {
501
		patcherPatch(old, patch, expt);
502
		filePatch(old, patch, expt);
503
	}
504
505
	private void filePatch(final String old, String patch, String expt) throws CoreException, IOException {
506
		LineReader lr= new LineReader(getReader(expt));
507
		List inLines= lr.readLines();
508
		String expected = LineReader.createString(false, inLines);
509
		
510
		IStorage oldStorage = new StringStorage(old);
511
		IStorage patchStorage = new StringStorage(patch);
512
		IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
513
		assertTrue(patches.length == 1);
514
		IFilePatchResult result = patches[0].apply(oldStorage, new PatchConfiguration(), null);
515
		assertTrue(result.hasMatches());
516
		assertFalse(result.hasRejects());
517
		InputStream actualStream = result.getPatchedContents();
518
		String actual = asString(actualStream);
519
		assertEquals(expected, actual);
520
	}
521
522
	private String asString(InputStream exptStream) throws IOException {
523
		return Utilities.readString(exptStream, ResourcesPlugin.getEncoding());
524
	}
525
526
	private void patcherPatch(String old, String patch, String expt) {
527
		LineReader lr= new LineReader(getReader(old));
528
		List inLines= lr.readLines();
529
530
		WorkspacePatcher patcher= new WorkspacePatcher();
531
		try {
532
			patcher.parse(getReader(patch));
533
		} catch (IOException e) {
534
			e.printStackTrace();
535
		}
536
		
537
		FileDiff[] diffs= patcher.getDiffs();
538
		Assert.assertEquals(diffs.length, 1);
539
		
540
		FileDiffResult diffResult = patcher.getDiffResult(diffs[0]);
541
		diffResult.patch(inLines, null);
542
		
543
		LineReader expectedContents= new LineReader(getReader(expt));
544
		List expectedLines= expectedContents.readLines();
545
		
546
		Object[] expected= expectedLines.toArray();
547
		Object[] result= inLines.toArray();
548
		
549
		Assert.assertEquals(expected.length, result.length);
550
		
551
		for (int i= 0; i < expected.length; i++)
552
			Assert.assertEquals(expected[i], result[i]);
553
	}
554
	
555
	private void patchWorkspace(String[] originalFiles, String patch,
458
	private void patchWorkspace(String[] originalFiles, String patch,
556
			String[] expectedOutcomeFiles, boolean reverse,
459
			String[] expectedOutcomeFiles, boolean reverse,
557
			int fuzzFactor) {
460
			int fuzzFactor) {
Lines 616-624 Link Here
616
			for (int j= 0; j < expected.length; j++)
519
			for (int j= 0; j < expected.length; j++)
617
				Assert.assertEquals(msg, expected[j], result[j]);
520
				Assert.assertEquals(msg, expected[j], result[j]);
618
		}
521
		}
619
	}
620
	
621
	private Bundle getBundle() {
622
		return CompareTestPlugin.getDefault().getBundle();
623
	}	
522
	}	
624
}
523
}
(-)src/org/eclipse/compare/tests/AllTests.java (+1 lines)
Lines 32-37 Link Here
32
		suite.addTestSuite(DiffTest.class);
32
		suite.addTestSuite(DiffTest.class);
33
		suite.addTestSuite(FileDiffResultTest.class);
33
		suite.addTestSuite(FileDiffResultTest.class);
34
		suite.addTestSuite(ContentMergeViewerTest.class);
34
		suite.addTestSuite(ContentMergeViewerTest.class);
35
		suite.addTestSuite(UnifiedDiffFormatterTest.class);
35
		//$JUnit-END$
36
		//$JUnit-END$
36
		return suite;
37
		return suite;
37
	}
38
	}
(-)patchdata/unifiedDiffFormatter/exp_no_newline.txt (+6 lines)
Added Link Here
1
[a]
2
[b1]
3
[c1]
4
[d1]
5
[e]
6
[f]
(-)patchdata/unifiedDiffFormatter/exp_additionA.txt (+13 lines)
Added Link Here
1
--- addition.txt	2005-05-09 12:14:04.000000000 +0200
Added Link Here
1
--- addition.txt	2005-05-09 12:14:04.000000000 +0200
Added Link Here
1
--- context.txt	20 Dec 2008 02:59:19 -0000
Added Link Here
1
--- addition.txt	2005-05-09 12:14:04.000000000 +0200
Added Link Here
1
[1]
2
[2]
3
[3]
4
[4]
5
[5]
6
[6]
7
[7]
8
[8]
9
[9]
(-)src/org/eclipse/compare/tests/AbstractPatchTest.java (+160 lines)
Added Link Here
1
--- exp_addition.txt	2005-05-09 12:14:04.000000000 +0200
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - implementation
10
 *******************************************************************************/
11
package org.eclipse.compare.tests;
12
13
import java.io.BufferedInputStream;
14
import java.io.BufferedReader;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.InputStreamReader;
18
import java.net.URL;
19
import java.util.List;
20
21
import junit.framework.Assert;
22
import junit.framework.TestCase;
23
24
import org.eclipse.compare.internal.Utilities;
25
import org.eclipse.compare.internal.core.patch.FileDiff;
26
import org.eclipse.compare.internal.core.patch.FileDiffResult;
27
import org.eclipse.compare.internal.core.patch.LineReader;
28
import org.eclipse.compare.internal.patch.WorkspacePatcher;
29
import org.eclipse.compare.patch.ApplyPatchOperation;
30
import org.eclipse.compare.patch.IFilePatch;
31
import org.eclipse.compare.patch.IFilePatchResult;
32
import org.eclipse.compare.patch.PatchConfiguration;
33
import org.eclipse.core.resources.IStorage;
34
import org.eclipse.core.resources.ResourcesPlugin;
35
import org.eclipse.core.runtime.CoreException;
36
import org.eclipse.core.runtime.IPath;
37
import org.eclipse.core.runtime.Path;
38
import org.osgi.framework.Bundle;
39
40
public abstract class AbstractPatchTest extends TestCase {
41
42
	public AbstractPatchTest() {
43
		super();
44
	}
45
46
	public AbstractPatchTest(String name) {
47
		super(name);
48
	}
49
50
	class StringStorage implements IStorage {
51
		String fileName;
52
53
		public StringStorage(String old) {
54
			fileName = old;
55
		}
56
57
		public Object getAdapter(Class adapter) {
58
			return null;
59
		}
60
61
		public boolean isReadOnly() {
62
			return false;
63
		}
64
65
		public String getName() {
66
			return fileName;
67
		}
68
69
		public IPath getFullPath() {
70
			return null;
71
		}
72
73
		public InputStream getContents() throws CoreException {
74
			return new BufferedInputStream(asInputStream(fileName));
75
		}
76
	}
77
78
	protected abstract String getWorkingFolder();
79
80
	protected BufferedReader getReader(String name) {
81
		InputStream resourceAsStream = asInputStream(name);
82
		InputStreamReader reader2 = new InputStreamReader(resourceAsStream);
83
		return new BufferedReader(reader2);
84
	}
85
86
	protected InputStream asInputStream(String name) {
87
		IPath path = new Path(getWorkingFolder()).append(name);
88
		try {
89
			URL url = new URL(getBundle().getEntry("/"), path.toString());
90
			return url.openStream();
91
		} catch (IOException e) {
92
			fail("Failed while reading " + name);
93
			return null; // never reached
94
		}
95
	}
96
97
	protected void patch(final String old, String patch, String expt)
98
			throws CoreException, IOException {
99
		patcherPatch(old, patch, expt);
100
		filePatch(old, patch, expt);
101
	}
102
103
	void filePatch(final String old, String patch, String expt)
104
			throws CoreException, IOException {
105
		LineReader lr = new LineReader(getReader(expt));
106
		List inLines = lr.readLines();
107
		String expected = LineReader.createString(false, inLines);
108
109
		IStorage oldStorage = new StringStorage(old);
110
		IStorage patchStorage = new StringStorage(patch);
111
		IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
112
		assertTrue(patches.length == 1);
113
		IFilePatchResult result = patches[0].apply(oldStorage,
114
				new PatchConfiguration(), null);
115
		assertTrue(result.hasMatches());
116
		assertFalse(result.hasRejects());
117
		InputStream actualStream = result.getPatchedContents();
118
		String actual = asString(actualStream);
119
		assertEquals(expected, actual);
120
	}
121
122
	protected String asString(InputStream exptStream) throws IOException {
123
		return Utilities.readString(exptStream, ResourcesPlugin.getEncoding());
124
	}
125
126
	void patcherPatch(String old, String patch, String expt) {
127
		LineReader lr = new LineReader(getReader(old));
128
		List inLines = lr.readLines();
129
130
		WorkspacePatcher patcher = new WorkspacePatcher();
131
		try {
132
			patcher.parse(getReader(patch));
133
		} catch (IOException e) {
134
			e.printStackTrace();
135
		}
136
137
		FileDiff[] diffs = patcher.getDiffs();
138
		Assert.assertEquals(diffs.length, 1);
139
140
		FileDiffResult diffResult = patcher.getDiffResult(diffs[0]);
141
		diffResult.patch(inLines, null);
142
143
		LineReader expectedContents = new LineReader(getReader(expt));
144
		List expectedLines = expectedContents.readLines();
145
146
		Object[] expected = expectedLines.toArray();
147
		Object[] result = inLines.toArray();
148
149
		Assert.assertEquals(expected.length, result.length);
150
151
		for (int i = 0; i < expected.length; i++)
152
			Assert.assertEquals(expected[i], result[i]);
153
	}
154
155
	protected Bundle getBundle() {
156
		return CompareTestPlugin.getDefault().getBundle();
157
	}
158
159
}
(-)patchdata/unifiedDiffFormatter/patchConfiguration.properties (+3 lines)
Added Link Here
1
#This directory contains data files for purpose of testing org.eclipse.compare.internal.UnifiedDiffFormatter class.
2
#The content should be skipped while running org.eclipse.compare.tests.PatchTest.testPatchdataSubfolders().
3
skipTest=true
(-)patchdata/unifiedDiffFormatter/no_newline.txt (+8 lines)
Added Link Here
1
--- context.txt	20 Dec 2008 02:59:19 -0000
Added Link Here
1
--- empty1.txt	24 Dec 2008 12:56:00 -0000
Added Link Here
1
[a]
2
[b]
3
[c]
4
[d]
5
[e]
6
[f]
(-)patchdata/unifiedDiffFormatter/exp_context.txt (+25 lines)
Added Link Here
1
[a]
2
[b]
3
[c]
4
[c1]
5
[c2]
6
[d]
7
[e]
8
[f]
9
[g]
10
[h]
11
[i1]
12
[j]
13
[k]
14
[l]
15
[m]
16
[n]
17
[p]
18
[q]
19
[r]
20
[s]
21
[s1]
22
[t]
23
[u]
24
[v]
25
[w]
(-)patchdata/unifiedDiffFormatter/exp_addition.txt (+10 lines)
Added Link Here
1
--- exp_addition.txt	2005-05-09 12:14:04.000000000 +0200
Added Link Here
1
[1]
2
[2]
3
[3]
4
[4]
5
[5]
6
[6]
7
[7]
8
[8]
9
[9]
(-)patchdata/unifiedDiffFormatter/context.txt (+24 lines)
Added Link Here
1
--- no_newline.txt	2005-05-09 12:14:04.000000000 +0200
Added Link Here
1
[a]
2
[b]
3
[c]
4
[d]
5
[e]
6
[f]
7
[g]
8
[h]
9
[i]
10
[j]
11
[k]
12
[l]
13
[m]
14
[n]
15
[o]
16
[p]
17
[q]
18
[r]
19
[s]
20
[t]
21
[u]
22
[v]
23
[w]
(-)patchdata/unifiedDiffFormatter/exp_addition2.txt (+9 lines)
Added Link Here
1
[1]
2
[2]
3
[3]
4
[4]
5
[5]
6
[6]
7
[7]
8
[8]
9
[9]
(-)src/org/eclipse/compare/tests/UnifiedDiffFormatterTest.java (+203 lines)
Added Link Here
1
--- addition.txt	2005-05-09 12:14:04.000000000 +0200
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Krzysztof Poglodzinski (intuicje@gmail.com) - initial API and implementation
10
 *     Mariusz Tanski (mariusztanski@gmail.com) - initial API and implementation
11
 *     Kacper Zdanowicz (kacper.zdanowicz@gmail.com) - initial API and implementation 
12
 *     IBM Corporation - implementation
13
 *******************************************************************************/
14
package org.eclipse.compare.tests;
15
16
import java.io.File;
17
import java.io.IOException;
18
import java.io.InputStream;
19
20
import org.eclipse.compare.CompareConfiguration;
21
import org.eclipse.compare.contentmergeviewer.ITokenComparator;
22
import org.eclipse.compare.contentmergeviewer.TokenComparator;
23
import org.eclipse.compare.internal.MergeViewerContentProvider;
24
import org.eclipse.compare.internal.UnifiedDiffFormatter;
25
import org.eclipse.compare.internal.merge.DocumentMerger;
26
import org.eclipse.compare.internal.merge.DocumentMerger.IDocumentMergerInput;
27
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.IPath;
29
import org.eclipse.core.runtime.Path;
30
import org.eclipse.jface.text.Document;
31
import org.eclipse.jface.text.IDocument;
32
import org.eclipse.jface.text.Position;
33
34
public class UnifiedDiffFormatterTest extends AbstractPatchTest {
35
36
	public UnifiedDiffFormatterTest(String name) {
37
		super(name);
38
	}
39
40
	private static final String TESTPATCHFILE = "testPatch.txt";
41
	
42
	protected void setUp() throws Exception {
43
		super.setUp();
44
		File file = getTestPatchFile();
45
		if (!file.exists()) {
46
			file.createNewFile();
47
		}
48
	}
49
	
50
	protected void tearDown() throws Exception {
51
		super.tearDown();
52
		getTestPatchFile().delete();
53
	}
54
	
55
	protected String getWorkingFolder() {
56
		return "patchdata/unifiedDiffFormatter";
57
	}
58
	
59
	class FormatterTestDocMerger implements IDocumentMergerInput {
60
61
		private Document fromDoc;
62
		private Document toDoc;
63
		
64
		public FormatterTestDocMerger(Document fromDoc, Document toDoc) {
65
			this.fromDoc = fromDoc;
66
			this.toDoc = toDoc;
67
		}
68
		public ITokenComparator createTokenComparator(String line) {
69
	            return new TokenComparator(line);
70
	    }
71
	    public CompareConfiguration getCompareConfiguration() {
72
	            return new CompareConfiguration();
73
	    }
74
	    public IDocument getDocument(char contributor) {
75
	            switch (contributor) {
76
	            case MergeViewerContentProvider.LEFT_CONTRIBUTOR:
77
	                    return fromDoc;
78
	            case MergeViewerContentProvider.RIGHT_CONTRIBUTOR:
79
	                    return toDoc;
80
	            default:
81
	                    return null;
82
	            }
83
	    }
84
	    public int getHunkStart() {
85
	            return 0;
86
	    }
87
	    public Position getRegion(char contributor) {
88
	            switch (contributor) {
89
	            case MergeViewerContentProvider.LEFT_CONTRIBUTOR:
90
	                    return new Position(0, fromDoc.getLength());
91
	            case MergeViewerContentProvider.RIGHT_CONTRIBUTOR:
92
	                    return new Position(0, toDoc.getLength());
93
	            }
94
	            return null;
95
	    }
96
	    public boolean isHunkOnLeft() {
97
	    	return false;
98
	    }
99
	    public boolean isIgnoreAncestor() {
100
	    	return true;
101
	    }
102
	    public boolean isPatchHunk() {
103
	    	return false;
104
	    }
105
	    public boolean isShowPseudoConflicts() {
106
	    	return false;
107
	    }
108
	    public boolean isThreeWay() {
109
	    	return false;
110
	    }
111
	    public boolean isPatchHunkOk() {
112
	    	return false;
113
	    }
114
	}
115
	
116
	public void testLeftEmptyPatch() throws CoreException, IOException {
117
		createPatch("addition.txt", "exp_addition.txt", "patch_additionA2.txt");
118
		patch("addition.txt", "exp_addition.txt");
119
	}
120
	
121
	public void testRightEmptyPatch() throws CoreException, IOException {
122
		createPatch("exp_addition.txt", "addition.txt", "patch_additionB2.txt");
123
		patch("exp_addition.txt", "addition.txt");
124
	}
125
	
126
	public void testEmptyFilesPatch() throws CoreException, IOException {
127
		createPatch("empty1.txt", "empty2.txt", "patch_empty.txt");
128
		patch("empty1.txt", "empty2.txt");
129
	}
130
	
131
	public void testUnterminatedCreatePatch() throws CoreException, IOException {
132
		createPatch("addition.txt", "exp_addition2.txt", "patch_additionC2.txt");
133
		patch("addition.txt", "exp_addition2.txt");
134
	}
135
	
136
	public void testCreateExamplePatch()throws CoreException, IOException {
137
		createPatch("context.txt", "exp_context.txt", "patch_additionD2.txt");
138
		patch("context.txt", "exp_context.txt");
139
	}
140
	
141
	public void testBothFilesWithoutEndingNewlinePatch()throws CoreException, IOException {
142
		createPatch("no_newline.txt", "exp_no_newline.txt", "patch_no_newline.txt");
143
		patch("no_newline.txt",  "exp_no_newline.txt");
144
	}
145
	
146
	private void patch(final String old, String expt) throws CoreException,	IOException {
147
		patch(old, TESTPATCHFILE, expt);
148
	}
149
	
150
	private void createPatch(String fromFilePath, String toFilePath, String expectedPatch) throws CoreException, IOException{
151
152
		final Document fromDoc = new Document(readFileToString(fromFilePath));
153
		final Document toDoc = new Document(readFileToString(toFilePath));
154
155
		DocumentMerger merger = new DocumentMerger(new FormatterTestDocMerger(fromDoc, toDoc));
156
		// Compare Editor calculates diffs while building the UI
157
		merger.doDiff();
158
159
		UnifiedDiffFormatter formatter = new UnifiedDiffFormatter(merger,
160
                fromDoc, toDoc, fromFilePath, toFilePath, false);		
161
		formatter.generateDiff(getTestPatchFile());
162
163
		String patchContent = readFileToString(TESTPATCHFILE);
164
		String expectedContent = readFileToString(expectedPatch);
165
		
166
		String[] patchContents = patchContent.split("\n");
167
		String[] expectedContents = expectedContent.split("\n");
168
		
169
		patchContent = getContentFromLines(patchContents);
170
		expectedContent = getContentFromLines(expectedContents);
171
		assertEquals(patchContent, expectedContent);
172
	}
173
	
174
	private File getTestPatchFile() throws IOException {
175
		IPath path= new Path(getWorkingFolder()).append(TESTPATCHFILE);
176
		return path.toFile();
177
	}
178
	
179
	private String readFileToString(String name) throws IOException {
180
		InputStream resourceAsStream = asInputStream(name);
181
		return asString(resourceAsStream);
182
	}
183
184
	private String getContentFromLines(String[] patchContents) {
185
		// TODO: test only part of the patch content 
186
		StringBuffer patchContent = new StringBuffer();
187
		for (int i = 0; i < patchContents.length; i++) {
188
			String line = patchContents[i];
189
			if (line.startsWith(UnifiedDiffFormatter.NEW_FILE_PREFIX)
190
					|| line.startsWith(UnifiedDiffFormatter.OLD_FILE_PREFIX)) {
191
				String[] line_split = line.split("\t");
192
				patchContent.append(line_split[0]);
193
				continue;
194
			} else if (line.startsWith(UnifiedDiffFormatter.INDEX_MARKER)
195
					|| line.startsWith(UnifiedDiffFormatter.DELIMITER)) {
196
				continue;
197
			}
198
			patchContent.append(line);
199
		}
200
		return patchContent.toString();
201
	}
202
}

Return to bug 71374