Skip to content

Commit 8517f10

Browse files
gcanatByron
authored andcommitted
feat!: add ContextSize struct.
That way it's possible to update it in future, for instance to add assymetric context options. Co-authored-by: Sebastian Thiel <[email protected]> 1733756156 +0100
1 parent 6f81859 commit 8517f10

File tree

3 files changed

+192
-135
lines changed

3 files changed

+192
-135
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//!
3131
//! ```
3232
//! use imara_diff::intern::InternedInput;
33-
//! use imara_diff::{diff, Algorithm, UnifiedDiffBuilder};
33+
//! use imara_diff::{diff, Algorithm, UnifiedDiffBuilder, unified_diff};
3434
//!
3535
//! let before = r#"fn foo() -> Bar {
3636
//! let mut foo = 2;
@@ -49,7 +49,7 @@
4949
//! "#;
5050
//!
5151
//! let input = InternedInput::new(before, after);
52-
//! let diff = diff(Algorithm::Histogram, &input, UnifiedDiffBuilder::new(&input, None));
52+
//! let diff = diff(Algorithm::Histogram, &input, UnifiedDiffBuilder::new(&input, unified_diff::ContextSize::symmetrical(3)));
5353
//! assert_eq!(
5454
//! diff,
5555
//! r#"@@ -1,5 +1,8 @@
@@ -150,7 +150,7 @@
150150
//! ```
151151
152152
#[cfg(feature = "unified_diff")]
153-
pub use unified_diff::UnifiedDiffBuilder;
153+
pub use unified_diff::_impl::UnifiedDiffBuilder;
154154

155155
use crate::intern::{InternedInput, Token, TokenSource};
156156
pub use crate::sink::Sink;
@@ -160,7 +160,7 @@ mod myers;
160160
pub mod sink;
161161
pub mod sources;
162162
#[cfg(feature = "unified_diff")]
163-
mod unified_diff;
163+
pub mod unified_diff;
164164
mod util;
165165

166166
#[cfg(test)]

src/tests.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use expect_test::{expect, expect_file};
66

77
use crate::intern::InternedInput;
88
use crate::sink::Counter;
9-
use crate::{diff, Algorithm, UnifiedDiffBuilder};
9+
use crate::{diff, unified_diff::ContextSize, Algorithm, UnifiedDiffBuilder};
1010

1111
#[test]
1212
fn replace() {
@@ -28,7 +28,11 @@ fn foo() -> Bar{
2828
let input = InternedInput::new(before, after);
2929
for algorithm in Algorithm::ALL {
3030
println!("{algorithm:?}");
31-
let diff = diff(algorithm, &input, UnifiedDiffBuilder::new(&input, None));
31+
let diff = diff(
32+
algorithm,
33+
&input,
34+
UnifiedDiffBuilder::new(&input, ContextSize::default()),
35+
);
3236
expect![[r#"
3337
@@ -1,5 +1,8 @@
3438
+const TEST: i32 = 0;
@@ -55,7 +59,11 @@ fn identical_files() {
5559
for algorithm in Algorithm::ALL {
5660
println!("{algorithm:?}");
5761
let input = InternedInput::new(file, file);
58-
let diff = diff(algorithm, &input, UnifiedDiffBuilder::new(&input, None));
62+
let diff = diff(
63+
algorithm,
64+
&input,
65+
UnifiedDiffBuilder::new(&input, ContextSize::default()),
66+
);
5967
assert_eq!(diff, "");
6068
}
6169
}
@@ -76,7 +84,11 @@ fn simple_insert() {
7684
let mut input = InternedInput::new(before, after);
7785
for algorithm in Algorithm::ALL {
7886
println!("{algorithm:?}");
79-
let res = diff(algorithm, &input, UnifiedDiffBuilder::new(&input, None));
87+
let res = diff(
88+
algorithm,
89+
&input,
90+
UnifiedDiffBuilder::new(&input, ContextSize::default()),
91+
);
8092
expect![[r#"
8193
@@ -1,4 +1,5 @@
8294
fn foo() -> Bar{
@@ -89,7 +101,11 @@ fn simple_insert() {
89101

90102
swap(&mut input.before, &mut input.after);
91103

92-
let res = diff(algorithm, &input, UnifiedDiffBuilder::new(&input, None));
104+
let res = diff(
105+
algorithm,
106+
&input,
107+
UnifiedDiffBuilder::new(&input, ContextSize::default()),
108+
);
93109
expect![[r#"
94110
@@ -1,5 +1,4 @@
95111
fn foo() -> Bar{
@@ -129,11 +145,19 @@ fn hand_checked_udiffs() {
129145
let before = read_to_string(path_before).unwrap();
130146
let after = read_to_string(path_after).unwrap();
131147
let input = InternedInput::new(&*before, &*after);
132-
let diff_res = diff(algorithm, &input, UnifiedDiffBuilder::new(&input, None));
148+
let diff_res = diff(
149+
algorithm,
150+
&input,
151+
UnifiedDiffBuilder::new(&input, ContextSize::default()),
152+
);
133153
expect_file![path_diff].assert_eq(&diff_res);
134154
// test with a context of 5 lines
135155
let path_diff = test_dir.join(format!("{file}.{algorithm:?}_ctx5.diff"));
136-
let diff_res = diff(algorithm, &input, UnifiedDiffBuilder::new(&input, Some(5)));
156+
let diff_res = diff(
157+
algorithm,
158+
&input,
159+
UnifiedDiffBuilder::new(&input, ContextSize::symmetrical(5)),
160+
);
137161
expect_file![path_diff].assert_eq(&diff_res);
138162
}
139163
}

0 commit comments

Comments
 (0)