| 1 | mod tagfile { |
| 2 | use rust_apt::tagfile::{self, TagSection}; |
| 3 | |
| 4 | #[test] |
| 5 | fn correct() { |
| 6 | let control_file = include_str!("files/tagfile/correct.control"); |
| 7 | let dpkg_status = include_str!("/var/lib/dpkg/status"); |
| 8 | let control_sections: Vec<&str> = control_file.split("\n\n").collect(); |
| 9 | let control_section_one = TagSection::new(control_sections.first().unwrap()).unwrap(); |
| 10 | let control_section_two = TagSection::new(control_sections.get(1).unwrap()).unwrap(); |
| 11 | |
| 12 | assert!(tagfile::parse_tagfile(dpkg_status).is_ok()); |
| 13 | assert!(tagfile::parse_tagfile(control_file).is_ok()); |
| 14 | assert!(TagSection::new(control_file).is_err()); |
| 15 | assert!( |
| 16 | TagSection::new("This-Is-Not-A-Valid-Control-File-Because-Its-Not-Colon-Separated") |
| 17 | .is_err() |
| 18 | ); |
| 19 | |
| 20 | assert_eq!(control_section_one.get("Package").unwrap(), "pkg1"); |
| 21 | assert_eq!(control_section_one.get("Version").unwrap(), "1.0.0"); |
| 22 | assert_eq!(control_section_one.get("Description").unwrap(), "pkgdesc1"); |
| 23 | assert_eq!( |
| 24 | control_section_one.get("Multi-Line").unwrap(), |
| 25 | "Wow\n This is\n Multiple lines!" |
| 26 | ); |
| 27 | assert_eq!(control_section_one.get("Back-To").unwrap(), "Normal"); |
| 28 | assert!( |
| 29 | control_section_one |
| 30 | .get("Not-A-Key-In-The-Control-File") |
| 31 | .is_none() |
| 32 | ); |
| 33 | |
| 34 | assert_eq!(control_section_two.get("Package").unwrap(), "pkg2"); |
| 35 | assert_eq!(control_section_two.get("Version").unwrap(), "2.0.0"); |
| 36 | assert_eq!(control_section_two.get("Description").unwrap(), "pkgdesc2"); |
| 37 | assert_eq!( |
| 38 | control_section_two.get("Value-Starts-On-Newline").unwrap(), |
| 39 | "\n Well that's interesting!\n It's nice that this isn't failing the test, isn't \ |
| 40 | it??" |
| 41 | ); |
| 42 | assert_eq!( |
| 43 | control_section_two.get("Normal-Line").unwrap(), |
| 44 | "Once again" |
| 45 | ); |
| 46 | assert_eq!( |
| 47 | control_section_two.get("Tabbed-Indentation").unwrap(), |
| 48 | "\n\tAll my homies know that tabs be superior.\n\t Why not just use both?" |
| 49 | ); |
| 50 | } |
| 51 | } |