summaryrefslogtreecommitdiffstats
path: root/vendor/similar/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/similar/src
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/similar/src')
-rw-r--r--vendor/similar/src/algorithms/lcs.rs16
-rw-r--r--vendor/similar/src/algorithms/myers.rs2
-rw-r--r--vendor/similar/src/algorithms/snapshots/similar__algorithms__lcs__same.snap12
-rw-r--r--vendor/similar/src/algorithms/utils.rs2
-rw-r--r--vendor/similar/src/text/mod.rs25
-rw-r--r--vendor/similar/src/udiff.rs2
-rw-r--r--vendor/similar/src/utils.rs4
7 files changed, 46 insertions, 17 deletions
diff --git a/vendor/similar/src/algorithms/lcs.rs b/vendor/similar/src/algorithms/lcs.rs
index 6d1af687e..5eb3a63d0 100644
--- a/vendor/similar/src/algorithms/lcs.rs
+++ b/vendor/similar/src/algorithms/lcs.rs
@@ -64,6 +64,12 @@ where
let common_prefix_len = common_prefix_len(old, old_range.clone(), new, new_range.clone());
let common_suffix_len = common_suffix_len(old, old_range.clone(), new, new_range.clone());
+ // If the sequences are not different then we're done
+ if common_prefix_len == old_range.len() && (old_range.len() == new_range.len()) {
+ d.equal(0, 0, old_range.len())?;
+ return Ok(());
+ }
+
let maybe_table = make_table(
old,
common_prefix_len..(old_range.len() - common_suffix_len),
@@ -218,3 +224,13 @@ fn test_pat() {
diff(&mut d, a, 0..a.len(), b, 0..b.len()).unwrap();
insta::assert_debug_snapshot!(d.ops());
}
+
+#[test]
+fn test_same() {
+ let a: &[usize] = &[0, 1, 2, 3, 4, 4, 4, 5];
+ let b: &[usize] = &[0, 1, 2, 3, 4, 4, 4, 5];
+
+ let mut d = crate::algorithms::Capture::new();
+ diff(&mut d, a, 0..a.len(), b, 0..b.len()).unwrap();
+ insta::assert_debug_snapshot!(d.ops());
+}
diff --git a/vendor/similar/src/algorithms/myers.rs b/vendor/similar/src/algorithms/myers.rs
index 542c7ed75..8a0c21dbe 100644
--- a/vendor/similar/src/algorithms/myers.rs
+++ b/vendor/similar/src/algorithms/myers.rs
@@ -12,7 +12,7 @@
//! # Heuristics
//!
//! At present this implementation of Myers' does not implement any more advanced
-//! heuristics that would solve some pathological cases. For instane passing two
+//! heuristics that would solve some pathological cases. For instance passing two
//! large and completely distinct sequences to the algorithm will make it spin
//! without making reasonable progress. Currently the only protection in the
//! library against this is to pass a deadline to the diffing algorithm.
diff --git a/vendor/similar/src/algorithms/snapshots/similar__algorithms__lcs__same.snap b/vendor/similar/src/algorithms/snapshots/similar__algorithms__lcs__same.snap
new file mode 100644
index 000000000..4b9511b41
--- /dev/null
+++ b/vendor/similar/src/algorithms/snapshots/similar__algorithms__lcs__same.snap
@@ -0,0 +1,12 @@
+---
+source: src/algorithms/lcs.rs
+assertion_line: 235
+expression: d.ops()
+---
+[
+ Equal {
+ old_index: 0,
+ new_index: 0,
+ len: 8,
+ },
+]
diff --git a/vendor/similar/src/algorithms/utils.rs b/vendor/similar/src/algorithms/utils.rs
index 0d14ac799..812f97ddd 100644
--- a/vendor/similar/src/algorithms/utils.rs
+++ b/vendor/similar/src/algorithms/utils.rs
@@ -11,7 +11,7 @@ pub fn is_empty_range<T: PartialOrd<T>>(range: &Range<T>) -> bool {
!(range.start < range.end)
}
-/// Represents an item in the vector returend by [`unique`].
+/// Represents an item in the vector returned by [`unique`].
///
/// It compares like the underlying item does it was created from but
/// carries the index it was originally created from.
diff --git a/vendor/similar/src/text/mod.rs b/vendor/similar/src/text/mod.rs
index b1a45f3c3..23408e63c 100644
--- a/vendor/similar/src/text/mod.rs
+++ b/vendor/similar/src/text/mod.rs
@@ -37,23 +37,13 @@ impl Deadline {
/// A builder type config for more complex uses of [`TextDiff`].
///
/// Requires the `text` feature.
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, Default)]
pub struct TextDiffConfig {
algorithm: Algorithm,
newline_terminated: Option<bool>,
deadline: Option<Deadline>,
}
-impl Default for TextDiffConfig {
- fn default() -> TextDiffConfig {
- TextDiffConfig {
- algorithm: Algorithm::default(),
- newline_terminated: None,
- deadline: None,
- }
- }
-}
-
impl TextDiffConfig {
/// Changes the algorithm.
///
@@ -66,7 +56,7 @@ impl TextDiffConfig {
/// Sets a deadline for the diff operation.
///
/// By default a diff will take as long as it takes. For certain diff
- /// algorthms like Myer's and Patience a maximum running time can be
+ /// algorithms like Myer's and Patience a maximum running time can be
/// defined after which the algorithm gives up and approximates.
pub fn deadline(&mut self, deadline: Instant) -> &mut Self {
self.deadline = Some(Deadline::Absolute(deadline));
@@ -768,3 +758,14 @@ fn test_serde_ops() {
let json = serde_json::to_string_pretty(&changes).unwrap();
insta::assert_snapshot!(&json);
}
+
+#[test]
+fn test_regression_issue_37() {
+ let config = TextDiffConfig::default();
+ let diff = config.diff_lines("\u{18}\n\n", "\n\n\r");
+ let mut output = diff.unified_diff();
+ assert_eq!(
+ output.context_radius(0).to_string(),
+ "@@ -1 +1,0 @@\n-\u{18}\n@@ -2,0 +2,2 @@\n+\n+\r"
+ );
+}
diff --git a/vendor/similar/src/udiff.rs b/vendor/similar/src/udiff.rs
index 80a30cf82..1b887e353 100644
--- a/vendor/similar/src/udiff.rs
+++ b/vendor/similar/src/udiff.rs
@@ -57,7 +57,7 @@ impl UnifiedDiffHunkRange {
impl fmt::Display for UnifiedDiffHunkRange {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut beginning = self.start() + 1;
- let len = self.end() - self.start();
+ let len = self.end().saturating_sub(self.start());
if len == 1 {
write!(f, "{}", beginning)
} else {
diff --git a/vendor/similar/src/utils.rs b/vendor/similar/src/utils.rs
index 1f8fdc989..44776fe24 100644
--- a/vendor/similar/src/utils.rs
+++ b/vendor/similar/src/utils.rs
@@ -37,7 +37,7 @@ struct SliceRemapper<'x, T: ?Sized> {
indexes: Vec<Range<usize>>,
}
-impl<'x, 'slices, T: DiffableStr + ?Sized> SliceRemapper<'x, T> {
+impl<'x, T: DiffableStr + ?Sized> SliceRemapper<'x, T> {
fn new(source: &'x T, slices: &[&'x T]) -> SliceRemapper<'x, T> {
let indexes = slices
.iter()
@@ -99,7 +99,7 @@ pub struct TextDiffRemapper<'x, T: ?Sized> {
new: SliceRemapper<'x, T>,
}
-impl<'x, 'slices, T: DiffableStr + ?Sized> TextDiffRemapper<'x, T> {
+impl<'x, T: DiffableStr + ?Sized> TextDiffRemapper<'x, T> {
/// Creates a new remapper from strings and slices.
pub fn new(
old_slices: &[&'x T],