Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

RebaseTodoFileTest.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2019, Thomas Wolf <thomas.wolf@paranor.ch> 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.lib;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.fail;
  13. import java.io.IOException;
  14. import java.nio.file.Files;
  15. import java.nio.file.Path;
  16. import java.nio.file.Paths;
  17. import java.util.Arrays;
  18. import java.util.List;
  19. import org.eclipse.jgit.junit.RepositoryTestCase;
  20. import org.junit.Test;
  21. public class RebaseTodoFileTest extends RepositoryTestCase {
  22. private static final String TEST_TODO = "test.todo";
  23. private void createTodoList(String... lines) throws IOException {
  24. Path p = Paths.get(db.getDirectory().getAbsolutePath(), TEST_TODO);
  25. Files.write(p, Arrays.asList(lines));
  26. }
  27. @Test
  28. public void testReadTodoFile() throws Exception {
  29. String[] expected = { "reword " + ObjectId.zeroId().name() + " Foo",
  30. "# A comment in the todo list",
  31. "pick " + ObjectId.zeroId().name() + " Foo fie",
  32. "squash " + ObjectId.zeroId().name() + " F",
  33. "fixup " + ObjectId.zeroId().name(),
  34. "edit " + ObjectId.zeroId().name() + " f",
  35. "edit " + ObjectId.zeroId().name() + ' ' };
  36. createTodoList(expected);
  37. RebaseTodoFile todo = new RebaseTodoFile(db);
  38. List<RebaseTodoLine> lines = todo.readRebaseTodo(TEST_TODO, true);
  39. assertEquals("Expected 7 lines", 7, lines.size());
  40. int i = 0;
  41. for (RebaseTodoLine line : lines) {
  42. switch (i) {
  43. case 0:
  44. assertEquals("Expected REWORD", RebaseTodoLine.Action.REWORD,
  45. line.getAction());
  46. assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
  47. line.getCommit());
  48. assertEquals("Unexpected Message", "Foo",
  49. line.getShortMessage());
  50. break;
  51. case 1:
  52. assertEquals("Expected COMMENT", RebaseTodoLine.Action.COMMENT,
  53. line.getAction());
  54. assertEquals("Unexpected Message",
  55. "# A comment in the todo list",
  56. line.getComment());
  57. break;
  58. case 2:
  59. assertEquals("Expected PICK", RebaseTodoLine.Action.PICK,
  60. line.getAction());
  61. assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
  62. line.getCommit());
  63. assertEquals("Unexpected Message", "Foo fie",
  64. line.getShortMessage());
  65. break;
  66. case 3:
  67. assertEquals("Expected SQUASH", RebaseTodoLine.Action.SQUASH,
  68. line.getAction());
  69. assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
  70. line.getCommit());
  71. assertEquals("Unexpected Message", "F", line.getShortMessage());
  72. break;
  73. case 4:
  74. assertEquals("Expected FIXUP", RebaseTodoLine.Action.FIXUP,
  75. line.getAction());
  76. assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
  77. line.getCommit());
  78. assertEquals("Unexpected Message", "", line.getShortMessage());
  79. break;
  80. case 5:
  81. assertEquals("Expected EDIT", RebaseTodoLine.Action.EDIT,
  82. line.getAction());
  83. assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
  84. line.getCommit());
  85. assertEquals("Unexpected Message", "f", line.getShortMessage());
  86. break;
  87. case 6:
  88. assertEquals("Expected EDIT", RebaseTodoLine.Action.EDIT,
  89. line.getAction());
  90. assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
  91. line.getCommit());
  92. assertEquals("Unexpected Message", "", line.getShortMessage());
  93. break;
  94. default:
  95. fail("Too many lines");
  96. return;
  97. }
  98. i++;
  99. }
  100. }
  101. }