2
This code is derived from jgit (http://eclipse.org/jgit).
3
Copyright owners are documented in jgit's IP log.
5
This program and the accompanying materials are made available
6
under the terms of the Eclipse Distribution License v1.0 which
7
accompanies this distribution, is reproduced below, and is
8
available at http://www.eclipse.org/org/documents/edl-v10.php
12
Redistribution and use in source and binary forms, with or
13
without modification, are permitted provided that the following
16
- Redistributions of source code must retain the above copyright
17
notice, this list of conditions and the following disclaimer.
19
- Redistributions in binary form must reproduce the above
20
copyright notice, this list of conditions and the following
21
disclaimer in the documentation and/or other materials provided
22
with the distribution.
24
- Neither the name of the Eclipse Foundation, Inc. nor the
25
names of its contributors may be used to endorse or promote
26
products derived from this software without specific prior
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53
[NUnit.Framework.TestFixture]
54
public class DiffFormatterReflowTest
60
private FileHeader file;
62
private ByteArrayOutputStream @out;
64
private DiffFormatter fmt;
66
/// <exception cref="System.Exception"></exception>
67
[NUnit.Framework.SetUp]
68
public virtual void SetUp()
70
@out = new ByteArrayOutputStream();
71
fmt = new DiffFormatter(@out);
74
/// <exception cref="System.IO.IOException"></exception>
75
[NUnit.Framework.Test]
76
public virtual void TestNegativeContextFails()
82
NUnit.Framework.Assert.Fail("accepted negative context");
84
catch (ArgumentException)
90
/// <exception cref="System.IO.IOException"></exception>
91
[NUnit.Framework.Test]
92
public virtual void TestContext0()
99
/// <exception cref="System.IO.IOException"></exception>
100
[NUnit.Framework.Test]
101
public virtual void TestContext1()
108
/// <exception cref="System.IO.IOException"></exception>
109
[NUnit.Framework.Test]
110
public virtual void TestContext3()
117
/// <exception cref="System.IO.IOException"></exception>
118
[NUnit.Framework.Test]
119
public virtual void TestContext5()
126
/// <exception cref="System.IO.IOException"></exception>
127
[NUnit.Framework.Test]
128
public virtual void TestContext10()
135
/// <exception cref="System.IO.IOException"></exception>
136
[NUnit.Framework.Test]
137
public virtual void TestContext100()
144
/// <exception cref="System.IO.IOException"></exception>
145
[NUnit.Framework.Test]
146
public virtual void TestEmpty1()
149
AssertFormatted("E.patch");
152
/// <exception cref="System.IO.IOException"></exception>
153
[NUnit.Framework.Test]
154
public virtual void TestNoNewLine1()
157
AssertFormatted("Y.patch");
160
/// <exception cref="System.IO.IOException"></exception>
161
[NUnit.Framework.Test]
162
public virtual void TestNoNewLine2()
165
AssertFormatted("Z.patch");
168
/// <exception cref="System.IO.IOException"></exception>
169
private void Init(string name)
171
a = new RawText(ReadFile(name + "_PreImage"));
172
b = new RawText(ReadFile(name + "_PostImage"));
173
file = ParseTestPatchFile(name + ".patch").GetFiles()[0];
176
/// <exception cref="System.IO.IOException"></exception>
177
private void AssertFormatted()
179
AssertFormatted(Sharpen.Extensions.GetTestName() + ".out");
182
/// <exception cref="System.IO.IOException"></exception>
183
private void AssertFormatted(string name)
185
fmt.Format(file, a, b);
186
string exp = RawParseUtils.Decode(ReadFile(name));
187
NUnit.Framework.Assert.AreEqual(exp, RawParseUtils.Decode(@out.ToByteArray()));
190
/// <exception cref="System.IO.IOException"></exception>
191
private byte[] ReadFile(string patchFile)
193
InputStream @in = GetType().GetResourceAsStream(patchFile);
196
NUnit.Framework.Assert.Fail("No " + patchFile + " test vector");
202
byte[] buf = new byte[1024];
203
ByteArrayOutputStream temp = new ByteArrayOutputStream();
205
while ((n = @in.Read(buf)) > 0)
207
temp.Write(buf, 0, n);
209
return temp.ToByteArray();
217
/// <exception cref="System.IO.IOException"></exception>
218
private NGit.Patch.Patch ParseTestPatchFile(string patchFile)
220
InputStream @in = GetType().GetResourceAsStream(patchFile);
223
NUnit.Framework.Assert.Fail("No " + patchFile + " test vector");
229
NGit.Patch.Patch p = new NGit.Patch.Patch();