mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Expand tests for truncate
This commit is contained in:
parent
d7e8a03237
commit
e9e3d41008
1 changed files with 60 additions and 0 deletions
|
@ -79,3 +79,63 @@ fn test_failed_incorrect_arg() {
|
||||||
let (_at, mut ucmd) = at_and_ucmd!();
|
let (_at, mut ucmd) = at_and_ucmd!();
|
||||||
ucmd.args(&["-s", "+5A", TFILE1]).fails();
|
ucmd.args(&["-s", "+5A", TFILE1]).fails();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_at_most_shrinks() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let mut file = at.make_file(TFILE2);
|
||||||
|
file.write_all(b"1234567890").unwrap();
|
||||||
|
ucmd.args(&["--size", "<4", TFILE2]).succeeds();
|
||||||
|
file.seek(SeekFrom::End(0)).unwrap();
|
||||||
|
assert!(file.seek(SeekFrom::Current(0)).unwrap() == 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_at_most_no_change() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let mut file = at.make_file(TFILE2);
|
||||||
|
file.write_all(b"1234567890").unwrap();
|
||||||
|
ucmd.args(&["--size", "<40", TFILE2]).succeeds();
|
||||||
|
file.seek(SeekFrom::End(0)).unwrap();
|
||||||
|
assert!(file.seek(SeekFrom::Current(0)).unwrap() == 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_at_least_grows() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let mut file = at.make_file(TFILE2);
|
||||||
|
file.write_all(b"1234567890").unwrap();
|
||||||
|
ucmd.args(&["--size", ">15", TFILE2]).succeeds();
|
||||||
|
file.seek(SeekFrom::End(0)).unwrap();
|
||||||
|
assert!(file.seek(SeekFrom::Current(0)).unwrap() == 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_at_least_no_change() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let mut file = at.make_file(TFILE2);
|
||||||
|
file.write_all(b"1234567890").unwrap();
|
||||||
|
ucmd.args(&["--size", ">4", TFILE2]).succeeds();
|
||||||
|
file.seek(SeekFrom::End(0)).unwrap();
|
||||||
|
assert!(file.seek(SeekFrom::Current(0)).unwrap() == 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_round_down() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let mut file = at.make_file(TFILE2);
|
||||||
|
file.write_all(b"1234567890").unwrap();
|
||||||
|
ucmd.args(&["--size", "/4", TFILE2]).succeeds();
|
||||||
|
file.seek(SeekFrom::End(0)).unwrap();
|
||||||
|
assert!(file.seek(SeekFrom::Current(0)).unwrap() == 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_round_up() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let mut file = at.make_file(TFILE2);
|
||||||
|
file.write_all(b"1234567890").unwrap();
|
||||||
|
ucmd.args(&["--size", "*4", TFILE2]).succeeds();
|
||||||
|
file.seek(SeekFrom::End(0)).unwrap();
|
||||||
|
assert!(file.seek(SeekFrom::Current(0)).unwrap() == 12);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue