use lz_string::{Decoder, Error}; macro_rules! test { ($data:expr, $expected:expr $(,)?) => { let mut decoder = Decoder::new(); let result = decoder.decode_base64($data); assert_eq!(result, Ok($expected.to_owned())); } } #[test] fn simple() { test!("IZA", "a"); } #[test] fn repeat1() { test!("IbI", "aa"); } #[test] fn repeat2() { test!("Aco", "ààà"); } #[test] fn repeat3() { test!("Ac1A", "àààààà"); } #[test] fn incomplete() { test!("C4e1Q", "toto"); } #[test] fn padded() { test!("C4e1Q===", "toto"); } #[test] fn utf16() { test!("KORCJCIEBFhgRAU4WASCwiQ1ESCBvwjIBA", "Å∑⁄¢∆Ê‚√∫flı"); } #[test] fn common() { test!( "MYUwBALgTghglgOzCAzhMADsATVFEz4D2CQA", "ce train est à destination", ); } #[test] fn medium() { test!( "MIUwBALgTghglgOzCAzhMADsATVFEz4D2SuYACgIIBKAkgMpj2W0ByAKmADKUBaNAUQBcYAGpEArimRIAVxFSYwAFgCsAUgDcYAPIS4YAMYByPJCgAL6QBsSAcwB0QA", "Ce train est à destination de PARIS SAINT LAZARE: Vous en êtes à 45%; Oui c'est très long.", ); } #[test] fn long() { test!( "N4IglgJiA0IIwCYDMAWArKgbAtOUxAEMAXGBWYgW0IA8ZEAGWMSgBxgG1RIC4CAjQgDshAUwBOMUAHd6aABxJYAC3oMAnGlisA9gGcYAdliDixSdA5wkAXQC+d6AAJuUWAgHCxFmUfkoVNSYQXQNoAJBTc05rezsbE0IIADdOEABjHTZhAE84ADpMygIi1lyEQqyQBJA9MGJRKXA3EGR0TCQCIUJKRtgAZXrRJwBBACEAYQARAggswjAhAmkV/MIAV3TlYQhxMGTRfIAzCxDCAHNRdJI0pEMGBkw4BmrYPSviMB0ha9JLEDuD2w+BqrD2yUI6RyugANmAofRtBc+iBlGZWNAAPSYuoNQj8dIQSqUTFlS75NHFWDiURHAho4gY7E0o4SPZCc64w5FTEstmLc5kw6Ugisdb8OF6ZQSJo8bTixCoNBdHoogAK4sl0vEoxAjgy3waQj+oAA1qIctIdOIIGEOCBzZbrRAnIQCI6rTanPx3RbPS70tUHLAIKJkvC+tx2LBMCh8og4zgkPGCOs3bAALI6ABeYBhMMImLQ+QYTgAFBnIYtiPplABuJwAVQbAEljaIYU5K+knAB5fpOAAaTme+UwDdEQgAtI3+g3xMloAV1PkKnBMABKJwAcSupp0mIQDDgzyQcHUTgAYmAWToaJjk5h45gCPoCP2hwQjgWpQdTqO+FgAArMI4H1dZ3h8ZoCHQQg9AgI51HkQxMDQTBDHkdQkiOJIUHQ+QaWkVD8PUAR1hyCR1jlEA0AQ/C4IgTDkOIhijgwpCULQfAQxIdMuBAbpegIEZNm2IQpnBPonFqURzl6Y1OFAQSUUEPRzT+aSIRhdYUQ4Gw9XsOIgA===", "{\"id\",\"1234534625254\",\"at\",2,\"tmax\",120,\"imp\",[{\"id\",\"1\",\"banner\",{\"w\",1583,\"h\",1095,\"pos\",7,\"battr\",[13]}}, {\"id\",\"2\",\"banner\",{\"w\",784,\"h\",100,\"pos\",4,\"battr\",[13]}}],\"badv\",[\"company1.com\",\"company2.com\"],\"site\",{\"id\",\"234563\",\"name\",\"Site ABCD\",\"domain\",\"www.auchandrive.fr\",\"pagecat\",[\"3700610\"],\"sectioncat\",[\"3700624\"],\"privacypolicy\",1,\"page\",\"http,//siteabcd.com/page.htm\",\"ref\",\"http,//referringsite.com/referringpage.htm\",\"publisher\",{\"id\",\"pub12345\",\"name\",\"Publisher A\"},\"content\",{\"keywords\",[\"keyword a\",\"keyword b\",\"keyword c\"]}},\"device\",{\"ip\",\"64.124.253.1\",\"ua\",\"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv,1.9.2.16) Gecko/20110319 Firefox/3.6.16\",\"os\",\"OS X\",\"flashver\",\"10.1\",\"js\",1},\"user\",{\"id\",\"45asdf987656789adfad4678rew656789\",\"buyeruid\",\"5df678asd8987656asdf78987654\",\"data\",[{\"name\",\"AuchanDrive\", \"segment\",[{\"name\",\"basket\", \"value\",\"[]\"}]}]}}", ); } #[test] fn invalid() { let data = "*"; let expected = Err(Error::InvalidByte(0x2A)); let mut decoder = Decoder::new(); assert_eq!(decoder.decode_base64(data), expected); }