1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.lib;
45
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.fail;
48
49 import java.io.IOException;
50 import java.nio.file.Files;
51 import java.nio.file.Path;
52 import java.nio.file.Paths;
53 import java.util.Arrays;
54 import java.util.List;
55
56 import org.eclipse.jgit.junit.RepositoryTestCase;
57 import org.junit.Test;
58
59 public class RebaseTodoFileTest extends RepositoryTestCase {
60
61 private static final String TEST_TODO = "test.todo";
62
63 private void createTodoList(String... lines) throws IOException {
64 Path p = Paths.get(db.getDirectory().getAbsolutePath(), TEST_TODO);
65 Files.write(p, Arrays.asList(lines));
66 }
67
68 @Test
69 public void testReadTodoFile() throws Exception {
70 String[] expected = { "reword " + ObjectId.zeroId().name() + " Foo",
71 "# A comment in the todo list",
72 "pick " + ObjectId.zeroId().name() + " Foo fie",
73 "squash " + ObjectId.zeroId().name() + " F",
74 "fixup " + ObjectId.zeroId().name(),
75 "edit " + ObjectId.zeroId().name() + " f",
76 "edit " + ObjectId.zeroId().name() + ' ' };
77 createTodoList(expected);
78 RebaseTodoFile todo = new RebaseTodoFile(db);
79 List<RebaseTodoLine> lines = todo.readRebaseTodo(TEST_TODO, true);
80 assertEquals("Expected 7 lines", 7, lines.size());
81 int i = 0;
82 for (RebaseTodoLine line : lines) {
83 switch (i) {
84 case 0:
85 assertEquals("Expected REWORD", RebaseTodoLine.Action.REWORD,
86 line.getAction());
87 assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
88 line.getCommit());
89 assertEquals("Unexpected Message", "Foo",
90 line.getShortMessage());
91 break;
92 case 1:
93 assertEquals("Expected COMMENT", RebaseTodoLine.Action.COMMENT,
94 line.getAction());
95 assertEquals("Unexpected Message",
96 "# A comment in the todo list",
97 line.getComment());
98 break;
99 case 2:
100 assertEquals("Expected PICK", RebaseTodoLine.Action.PICK,
101 line.getAction());
102 assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
103 line.getCommit());
104 assertEquals("Unexpected Message", "Foo fie",
105 line.getShortMessage());
106 break;
107 case 3:
108 assertEquals("Expected SQUASH", RebaseTodoLine.Action.SQUASH,
109 line.getAction());
110 assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
111 line.getCommit());
112 assertEquals("Unexpected Message", "F", line.getShortMessage());
113 break;
114 case 4:
115 assertEquals("Expected FIXUP", RebaseTodoLine.Action.FIXUP,
116 line.getAction());
117 assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
118 line.getCommit());
119 assertEquals("Unexpected Message", "", line.getShortMessage());
120 break;
121 case 5:
122 assertEquals("Expected EDIT", RebaseTodoLine.Action.EDIT,
123 line.getAction());
124 assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
125 line.getCommit());
126 assertEquals("Unexpected Message", "f", line.getShortMessage());
127 break;
128 case 6:
129 assertEquals("Expected EDIT", RebaseTodoLine.Action.EDIT,
130 line.getAction());
131 assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
132 line.getCommit());
133 assertEquals("Unexpected Message", "", line.getShortMessage());
134 break;
135 default:
136 fail("Too many lines");
137 return;
138 }
139 i++;
140 }
141 }
142 }