Skip to content
Myr

Add helper method to create sized files, use meaningful names and add kibi and kilo tests.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jonathan · committed by David Peter · parent 409cf0c · Browse files · 1 file+45 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+45 added−16 removed

  • tests:+45 added−16 removed

1 file+45 added−16 removed

modified:tests/tests.rs+45 added-16 removed
13 unmodified lines
1415use regex::escape;16use std::fs;17use std::io::Write;18use std::path::Path;19use testenv::TestEnv;2021static DEFAULT_DIRS: &'static [&'static str] = &["one/two/three", "one/two/three/directory_foo"];22
29 unmodified lines
52 let root_path = get_absolute_root_path(&env);53 (env, root_path)54}5556#[cfg(test)]57fn create_file_with_size<P: AsRef<Path>>(path: P, size_in_bytes: usize) {58 let content = "#".repeat(size_in_bytes);59 let mut f = fs::File::create::<P>(path).unwrap();60 f.write(content.as_bytes()).unwrap();61}6263/// Simple tests64#[test]65fn test_simple() {66 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
949 unmodified lines
1016 let dirs = &["test1", "test2"];1017 let files = &["test1/a.foo", "test1/b.foo", "test1/c.foo"];1018 let te = TestEnv::new(dirs, files);10191012 let mut f = fs::File::create(te.test_root().join("test1/tiny.foo")).unwrap();1013 f.write("Hello world".as_bytes()).unwrap(); // 11 bytes1014 f.flush().unwrap();1020 create_file_with_size(te.test_root().join("test1/11_bytes.foo"), 11);1021 create_file_with_size(te.test_root().join("test2/30_bytes.foo"), 30);1022 create_file_with_size(te.test_root().join("test1/3_kilobytes.foo"), 3 * 1000);1023 create_file_with_size(te.test_root().join("test2/4_kibibytes.foo"), 4 * 1024);10241016 let mut f = fs::File::create(te.test_root().join("test2/big.foo")).unwrap();1017 f.write("Hello user, fd is a nice tool.".as_bytes()).unwrap(); // 30 bytes1018 f.flush().unwrap();10191025 // Zero and non-zero sized files.1026 te.assert_output(1027 &["", "test1", "test2", "--size", "+0B"],1023 "test1/a.foo1028 "test1/11_bytes.foo1029 test1/a.foo1030 test1/b.foo1031 test1/c.foo1026 test1/tiny.foo1027 test2/big.foo"1032 test1/3_kilobytes.foo1033 test2/30_bytes.foo1034 test2/4_kibibytes.foo"1035 );10361037 // Zero sized files.1038 te.assert_output(
5 unmodified lines
10441045 // Files with 2 bytes or more.1046 te.assert_output(1047 &["", "test1", "test2", "--size", "+2B"],1041 "test1/tiny.foo1042 test2/big.foo"1048 "test1/11_bytes.foo1049 test1/3_kilobytes.foo1050 test2/30_bytes.foo1051 test2/4_kibibytes.foo"1052 );10531054 // Files with 2 bytes or less.1055 te.assert_output(
5 unmodified lines
10611062 // Files with size between 1 byte and 11 bytes.1063 te.assert_output(1064 &["", "test1", "test2", "--size", "+1B", "--size", "-11B"],1056 "test1/tiny.foo"1065 "test1/11_bytes.foo"1066 );10671068 // Files with size between 1 byte and 30 bytes.1069 te.assert_output(1070 &["", "test1", "test2", "--size", "+1B", "--size", "-30B"],1062 "test1/tiny.foo1063 test2/big.foo"1071 "test1/11_bytes.foo1072 test2/30_bytes.foo"1073 );10741075 // Files with size between 12 and 30 bytes.1076 te.assert_output(1077 &["", "test1", "test2", "--size", "+12B", "--size", "-30B"],1069 "test2/big.foo"1078 "test2/30_bytes.foo"1079 );10801081 // Files with size between 31 and 100 bytes.1082 te.assert_output(1083 &["", "test1", "test2", "--size", "+31B", "--size", "-100B"],1084 ""1085 );10861087 // Files with size between 3 kibibytes and 5 kibibytes.1088 te.assert_output(1089 &["", "test1", "test2", "--size", "+3ki", "--size", "-5ki"],1090 "test2/4_kibibytes.foo"1091 );10921093 // Files with size between 3 kilobytes and 5 kilobytes.1094 te.assert_output(1095 &["", "test1", "test2", "--size", "+3k", "--size", "-5k"],1096 "test1/3_kilobytes.foo1097 test2/4_kibibytes.foo"1098 );10991100 // Files with size greater than 3 kilobytes and less than 4 kibibytes.1101 te.assert_output(1102 &["", "test1", "test2", "--size", "+3k", "--size", "-3ki"],1103 "test1/3_kilobytes.foo"1104 );11051106}