mirror of
https://github.com/uutils/diffutils.git
synced 2026-06-10 15:48:59 -07:00
rustfmt the code
This commit is contained in:
@@ -44,10 +44,7 @@ fn main() -> Result<(), String> {
|
||||
&to.to_string_lossy(),
|
||||
context_count,
|
||||
),
|
||||
Format::Ed => ed_diff::diff(
|
||||
&from_content,
|
||||
&to_content,
|
||||
)?,
|
||||
Format::Ed => ed_diff::diff(&from_content, &to_content)?,
|
||||
};
|
||||
io::stdout().write_all(&result).unwrap();
|
||||
Ok(())
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::collections::VecDeque;
|
||||
use std::io::Write;
|
||||
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum DiffLine {
|
||||
Context(Vec<u8>),
|
||||
@@ -232,13 +231,15 @@ fn make_diff(expected: &[u8], actual: &[u8], context_size: usize) -> Vec<Mismatc
|
||||
for mismatch in &mut results {
|
||||
if !mismatch
|
||||
.expected
|
||||
.iter().any(|x| !matches!(&x, DiffLine::Context(_)))
|
||||
.iter()
|
||||
.any(|x| !matches!(&x, DiffLine::Context(_)))
|
||||
{
|
||||
mismatch.expected_all_context = true;
|
||||
}
|
||||
if !mismatch
|
||||
.actual
|
||||
.iter().any(|x| !matches!(&x, DiffLine::Context(_)))
|
||||
.iter()
|
||||
.any(|x| !matches!(&x, DiffLine::Context(_)))
|
||||
{
|
||||
mismatch.actual_all_context = true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#![no_main]
|
||||
#[macro_use] extern crate libfuzzer_sys;
|
||||
#[macro_use]
|
||||
extern crate libfuzzer_sys;
|
||||
extern crate ed_diff;
|
||||
|
||||
use std::fs::{self, File};
|
||||
@@ -11,16 +12,24 @@ fuzz_target!(|x: (Vec<u8>, Vec<u8>)| {
|
||||
from.push(b'\n');
|
||||
to.push(b'\n');
|
||||
if let Ok(s) = String::from_utf8(from.clone()) {
|
||||
if !s.is_ascii() { return }
|
||||
if s.find(|x| x < ' ' && x != '\n').is_some() { return }
|
||||
if !s.is_ascii() {
|
||||
return;
|
||||
}
|
||||
if s.find(|x| x < ' ' && x != '\n').is_some() {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return
|
||||
return;
|
||||
}
|
||||
if let Ok(s) = String::from_utf8(to.clone()) {
|
||||
if !s.is_ascii() { return }
|
||||
if s.find(|x| x < ' ' && x != '\n').is_some() { return }
|
||||
if !s.is_ascii() {
|
||||
return;
|
||||
}
|
||||
if s.find(|x| x < ' ' && x != '\n').is_some() {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return
|
||||
return;
|
||||
}
|
||||
let diff = ed_diff::diff_w(&from, &to, "target/fuzz.file").unwrap();
|
||||
File::create("target/fuzz.file.original")
|
||||
@@ -45,11 +54,18 @@ fuzz_target!(|x: (Vec<u8>, Vec<u8>)| {
|
||||
.output()
|
||||
.unwrap();
|
||||
if !output.status.success() {
|
||||
panic!("STDOUT:\n{}\nSTDERR:\n{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
|
||||
panic!(
|
||||
"STDOUT:\n{}\nSTDERR:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
let result = fs::read("target/fuzz.file").unwrap();
|
||||
if result != to {
|
||||
panic!("STDOUT:\n{}\nSTDERR:\n{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
|
||||
panic!(
|
||||
"STDOUT:\n{}\nSTDERR:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -109,12 +109,7 @@ pub fn diff(expected: &[u8], actual: &[u8]) -> Result<Vec<u8>, DiffError> {
|
||||
let actual_count: isize = result.actual.len() as isize;
|
||||
match (expected_count, actual_count) {
|
||||
(0, 0) => unreachable!(),
|
||||
(0, _) => writeln!(
|
||||
&mut output,
|
||||
"{}a",
|
||||
line_number_expected - 1
|
||||
)
|
||||
.unwrap(),
|
||||
(0, _) => writeln!(&mut output, "{}a", line_number_expected - 1).unwrap(),
|
||||
(_, 0) => writeln!(
|
||||
&mut output,
|
||||
"{},{}d",
|
||||
@@ -230,7 +225,6 @@ fn test_permutations() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_permutations_empty_lines() {
|
||||
// test all possible six-line files with missing newlines.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#![no_main]
|
||||
#[macro_use] extern crate libfuzzer_sys;
|
||||
#[macro_use]
|
||||
extern crate libfuzzer_sys;
|
||||
extern crate normal_diff;
|
||||
|
||||
use std::fs::{self, File};
|
||||
@@ -47,11 +48,18 @@ fuzz_target!(|x: (Vec<u8>, Vec<u8>)| {
|
||||
.output()
|
||||
.unwrap();
|
||||
if !output.status.success() {
|
||||
panic!("STDOUT:\n{}\nSTDERR:\n{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
|
||||
panic!(
|
||||
"STDOUT:\n{}\nSTDERR:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
let result = fs::read("target/fuzz.file").unwrap();
|
||||
if result != to {
|
||||
panic!("STDOUT:\n{}\nSTDERR:\n{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
|
||||
panic!(
|
||||
"STDOUT:\n{}\nSTDERR:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -63,7 +63,10 @@ fn make_diff(expected: &[u8], actual: &[u8]) -> Vec<Mismatch> {
|
||||
line_number_actual += 1;
|
||||
}
|
||||
diff::Result::Both(str, _) => {
|
||||
match (line_number_expected > expected_lines_count, line_number_actual > actual_lines_count) {
|
||||
match (
|
||||
line_number_expected > expected_lines_count,
|
||||
line_number_actual > actual_lines_count,
|
||||
) {
|
||||
(true, false) => {
|
||||
line_number_expected += 1;
|
||||
line_number_actual += 1;
|
||||
@@ -88,7 +91,7 @@ fn make_diff(expected: &[u8], actual: &[u8]) -> Vec<Mismatch> {
|
||||
mismatch.line_number_expected = line_number_expected;
|
||||
mismatch.line_number_actual = line_number_actual;
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#![no_main]
|
||||
#[macro_use] extern crate libfuzzer_sys;
|
||||
#[macro_use]
|
||||
extern crate libfuzzer_sys;
|
||||
extern crate unified_diff;
|
||||
|
||||
use std::fs::{self, File};
|
||||
@@ -20,7 +21,13 @@ fuzz_target!(|x: (Vec<u8>, Vec<u8>, u8)| {
|
||||
} else {
|
||||
return
|
||||
}*/
|
||||
let diff = unified_diff::diff(&from, "a/fuzz.file", &to, "target/fuzz.file", context as usize);
|
||||
let diff = unified_diff::diff(
|
||||
&from,
|
||||
"a/fuzz.file",
|
||||
&to,
|
||||
"target/fuzz.file",
|
||||
context as usize,
|
||||
);
|
||||
File::create("target/fuzz.file.original")
|
||||
.unwrap()
|
||||
.write_all(&from)
|
||||
@@ -45,11 +52,18 @@ fuzz_target!(|x: (Vec<u8>, Vec<u8>, u8)| {
|
||||
.output()
|
||||
.unwrap();
|
||||
if !output.status.success() {
|
||||
panic!("STDOUT:\n{}\nSTDERR:\n{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
|
||||
panic!(
|
||||
"STDOUT:\n{}\nSTDERR:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
let result = fs::read("target/fuzz.file").unwrap();
|
||||
if result != to {
|
||||
panic!("STDOUT:\n{}\nSTDERR:\n{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
|
||||
panic!(
|
||||
"STDOUT:\n{}\nSTDERR:\n{}",
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user