Skip to content

Commit 2cc0070

Browse files
committed
fix: merge_file test
1 parent 82d8f87 commit 2cc0070

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

src/merge.rs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use libc::c_char;
1+
use libc::{c_char, size_t};
22
use libc::{c_uint, c_ushort};
33
use std::ffi::CString;
44
use std::marker;
@@ -465,7 +465,7 @@ impl<'a> MergeFileInput<'a> {
465465
self.content = Some(content);
466466

467467
self.raw.ptr = content.as_ptr() as *const c_char;
468-
self.raw.size = content.len() as usize;
468+
self.raw.size = content.len() as size_t;
469469

470470
self
471471
}
@@ -513,3 +513,53 @@ pub fn merge_file(
513513
Ok(Binding::from_raw(ret))
514514
}
515515
}
516+
517+
#[cfg(test)]
518+
mod tests {
519+
use crate::{MergeFileInput, MergeFileOptions};
520+
521+
use std::path::Path;
522+
523+
#[test]
524+
fn smoke_merge_file() {
525+
let file_path = Path::new("file");
526+
let base = {
527+
let mut input = MergeFileInput::new();
528+
input.content(b"base").path(file_path);
529+
input
530+
};
531+
532+
let ours = {
533+
let mut input = MergeFileInput::new();
534+
input.content(b"foo").path(file_path);
535+
input
536+
};
537+
538+
let theirs = {
539+
let mut input = MergeFileInput::new();
540+
input.content(b"bar").path(file_path);
541+
input
542+
};
543+
544+
let mut opts = MergeFileOptions::new();
545+
opts.ancestor_label("ancestor");
546+
opts.our_label("ours");
547+
opts.their_label("theirs");
548+
opts.style_diff3(true);
549+
let merge_file_result = crate::merge_file(&base, &ours, &theirs, Some(&mut opts)).unwrap();
550+
551+
assert!(!merge_file_result.is_automergeable());
552+
assert_eq!(merge_file_result.path(), Some("file"));
553+
assert_eq!(
554+
String::from_utf8_lossy(merge_file_result.content()).to_string(),
555+
r"<<<<<<< ours
556+
foo
557+
||||||| ancestor
558+
base
559+
=======
560+
bar
561+
>>>>>>> theirs
562+
",
563+
);
564+
}
565+
}

0 commit comments

Comments
 (0)