You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PatchCcErrorTest.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (C) 2008, Google Inc. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.patch;
  11. import static java.lang.Integer.valueOf;
  12. import static org.junit.Assert.assertEquals;
  13. import static org.junit.Assert.assertSame;
  14. import static org.junit.Assert.assertTrue;
  15. import static org.junit.Assert.fail;
  16. import java.io.IOException;
  17. import java.io.InputStream;
  18. import java.text.MessageFormat;
  19. import org.eclipse.jgit.internal.JGitText;
  20. import org.eclipse.jgit.junit.JGitTestUtil;
  21. import org.junit.Test;
  22. public class PatchCcErrorTest {
  23. @Test
  24. public void testError_CcTruncatedOld() throws IOException {
  25. final Patch p = parseTestPatchFile();
  26. assertEquals(1, p.getFiles().size());
  27. assertEquals(3, p.getErrors().size());
  28. {
  29. final FormatError e = p.getErrors().get(0);
  30. assertSame(FormatError.Severity.ERROR, e.getSeverity());
  31. assertEquals(MessageFormat.format(
  32. JGitText.get().truncatedHunkLinesMissingForAncestor,
  33. valueOf(1), valueOf(1)), e.getMessage());
  34. assertEquals(346, e.getOffset());
  35. assertTrue(e.getLineText().startsWith(
  36. "@@@ -55,12 -163,13 +163,15 @@@ public "));
  37. }
  38. {
  39. final FormatError e = p.getErrors().get(1);
  40. assertSame(FormatError.Severity.ERROR, e.getSeverity());
  41. assertEquals(MessageFormat.format(
  42. JGitText.get().truncatedHunkLinesMissingForAncestor,
  43. valueOf(2), valueOf(2)), e.getMessage());
  44. assertEquals(346, e.getOffset());
  45. assertTrue(e.getLineText().startsWith(
  46. "@@@ -55,12 -163,13 +163,15 @@@ public "));
  47. }
  48. {
  49. final FormatError e = p.getErrors().get(2);
  50. assertSame(FormatError.Severity.ERROR, e.getSeverity());
  51. assertEquals("Truncated hunk, at least 3 new lines is missing", e
  52. .getMessage());
  53. assertEquals(346, e.getOffset());
  54. assertTrue(e.getLineText().startsWith(
  55. "@@@ -55,12 -163,13 +163,15 @@@ public "));
  56. }
  57. }
  58. private Patch parseTestPatchFile() throws IOException {
  59. final String patchFile = JGitTestUtil.getName() + ".patch";
  60. try (InputStream in = getClass().getResourceAsStream(patchFile)) {
  61. if (in == null) {
  62. fail("No " + patchFile + " test vector");
  63. return null; // Never happens
  64. }
  65. final Patch p = new Patch();
  66. p.parse(in);
  67. return p;
  68. }
  69. }
  70. }