mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
change PsycParser API to make it possible to parse large packets and process them partially; prepare PsycDictParser
This commit is contained in:
parent
ec261f3e20
commit
d12047ee18
5 changed files with 300 additions and 97 deletions
|
@ -7,8 +7,8 @@ fn test_parse() {
|
|||
|
||||
let expected = vec![PsycParserResult::RoutingModifier{
|
||||
operator: ':',
|
||||
name: &test_data[1 .. 8],
|
||||
value: &test_data[9 .. 36],
|
||||
name: "_target".as_bytes(),
|
||||
value: "psyc://ve.symlynx.com/@blog".as_bytes(),
|
||||
},
|
||||
PsycParserResult::StateSync];
|
||||
|
||||
|
@ -23,34 +23,39 @@ fn test_parse() {
|
|||
|
||||
#[test]
|
||||
fn test_insufficient() {
|
||||
let test_data = ":_target\tpsyc://ve.symlynx.com/@blog\n\n:_nick\tlurchi\n|\n".to_string().into_bytes();
|
||||
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();
|
||||
|
||||
let expected = vec![PsycParserResult::InsufficientData,
|
||||
PsycParserResult::RoutingModifier {
|
||||
operator: ':',
|
||||
name: &test_data[1 .. 8],
|
||||
value: &test_data[9 .. 36]
|
||||
},
|
||||
PsycParserResult::InsufficientData,
|
||||
PsycParserResult::EntityModifier{
|
||||
operator: ':',
|
||||
name: &test_data[39 .. 44],
|
||||
value: &test_data[45 .. 51],
|
||||
},
|
||||
PsycParserResult::Complete];
|
||||
|
||||
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];
|
||||
|
||||
let mut parser = PsycParser::new();
|
||||
|
||||
parser.set_buffer(&test_data[.. 1]);
|
||||
parser.set_buffer(&test_data1[.. 1]);
|
||||
assert_eq!(parser.parse().unwrap(), expected[0]);
|
||||
|
||||
parser.set_buffer(&test_data[.. 46]);
|
||||
|
||||
let unparsed_length = parser.copy_unparsed_into_buffer(&mut test_data1);
|
||||
assert_eq!(unparsed_length, 1);
|
||||
parser.set_buffer(&test_data1[.. 44]);
|
||||
assert_eq!(parser.parse().unwrap(), expected[1]);
|
||||
|
||||
parser.set_buffer(&test_data[.. 49]);
|
||||
|
||||
assert_eq!(parser.parse().unwrap(), expected[2]);
|
||||
|
||||
parser.set_buffer(&test_data);
|
||||
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);
|
||||
assert_eq!(parser.parse().unwrap(), expected[3]);
|
||||
|
||||
assert_eq!(parser.parse().unwrap(), expected[4]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue