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.

EditListTest.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (C) 2009, 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 org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.fail;
  13. import java.io.IOException;
  14. import java.io.InputStream;
  15. import org.eclipse.jgit.diff.Edit;
  16. import org.eclipse.jgit.diff.EditList;
  17. import org.junit.Test;
  18. public class EditListTest {
  19. @Test
  20. public void testHunkHeader() throws IOException {
  21. final Patch p = parseTestPatchFile("testGetText_BothISO88591.patch");
  22. final FileHeader fh = p.getFiles().get(0);
  23. final EditList list0 = fh.getHunks().get(0).toEditList();
  24. assertEquals(1, list0.size());
  25. assertEquals(new Edit(4 - 1, 5 - 1, 4 - 1, 5 - 1), list0.get(0));
  26. final EditList list1 = fh.getHunks().get(1).toEditList();
  27. assertEquals(1, list1.size());
  28. assertEquals(new Edit(16 - 1, 17 - 1, 16 - 1, 17 - 1), list1.get(0));
  29. }
  30. @Test
  31. public void testFileHeader() throws IOException {
  32. final Patch p = parseTestPatchFile("testGetText_BothISO88591.patch");
  33. final FileHeader fh = p.getFiles().get(0);
  34. final EditList e = fh.toEditList();
  35. assertEquals(2, e.size());
  36. assertEquals(new Edit(4 - 1, 5 - 1, 4 - 1, 5 - 1), e.get(0));
  37. assertEquals(new Edit(16 - 1, 17 - 1, 16 - 1, 17 - 1), e.get(1));
  38. }
  39. @Test
  40. public void testTypes() throws IOException {
  41. final Patch p = parseTestPatchFile("testEditList_Types.patch");
  42. final FileHeader fh = p.getFiles().get(0);
  43. final EditList e = fh.toEditList();
  44. assertEquals(3, e.size());
  45. assertEquals(new Edit(3 - 1, 3 - 1, 3 - 1, 4 - 1), e.get(0));
  46. assertEquals(new Edit(17 - 1, 19 - 1, 18 - 1, 18 - 1), e.get(1));
  47. assertEquals(new Edit(23 - 1, 25 - 1, 22 - 1, 28 - 1), e.get(2));
  48. }
  49. private Patch parseTestPatchFile(String patchFile) throws IOException {
  50. try (InputStream in = getClass().getResourceAsStream(patchFile)) {
  51. if (in == null) {
  52. fail("No " + patchFile + " test vector");
  53. return null; // Never happens
  54. }
  55. final Patch p = new Patch();
  56. p.parse(in);
  57. return p;
  58. }
  59. }
  60. }