Add support for parsing "diff --cc" style patches
[egit/charleso.git] / org.spearce.jgit.test / tst / org / spearce / jgit / patch / PatchCcErrorTest.java
bloba2f3a19c411ea43019ff55524796b35f9daeaae7
1 /*
2 * Copyright (C) 2008, Google Inc.
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
21 * written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org.spearce.jgit.patch;
40 import java.io.IOException;
41 import java.io.InputStream;
43 import junit.framework.TestCase;
45 public class PatchCcErrorTest extends TestCase {
46 public void testError_CcTruncatedOld() throws IOException {
47 final Patch p = parseTestPatchFile();
48 assertEquals(1, p.getFiles().size());
49 assertEquals(3, p.getErrors().size());
51 final FormatError e = p.getErrors().get(0);
52 assertSame(FormatError.Severity.ERROR, e.getSeverity());
53 assertEquals(
54 "Truncated hunk, at least 1 lines is missing for ancestor 1",
55 e.getMessage());
56 assertEquals(346, e.getOffset());
57 assertTrue(e.getLineText().startsWith(
58 "@@@ -55,12 -163,13 +163,15 @@@ public "));
61 final FormatError e = p.getErrors().get(1);
62 assertSame(FormatError.Severity.ERROR, e.getSeverity());
63 assertEquals(
64 "Truncated hunk, at least 2 lines is missing for ancestor 2",
65 e.getMessage());
66 assertEquals(346, e.getOffset());
67 assertTrue(e.getLineText().startsWith(
68 "@@@ -55,12 -163,13 +163,15 @@@ public "));
71 final FormatError e = p.getErrors().get(2);
72 assertSame(FormatError.Severity.ERROR, e.getSeverity());
73 assertEquals("Truncated hunk, at least 3 new lines is missing", e
74 .getMessage());
75 assertEquals(346, e.getOffset());
76 assertTrue(e.getLineText().startsWith(
77 "@@@ -55,12 -163,13 +163,15 @@@ public "));
81 private Patch parseTestPatchFile() throws IOException {
82 final String patchFile = getName() + ".patch";
83 final InputStream in = getClass().getResourceAsStream(patchFile);
84 if (in == null) {
85 fail("No " + patchFile + " test vector");
86 return null; // Never happens
88 try {
89 final Patch p = new Patch();
90 p.parse(in);
91 return p;
92 } finally {
93 in.close();