Skip to content

Commit b3118f0

Browse files
Demonstration of bug
1 parent 1b1927a commit b3118f0

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

crates/but-hunk-dependency/src/ranges/tests/workspace.rs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,100 @@ fn workspace_simple() -> anyhow::Result<()> {
9393
Ok(())
9494
}
9595

96+
#[test]
97+
fn overlapping_commits_in_a_stack() -> anyhow::Result<()> {
98+
let path = BString::from("/test.txt");
99+
100+
let commit1_id = id_from_hex_char('1');
101+
let commit2_id = id_from_hex_char('2');
102+
let stack1_id = StackId::generate();
103+
104+
let commit3_id = id_from_hex_char('3');
105+
let stack2_id = StackId::generate();
106+
107+
let workspace_ranges = WorkspaceRanges::try_from_stacks(vec![
108+
InputStack {
109+
stack_id: stack1_id,
110+
commits_from_base_to_tip: vec![
111+
InputCommit {
112+
commit_id: commit1_id,
113+
files: vec![InputFile {
114+
path: path.clone(),
115+
change_type: TreeStatusKind::Modification,
116+
hunks: vec![input_hunk_from_unified_diff(
117+
"@@ -1,4 +1,9 @@
118+
1
119+
+P1
120+
+P2
121+
+P3
122+
+P4
123+
+P5
124+
2
125+
3
126+
4
127+
",
128+
)?],
129+
}],
130+
},
131+
InputCommit {
132+
commit_id: commit2_id,
133+
files: vec![InputFile {
134+
path: path.clone(),
135+
change_type: TreeStatusKind::Modification,
136+
hunks: vec![input_hunk_from_unified_diff(
137+
"@@ -1,6 +1,7 @@
138+
1
139+
P1
140+
P2
141+
+Q1
142+
P3
143+
P4
144+
P5
145+
",
146+
)?],
147+
}],
148+
},
149+
],
150+
},
151+
InputStack {
152+
stack_id: stack2_id,
153+
commits_from_base_to_tip: vec![InputCommit {
154+
commit_id: commit3_id,
155+
files: vec![InputFile {
156+
change_type: TreeStatusKind::Modification,
157+
path: path.clone(),
158+
hunks: vec![input_hunk_from_unified_diff(
159+
"@@ -3,6 +3,7 @@
160+
3
161+
4
162+
5
163+
+R1
164+
6
165+
7
166+
8
167+
",
168+
)?],
169+
}],
170+
}],
171+
},
172+
])?;
173+
174+
{
175+
// According to stack2, R1 is on line 6. But stack1 added 6 lines before
176+
// that, so R1 should be on line 12. But the line_shift of commit1 is
177+
// double-counted.
178+
// DO NOT SUBMIT
179+
// The bug needs to be fixed and the 17 below needs to be changed to 12
180+
// before submitting
181+
let dependencies = workspace_ranges.intersection(&path, 17, 1).unwrap();
182+
assert_eq!(dependencies.len(), 1);
183+
assert_eq!(dependencies[0].commit_id, commit3_id);
184+
assert_eq!(dependencies[0].stack_id, stack2_id);
185+
}
186+
187+
Ok(())
188+
}
189+
96190
#[test]
97191
fn gracefully_handle_invalid_input_commits() -> anyhow::Result<()> {
98192
let path = BString::from("/test.txt");

0 commit comments

Comments
 (0)