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 (+4 lines)
Added Link Here
1
--- context.txt	20 Dec 2008 02:59:19 -0000
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 (+7 lines)
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 (+212 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
	}
45
	
46
	protected void tearDown() throws Exception {
47
		super.tearDown();
48
		getTestPatchFile().delete();
49
	}
50
	
51
	protected String getWorkingFolder() {
52
		return "patchdata/unifiedDiffFormatter";
53
	}
54
	
55
	class FormatterTestDocMerger implements IDocumentMergerInput {
56
57
		private Document fromDoc;
58
		private Document toDoc;
59
		
60
		public FormatterTestDocMerger(Document fromDoc, Document toDoc) {
61
			this.fromDoc = fromDoc;
62
			this.toDoc = toDoc;
63
		}
64
		public ITokenComparator createTokenComparator(String line) {
65
	            return new TokenComparator(line);
66
	    }
67
	    public CompareConfiguration getCompareConfiguration() {
68
	            return new CompareConfiguration();
69
	    }
70
	    public IDocument getDocument(char contributor) {
71
	            switch (contributor) {
72
	            case MergeViewerContentProvider.LEFT_CONTRIBUTOR:
73
	                    return fromDoc;
74
	            case MergeViewerContentProvider.RIGHT_CONTRIBUTOR:
75
	                    return toDoc;
76
	            default:
77
	                    return null;
78
	            }
79
	    }
80
	    public int getHunkStart() {
81
	            return 0;
82
	    }
83
	    public Position getRegion(char contributor) {
84
	            switch (contributor) {
85
	            case MergeViewerContentProvider.LEFT_CONTRIBUTOR:
86
	                    return new Position(0, fromDoc.getLength());
87
	            case MergeViewerContentProvider.RIGHT_CONTRIBUTOR:
88
	                    return new Position(0, toDoc.getLength());
89
	            }
90
	            return null;
91
	    }
92
	    public boolean isHunkOnLeft() {
93
	    	return false;
94
	    }
95
	    public boolean isIgnoreAncestor() {
96
	    	return true;
97
	    }
98
	    public boolean isPatchHunk() {
99
	    	return false;
100
	    }
101
	    public boolean isShowPseudoConflicts() {
102
	    	return false;
103
	    }
104
	    public boolean isThreeWay() {
105
	    	return false;
106
	    }
107
	    public boolean isPatchHunkOk() {
108
	    	return false;
109
	    }
110
	}
111
	
112
	public void testLeftEmptyPatch() throws CoreException, IOException {
113
		createPatch("addition.txt", "exp_addition.txt", "patch_additionA2.txt");
114
		patch("addition.txt", "exp_addition.txt");
115
	}
116
	
117
	public void testRightEmptyPatch() throws CoreException, IOException {
118
		createPatch("exp_addition.txt", "addition.txt", "patch_additionB2.txt");
119
		patch("exp_addition.txt", "addition.txt");
120
	}
121
	
122
	public void testEmptyFilesPatch() throws CoreException, IOException {
123
		createPatch("empty1.txt", "empty2.txt", "patch_empty.txt");
124
		patch("empty1.txt", "empty2.txt");
125
	}
126
	
127
	public void testUnterminatedCreatePatch() throws CoreException, IOException {
128
		createPatch("addition.txt", "exp_addition2.txt", "patch_additionC2.txt");
129
		patch("addition.txt", "exp_addition2.txt");
130
	}
131
	
132
	public void testCreateExamplePatch()throws CoreException, IOException {
133
		createPatch("context.txt", "exp_context.txt", "patch_additionD2.txt");
134
		patch("context.txt", "exp_context.txt");
135
	}
136
	
137
	public void testBothFilesWithoutEndingNewlinePatch()throws CoreException, IOException {
138
		createPatch("no_newline.txt", "exp_no_newline.txt", "patch_no_newline.txt");
139
		patch("no_newline.txt",  "exp_no_newline.txt");
140
	}
141
	
142
	private void patch(final String old, String expt) throws CoreException,	IOException {
143
		patch(old, TESTPATCHFILE, expt);
144
	}
145
	
146
	private void createPatch(String fromFilePath, String toFilePath, String expectedPatch) throws CoreException, IOException{
147
148
		final Document fromDoc = new Document(readFileToString(getTestFile(fromFilePath).getName()));
149
		final Document toDoc = new Document(readFileToString(getTestFile(toFilePath).getName()));
150
151
		DocumentMerger merger = new DocumentMerger(new FormatterTestDocMerger(fromDoc, toDoc));
152
		// Compare Editor calculates diffs while building the UI
153
		merger.doDiff();
154
155
		UnifiedDiffFormatter formatter = new UnifiedDiffFormatter(merger,
156
                fromDoc, toDoc, fromFilePath, toFilePath, false);		
157
		formatter.generateDiff(getTestPatchFile());
158
159
		String patchContent = readFileToString(TESTPATCHFILE);
160
		String expectedContent = readFileToString(expectedPatch);
161
		
162
		String[] patchContents = patchContent.split("\n");
163
		String[] expectedContents = expectedContent.split("\n");
164
		
165
		patchContent = getContentFromLines(patchContents);
166
		expectedContent = getContentFromLines(expectedContents);
167
		assertEquals(patchContent, expectedContent);
168
	}
169
	
170
	private File getTestPatchFile() throws IOException {
171
		return getTestFile(TESTPATCHFILE);
172
	}
173
	
174
	private File getTestFile(String _name) {
175
		IPath path= new Path(getWorkingFolder()).append(_name);
176
		File file = path.toFile();
177
		if(!file.exists())
178
			try {
179
				file.createNewFile();
180
				return file;
181
			} catch (IOException e) {
182
				fail("Failed while creating: " + _name);
183
				return null;
184
			}
185
		return file;
186
	}
187
	
188
	private String readFileToString(String name) throws IOException {
189
		InputStream resourceAsStream = asInputStream(name);
190
		return asString(resourceAsStream);
191
	}
192
193
	private String getContentFromLines(String[] patchContents) {
194
		// TODO: test only part of the patch content 
195
		StringBuffer patchContent = new StringBuffer();
196
		for (int i = 0; i < patchContents.length; i++) {
197
			String line = patchContents[i];
198
			if (line.startsWith(UnifiedDiffFormatter.NEW_FILE_PREFIX)
199
					|| line.startsWith(UnifiedDiffFormatter.OLD_FILE_PREFIX)) {
200
				String[] line_split = line.split("\t");
201
				patchContent.append(line_split[0]);
202
				continue;
203
			} else if (line.startsWith(UnifiedDiffFormatter.INDEX_MARKER)
204
					|| line.startsWith(UnifiedDiffFormatter.DELIMITER)) {
205
				continue;
206
			}
207
			patchContent.append(line);
208
		}
209
		return patchContent.toString();
210
	}
211
}

Return to bug 71374