extern crate dotproperties; use std::path::{Path, PathBuf}; use std::collections::HashMap; fn sample(s: &str) -> PathBuf { Path::new(file!()).with_file_name(s) } #[test] fn test_parse_samples_from_slice() { assert!(dotproperties::parse_from_slice(include_bytes!("samples/a.properties")).is_ok()); assert!(dotproperties::parse_from_slice(include_bytes!("samples/b.properties")).is_ok()); assert!(dotproperties::parse_from_slice(include_bytes!("samples/c.properties")).is_ok()); assert!(dotproperties::parse_from_slice(include_bytes!("samples/d.properties")).is_ok()); assert!(dotproperties::parse_from_slice(include_bytes!("samples/e.properties")).is_ok()); assert!(dotproperties::parse_from_slice(include_bytes!("samples/f.properties")).is_ok()); assert!(dotproperties::parse_from_slice(include_bytes!("samples/g.properties")).is_ok()); assert!(dotproperties::parse_from_slice(include_bytes!("samples/h.properties")).is_ok()); assert!(dotproperties::parse_from_slice(include_bytes!("samples/i.properties")).is_ok()); assert!(dotproperties::parse_from_slice(include_bytes!("samples/j.properties")).is_ok()); } #[test] fn test_parse_samples_from_file() { assert!(dotproperties::parse_from_file(sample("samples/a.properties")).is_ok()); assert!(dotproperties::parse_from_file(sample("samples/b.properties")).is_ok()); assert!(dotproperties::parse_from_file(sample("samples/c.properties")).is_ok()); assert!(dotproperties::parse_from_file(sample("samples/d.properties")).is_ok()); assert!(dotproperties::parse_from_file(sample("samples/e.properties")).is_ok()); assert!(dotproperties::parse_from_file(sample("samples/f.properties")).is_ok()); assert!(dotproperties::parse_from_file(sample("samples/g.properties")).is_ok()); assert!(dotproperties::parse_from_file(sample("samples/h.properties")).is_ok()); assert!(dotproperties::parse_from_file(sample("samples/i.properties")).is_ok()); assert!(dotproperties::parse_from_file(sample("samples/j.properties")).is_ok()); } macro_rules! assert_key_value { ($m:expr, $k:expr, $v:expr) => {assert_eq!($m.get($k).map(|v| &**v), Some($v));} } #[test] fn test_parse_a() { let parsed = dotproperties::parse_from_file(sample("samples/a.properties")).unwrap(); assert_eq!(parsed.len(), 180); let map : HashMap<_,_> = parsed.into_iter().collect(); assert_key_value!(map, "config.unbind.ask", "Are you sure to unbind this configuration ?"); assert_key_value!(map, "config.title.exists", "? "); assert_key_value!(map, "404", "\
\The requested page was not found. If you are not forwarded in 3 seconds to the Web Console, please click here
\ "); } #[test] fn test_parse_b() { let parsed = dotproperties::parse_from_file(sample("samples/b.properties")).unwrap(); assert_eq!(parsed.len(), 45); let map : HashMap<_,_> = parsed.into_iter().collect(); assert_key_value!(map, "framework.system.packages.extra.basic", "com.sun.awt, \ com.sun.image.codec.jpeg, \ com.sun.imageio.spi, \ com.sun.xml.internal.bind, \ javax.accessibility, \ javax.imageio, \ javax.imageio.event, \ javax.imageio.metadata, \ javax.imageio.plugins.jpeg, \ javax.imageio.spi, \ javax.imageio.stream, \ javax.media, \ javax.swing, \ javax.swing.border, \ javax.swing.event, \ javax.swing.filechooser, \ javax.swing.plaf, \ javax.swing.plaf.basic, \ javax.swing.plaf.metal, \ javax.swing.table, \ javax.swing.text, \ javax.swing.tree, \ javax.xml.bind, \ javax.xml.parsers, \ javax.xml.namespace, \ javax.xml.stream, \ javax.xml.transform, \ javax.xml.transform.stax, \ javax.xml.validation, \ org.w3c.dom, \ org.xml.sax, \ org.xml.sax.ext, \ org.xml.sax.helpers, \ sun.awt, \ sun.awt.geom, \ sun.awt.image, \ sun.awt.image.codec, \ sun.java2d.opengl, \ sun.security.action, \ sun.misc, \ sun.net.www.protocol.file, \ sun.reflect"); assert_key_value!(map, "obr.repository.url", "http://felix.apache.org/obr/releases.xml ${weasis.codebase.url}/bundle/repository.xml"); assert_key_value!(map, "weasis.copyrights", "\u{00a9} 2009-2017 Weasis Team"); } #[test] fn test_parse_c() { let parsed = dotproperties::parse_from_file(sample("samples/c.properties")).unwrap(); assert_eq!(parsed.len(), 149); let map : HashMap<_,_> = parsed.into_iter().collect(); assert_key_value!(map, "Actor_Label_self", "Self \u{0020}\u{21e8}\u{0020} Self"); } #[test] fn test_parse_g() { let parsed = dotproperties::parse_from_file(sample("samples/g.properties")).unwrap(); assert_eq!(parsed.len(), 0); } #[test] fn test_parse_i() { let parsed = dotproperties::parse_from_file(sample("samples/i.properties")).unwrap(); let map : HashMap<_,_> = parsed.into_iter().collect(); assert_key_value!(map, "AE", "C\u{00e1}c Ti\u{1ec3}u V\u{01b0}\u{01a1}ng qu\u{1ed1}c A-r\u{1ead}p Th\u{1ed1}ng nh\u{1ea5}t"); }