src/main.rs
Lines
93.75 %
Functions
90.91 %
Regions
91.30 %
| Line | Count | Source (jump to first uncovered line) |
|---|---|---|
| 1 | mod second; | |
| 2 | ||
| 3 | 0 | fn main() { println!("Hello, world!"); } |
| 4 | ||
| 5 | 1 | fn validate_data_simple(data: &) -> <()()> { |
| 6 | 1 | if !eq(&[0x13, 0x37]) { return Err(()) } |
| 7 | 0 | ifas usize !=len() { return Err(()) } |
| 8 | 0 | return Ok(()); |
| 9 | 1 | } |
| 10 | ||
| 11 | 2 | fn validate_data_match(data: &) -> i32 { |
| 12 | 2 | let: u32 = match::<u32>() { |
| 13 | 1 | Ok() => { |
| 14 | 1 | let= 2 *; |
| 15 | 1 | if< 6 { |
| 16 | 0 | |
| 17 | } else { | |
| 18 | 1 | * 2 |
| 19 | } | |
| 20 | } | |
| 21 | 1 | Err(_) => 0 |
| 22 | }; | |
| 23 | 2 | if== 0 { |
| 24 | 1 | -1 |
| 25 | } else { | |
| 26 | 1 | (as i32) + 1 |
| 27 | } | |
| 28 | 2 | } |
| 29 | ||
| 30 | // https://doc.rust-lang.org/book/ch10-01-syntax.html | |
| 31 | 3 | fn largest<:>(list: &) -> & { |
| 32 | 3 | let mut= &[0]; |
| 33 | 3 | forin{ |
| 34 | 3 | if>{ |
| 35 | 3 | =; |
| 36 | 9 | } |
| 37 | } | |
| 38 | 3 | |
| 39 | 3 | } |
| 40 | ||
| 41 | 1 | fn validate_data_generics(data: &) { |
| 42 | 1 | let= vec![34, 50, 25, 100, 65]; |
| 43 | ||
| 44 | 1 | let= largest(&); |
| 45 | 1 | println!("The largest number is {}",); |
| 46 | ||
| 47 | 1 | let= vec!['y', 'm', 'a', 'q']; |
| 48 | ||
| 49 | 1 | let= largest(&); |
| 50 | 1 | println!("The largest char is {}",); |
| 51 | ||
| 52 | 1 | let= largest(as_bytes()); |
| 53 | 1 | println!("The largest content char is {}",); |
| 54 | 1 | } |
| 55 | ||
| 56 | struct Data { | |
| 57 | magic:u8 | |
| 58 | len: u8 | |
| 59 | content: | |
| 60 | } | |
| 61 | ||
| 62 | #[cfg()] | |
| 63 | mod tests { | |
| 64 | use crate::::; | |
| 65 | use crate::{,,,}; | |
| 66 | ||
| 67 | #[test] | |
| 68 | 1 | fn parser_detects_errors() { |
| 69 | 1 | let mut={: [0x73, 0x31],: 2,: "AB"parse()unwrap() }; |
| 70 | 1 | =+ "Y"; |
| 71 | 1 | let= validate_data_simple(&); |
| 72 | 1 | assert!(is_err()); |
| 73 | 1 | } |
| 74 | ||
| 75 | #[test] | |
| 76 | 1 | fn check_match() { |
| 77 | 1 | let={: [0x73, 0x31],: 2,: "XX"parse()unwrap() }; |
| 78 | 1 | let= validate_data_match(&); |
| 79 | 1 | assert_eq!(, -1); |
| 80 | 1 | } |
| 81 | ||
| 82 | #[test] | |
| 83 | 1 | fn check_match2() { |
| 84 | 1 | let={: [0x73, 0x31],: 2,: "40"parse()unwrap() }; |
| 85 | 1 | let= validate_data_match(&); |
| 86 | 1 | assert_eq!(, 161); |
| 87 | 1 | } |
| 88 | ||
| 89 | #[test] | |
| 90 | 1 | fn check_generic() { |
| 91 | 1 | let={: [0x73, 0x31],: 2,: "QWE"parse()unwrap() }; |
| 92 | 1 | validate_data_generics(&); |
| 93 | 1 | } |
| 94 | ||
| 95 | #[test] | |
| 96 | #[should_panic] | |
| 97 | 1 | fn check_panic() { |
| 98 | 1 | let={: [0x73, 0x31],: 0,: "4"parse()unwrap() }; |
| 99 | 1 | validate_data_panic(&); |
| 100 | 1 | } |
| 101 | ||
| 102 | #[test] | |
| 103 | 1 | fn check_not_panic() { |
| 104 | 1 | let={: [0x73, 0x31],: 2,: "4"parse()unwrap() }; |
| 105 | 1 | validate_data_panic(&); |
| 106 | 1 | } |
| 107 | } |