mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
fix usage restriction by adding lifetime specifier
This commit is contained in:
parent
2003e77ae3
commit
ec261f3e20
2 changed files with 35 additions and 58 deletions
|
@ -166,7 +166,7 @@ impl<'a> PsycParser<'a> {
|
|||
/// Parse the buffer previously set by set_buffer. Call repeatedly until the
|
||||
/// result is PsycParserResult::Complete or a PsycParserError.
|
||||
pub fn parse(&mut self)
|
||||
-> Result<PsycParserResult, PsycParserError> {
|
||||
-> Result<PsycParserResult<'a>, PsycParserError> {
|
||||
let state_ptr = &mut self.state as *mut PsycParseState;
|
||||
let mut name: PsycString;
|
||||
let mut value: PsycString;
|
||||
|
|
|
@ -5,76 +5,53 @@ use psyc::parser::*;
|
|||
fn test_parse() {
|
||||
let test_data = ":_target\tpsyc://ve.symlynx.com/@blog\n\n?\n|\n".to_string().into_bytes();
|
||||
|
||||
let expected1 =
|
||||
PsycParserResult::RoutingModifier{
|
||||
operator: ':',
|
||||
name: &test_data[1 .. 8],
|
||||
value: &test_data[9 .. 36],
|
||||
};
|
||||
|
||||
let expected2 = PsycParserResult::StateSync;
|
||||
let expected = vec![PsycParserResult::RoutingModifier{
|
||||
operator: ':',
|
||||
name: &test_data[1 .. 8],
|
||||
value: &test_data[9 .. 36],
|
||||
},
|
||||
PsycParserResult::StateSync];
|
||||
|
||||
let mut parser = PsycParser::new();
|
||||
|
||||
parser.set_buffer(&test_data);
|
||||
|
||||
{
|
||||
let result1 = parser.parse();
|
||||
assert_eq!(result1, Ok(expected1));
|
||||
}
|
||||
assert_eq!(parser.parse().unwrap(), expected[0]);
|
||||
|
||||
{
|
||||
let result2 = parser.parse();
|
||||
assert_eq!(result2, Ok(expected2));
|
||||
}
|
||||
assert_eq!(parser.parse().unwrap(), expected[1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insufficient() {
|
||||
let test_data = ":_target\tpsyc://ve.symlynx.com/@blog\n\n:_nick\tlurchi\n|\n".to_string().into_bytes();
|
||||
|
||||
let expected1 = PsycParserResult::InsufficientData;
|
||||
let expected2 =PsycParserResult::RoutingModifier {
|
||||
operator: ':',
|
||||
name: &test_data[1 .. 8],
|
||||
value: &test_data[9 .. 36]
|
||||
};
|
||||
let expected3 = PsycParserResult::InsufficientData;
|
||||
let expected4 = PsycParserResult::EntityModifier{
|
||||
operator: ':',
|
||||
name: &test_data[39 .. 44],
|
||||
value: &test_data[45 .. 51],
|
||||
};
|
||||
let expected5 = PsycParserResult::Complete;
|
||||
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];
|
||||
|
||||
let mut parser = PsycParser::new();
|
||||
|
||||
parser.set_buffer(&test_data[.. 1]);
|
||||
assert_eq!(parser.parse().unwrap(), expected[0]);
|
||||
|
||||
{
|
||||
parser.set_buffer(&test_data[.. 1]);
|
||||
let result1 = parser.parse();
|
||||
assert_eq!(result1, Ok(expected1));
|
||||
}
|
||||
|
||||
{
|
||||
parser.set_buffer(&test_data[.. 46]);
|
||||
let result2 = parser.parse();
|
||||
assert_eq!(result2, Ok(expected2));
|
||||
}
|
||||
|
||||
{
|
||||
parser.set_buffer(&test_data[.. 49]);
|
||||
let result3 = parser.parse();
|
||||
assert_eq!(result3, Ok(expected3));
|
||||
}
|
||||
|
||||
{
|
||||
parser.set_buffer(&test_data);
|
||||
let result4 = parser.parse();
|
||||
assert_eq!(result4, Ok(expected4));
|
||||
}
|
||||
|
||||
{
|
||||
let result5 = parser.parse();
|
||||
assert_eq!(result5, Ok(expected5));
|
||||
}
|
||||
parser.set_buffer(&test_data[.. 46]);
|
||||
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);
|
||||
assert_eq!(parser.parse().unwrap(), expected[3]);
|
||||
|
||||
assert_eq!(parser.parse().unwrap(), expected[4]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue