this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

test: add tests for input parsing

+70 -1
+52 -1
src/progress.rs
··· 11 11 Off, 12 12 } 13 13 14 - #[derive(Debug, Clone, Copy)] 14 + #[derive(Debug, Clone, Copy, PartialEq)] 15 15 pub struct ChunkSize { 16 16 pub size_in_bytes: usize, 17 17 } ··· 131 131 self.bar.finish(); 132 132 } 133 133 } 134 + 135 + #[cfg(test)] 136 + mod tests { 137 + use super::*; 138 + 139 + #[test] 140 + fn chunk_size_parsing() { 141 + assert!(ChunkSize::from_str("0").is_err()); 142 + assert!(ChunkSize::from_str("0mb").is_err()); 143 + assert_eq!( 144 + ChunkSize::from_str("1").unwrap(), 145 + ChunkSize { size_in_bytes: 1 } 146 + ); 147 + assert_eq!( 148 + ChunkSize::from_str("1kb").unwrap(), 149 + ChunkSize { 150 + size_in_bytes: 1024 151 + } 152 + ); 153 + assert_eq!( 154 + ChunkSize::from_str("16kib").unwrap(), 155 + ChunkSize { 156 + size_in_bytes: 16 * 1024 157 + } 158 + ); 159 + assert_eq!( 160 + ChunkSize::from_str("8mib").unwrap(), 161 + ChunkSize { 162 + size_in_bytes: 8 * 1024 * 1024 163 + } 164 + ); 165 + assert_eq!( 166 + ChunkSize::from_str("16mb").unwrap(), 167 + ChunkSize { 168 + size_in_bytes: 16 * 1024 * 1024 169 + } 170 + ); 171 + assert_eq!( 172 + ChunkSize::from_str("1gb").unwrap(), 173 + ChunkSize { 174 + size_in_bytes: 1024 * 1024 * 1024 175 + } 176 + ); 177 + assert_eq!( 178 + ChunkSize::from_str("16gib").unwrap(), 179 + ChunkSize { 180 + size_in_bytes: 16 * 1024 * 1024 * 1024 181 + } 182 + ); 183 + } 184 + }
+18
src/utils.rs
··· 149 149 Path(PathBuf), 150 150 Pipe(std::io::Stdout), 151 151 } 152 + 153 + #[cfg(test)] 154 + mod tests { 155 + use super::*; 156 + 157 + #[test] 158 + fn compression_level_parsing() { 159 + assert_eq!(CompressionLevel::from_str("0").unwrap().level, 0); 160 + assert_eq!(CompressionLevel::from_str("1").unwrap().level, 1); 161 + assert_eq!(CompressionLevel::from_str("9").unwrap().level, 9); 162 + assert_eq!(CompressionLevel::from_str("none").unwrap().level, 0); 163 + assert_eq!(CompressionLevel::from_str("fast").unwrap().level, 1); 164 + assert_eq!(CompressionLevel::from_str("best").unwrap().level, 9); 165 + assert_eq!(CompressionLevel::from_str("-1").is_err(), true); 166 + assert_eq!(CompressionLevel::from_str("10").is_err(), true); 167 + assert_eq!(CompressionLevel::from_str("foo").is_err(), true); 168 + } 169 + }