|
1 | | -use libc::c_char; |
| 1 | +use libc::{c_char, size_t}; |
2 | 2 | use libc::{c_uint, c_ushort}; |
3 | 3 | use std::ffi::CString; |
4 | 4 | use std::marker; |
@@ -465,7 +465,7 @@ impl<'a> MergeFileInput<'a> { |
465 | 465 | self.content = Some(content); |
466 | 466 |
|
467 | 467 | 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; |
469 | 469 |
|
470 | 470 | self |
471 | 471 | } |
@@ -513,3 +513,53 @@ pub fn merge_file( |
513 | 513 | Ok(Binding::from_raw(ret)) |
514 | 514 | } |
515 | 515 | } |
| 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