2016-08-22 22:04:57 +00:00
|
|
|
extern crate psyc;
|
|
|
|
use psyc::parser::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_parse() {
|
|
|
|
let test_data = ":_target\tpsyc://ve.symlynx.com/@blog\n\n?\n|\n".to_string().into_bytes();
|
|
|
|
|
2016-08-29 08:02:33 +00:00
|
|
|
let expected = vec![PsycParserResult::RoutingModifier{
|
|
|
|
operator: ':',
|
2016-08-31 17:14:41 +00:00
|
|
|
name: "_target".as_bytes(),
|
|
|
|
value: "psyc://ve.symlynx.com/@blog".as_bytes(),
|
2016-08-29 08:02:33 +00:00
|
|
|
},
|
|
|
|
PsycParserResult::StateSync];
|
2016-08-22 22:04:57 +00:00
|
|
|
|
|
|
|
let mut parser = PsycParser::new();
|
2016-08-28 23:00:31 +00:00
|
|
|
|
2016-08-22 22:04:57 +00:00
|
|
|
parser.set_buffer(&test_data);
|
|
|
|
|
2016-08-29 08:02:33 +00:00
|
|
|
assert_eq!(parser.parse().unwrap(), expected[0]);
|
2016-08-28 23:00:31 +00:00
|
|
|
|
2016-08-29 08:02:33 +00:00
|
|
|
assert_eq!(parser.parse().unwrap(), expected[1]);
|
2016-08-28 23:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_insufficient() {
|
2016-08-31 17:14:41 +00:00
|
|
|
let mut test_data1 = ":_target\tpsyc://ve.symlynx.com/@blog\n\n:_nick".to_string().into_bytes();
|
|
|
|
let mut test_data2 = "\tlurchi\n|\n".to_string().into_bytes();
|
2016-08-28 23:00:31 +00:00
|
|
|
|
2016-08-29 08:02:33 +00:00
|
|
|
let expected = vec![PsycParserResult::InsufficientData,
|
2016-08-31 17:14:41 +00:00
|
|
|
PsycParserResult::RoutingModifier {
|
|
|
|
operator: ':',
|
|
|
|
name: "_target".as_bytes(),
|
|
|
|
value: "psyc://ve.symlynx.com/@blog".as_bytes()
|
|
|
|
},
|
|
|
|
PsycParserResult::InsufficientData,
|
|
|
|
PsycParserResult::EntityModifier{
|
|
|
|
operator: ':',
|
|
|
|
name: "_nick".as_bytes(),
|
|
|
|
value: "lurchi".as_bytes(),
|
|
|
|
},
|
|
|
|
PsycParserResult::Complete];
|
|
|
|
|
2016-08-28 23:00:31 +00:00
|
|
|
let mut parser = PsycParser::new();
|
|
|
|
|
2016-08-31 17:14:41 +00:00
|
|
|
parser.set_buffer(&test_data1[.. 1]);
|
2016-08-29 08:02:33 +00:00
|
|
|
assert_eq!(parser.parse().unwrap(), expected[0]);
|
2016-08-31 17:14:41 +00:00
|
|
|
|
|
|
|
let unparsed_length = parser.copy_unparsed_into_buffer(&mut test_data1);
|
|
|
|
assert_eq!(unparsed_length, 1);
|
|
|
|
parser.set_buffer(&test_data1[.. 44]);
|
2016-08-29 08:02:33 +00:00
|
|
|
assert_eq!(parser.parse().unwrap(), expected[1]);
|
2016-08-31 17:14:41 +00:00
|
|
|
|
2016-08-29 08:02:33 +00:00
|
|
|
assert_eq!(parser.parse().unwrap(), expected[2]);
|
|
|
|
|
2016-08-31 17:14:41 +00:00
|
|
|
let unparsed_length = parser.copy_unparsed_into_buffer(&mut test_data1);
|
|
|
|
test_data1.resize(unparsed_length, 0);
|
|
|
|
test_data1.append(&mut test_data2);
|
|
|
|
parser.set_buffer(&test_data1);
|
2016-08-29 08:02:33 +00:00
|
|
|
assert_eq!(parser.parse().unwrap(), expected[3]);
|
|
|
|
|
|
|
|
assert_eq!(parser.parse().unwrap(), expected[4]);
|
2016-08-22 22:04:57 +00:00
|
|
|
}
|