Skip to content

Commit 08681f3

Browse files
committed
refactor
adjust Git sink to fit into to conform to project convetions
1 parent 75f24e7 commit 08681f3

File tree

3 files changed

+89
-85
lines changed

3 files changed

+89
-85
lines changed

gix-diff/src/blob/git_diff.rs

+4-85
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ pub struct ChangeGroup {
6363
/// Range indicating the lines of the previous block.
6464
/// To actually see how the previous block looked like, you need to combine this range with
6565
/// the [`InternedInput`].
66-
before: Range<usize>,
66+
pub before: Range<usize>,
6767
/// Range indicating the lines of the new block
6868
/// To actually see how the current block looks like, you need to combine this range with
6969
/// the [`InternedInput`].
70-
after: Range<usize>,
71-
change_kind: ChangeKind,
70+
pub after: Range<usize>,
71+
/// Further specify what kind of change is denoted by the ranges above.
72+
pub change_kind: ChangeKind,
7273
}
7374

7475
/// A [`Sink`] that creates a diff like git would.
@@ -316,85 +317,3 @@ where
316317
self.changes
317318
}
318319
}
319-
320-
#[test]
321-
fn git_diff_test() {
322-
let before = r#"struct SomeStruct {
323-
field1: f64,
324-
field2: f64,
325-
}
326-
327-
fn main() {
328-
// Some comment
329-
let c = SomeStruct { field1: 10.0, field2: 10.0 };
330-
331-
println!(
332-
"Print field1 from SomeStruct {}",
333-
get_field1(&c)
334-
);
335-
}
336-
337-
fn get_field1(c: &SomeStruct) -> f64 {
338-
c.field1
339-
}
340-
"#;
341-
342-
let after = r#"/// This is a struct
343-
struct SomeStruct {
344-
field1: f64,
345-
field2: f64,
346-
}
347-
348-
fn main() {
349-
let c = SomeStruct { field1: 10.0, field2: 10.0 };
350-
351-
println!(
352-
"Print field1 and field2 from SomeStruct {} {}",
353-
get_field1(&c), get_field2(&c)
354-
);
355-
println!("Print another line");
356-
}
357-
358-
fn get_field1(c: &SomeStruct) -> f64 {
359-
c.field1
360-
}
361-
362-
fn get_field2(c: &SomeStruct) -> f64 {
363-
c.field2
364-
}
365-
"#;
366-
use crate::blob::git_diff::ChangeKind;
367-
368-
let input = InternedInput::new(before, after);
369-
let diff = imara_diff::diff(imara_diff::Algorithm::Histogram, &input, GitDiff::new(&input));
370-
assert_eq!(
371-
diff,
372-
vec![
373-
ChangeGroup {
374-
before: 0..0,
375-
after: 0..1,
376-
change_kind: ChangeKind::Added
377-
},
378-
ChangeGroup {
379-
before: 6..7,
380-
after: 7..7,
381-
change_kind: ChangeKind::RemovedBelow
382-
},
383-
ChangeGroup {
384-
before: 10..12,
385-
after: 10..12,
386-
change_kind: ChangeKind::Modified
387-
},
388-
ChangeGroup {
389-
before: 13..13,
390-
after: 13..14,
391-
change_kind: ChangeKind::Added
392-
},
393-
ChangeGroup {
394-
before: 17..17,
395-
after: 19..23,
396-
change_kind: ChangeKind::Added
397-
}
398-
]
399-
);
400-
}

gix-diff/tests/diff/blob/git_diff.rs

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
use gix_diff::blob::intern::InternedInput;
2+
use gix_diff::blob::{Algorithm, ChangeGroup, ChangeKind, GitDiff};
3+
4+
#[test]
5+
fn basic() {
6+
let before = r#"struct SomeStruct {
7+
field1: f64,
8+
field2: f64,
9+
}
10+
11+
fn main() {
12+
// Some comment
13+
let c = SomeStruct { field1: 10.0, field2: 10.0 };
14+
15+
println!(
16+
"Print field1 from SomeStruct {}",
17+
get_field1(&c)
18+
);
19+
}
20+
21+
fn get_field1(c: &SomeStruct) -> f64 {
22+
c.field1
23+
}
24+
"#;
25+
26+
let after = r#"/// This is a struct
27+
struct SomeStruct {
28+
field1: f64,
29+
field2: f64,
30+
}
31+
32+
fn main() {
33+
let c = SomeStruct { field1: 10.0, field2: 10.0 };
34+
35+
println!(
36+
"Print field1 and field2 from SomeStruct {} {}",
37+
get_field1(&c), get_field2(&c)
38+
);
39+
println!("Print another line");
40+
}
41+
42+
fn get_field1(c: &SomeStruct) -> f64 {
43+
c.field1
44+
}
45+
46+
fn get_field2(c: &SomeStruct) -> f64 {
47+
c.field2
48+
}
49+
"#;
50+
use crate::blob::git_diff::ChangeKind;
51+
52+
let input = InternedInput::new(before, after);
53+
let diff = gix_diff::blob::diff(Algorithm::Histogram, &input, GitDiff::new(&input));
54+
assert_eq!(
55+
diff,
56+
vec![
57+
ChangeGroup {
58+
before: 0..0,
59+
after: 0..1,
60+
change_kind: ChangeKind::Added
61+
},
62+
ChangeGroup {
63+
before: 6..7,
64+
after: 7..7,
65+
change_kind: ChangeKind::RemovedBelow
66+
},
67+
ChangeGroup {
68+
before: 10..12,
69+
after: 10..12,
70+
change_kind: ChangeKind::Modified
71+
},
72+
ChangeGroup {
73+
before: 13..13,
74+
after: 13..14,
75+
change_kind: ChangeKind::Added
76+
},
77+
ChangeGroup {
78+
before: 17..17,
79+
after: 19..23,
80+
change_kind: ChangeKind::Added
81+
}
82+
]
83+
);
84+
}

gix-diff/tests/diff/blob/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod git_diff;
12
pub(crate) mod pipeline;
23
mod platform;
34
mod unified_diff;

0 commit comments

Comments
 (0)