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
|
/// Parse the buffer previously set by set_buffer. Call repeatedly until the
|
||||||
/// result is PsycParserResult::Complete or a PsycParserError.
|
/// result is PsycParserResult::Complete or a PsycParserError.
|
||||||
pub fn parse(&mut self)
|
pub fn parse(&mut self)
|
||||||
-> Result<PsycParserResult, PsycParserError> {
|
-> Result<PsycParserResult<'a>, PsycParserError> {
|
||||||
let state_ptr = &mut self.state as *mut PsycParseState;
|
let state_ptr = &mut self.state as *mut PsycParseState;
|
||||||
let mut name: PsycString;
|
let mut name: PsycString;
|
||||||
let mut value: PsycString;
|
let mut value: PsycString;
|
||||||
|
|
|
@ -5,76 +5,53 @@ use psyc::parser::*;
|
||||||
fn test_parse() {
|
fn test_parse() {
|
||||||
let test_data = ":_target\tpsyc://ve.symlynx.com/@blog\n\n?\n|\n".to_string().into_bytes();
|
let test_data = ":_target\tpsyc://ve.symlynx.com/@blog\n\n?\n|\n".to_string().into_bytes();
|
||||||
|
|
||||||
let expected1 =
|
let expected = vec![PsycParserResult::RoutingModifier{
|
||||||
PsycParserResult::RoutingModifier{
|
operator: ':',
|
||||||
operator: ':',
|
name: &test_data[1 .. 8],
|
||||||
name: &test_data[1 .. 8],
|
value: &test_data[9 .. 36],
|
||||||
value: &test_data[9 .. 36],
|
},
|
||||||
};
|
PsycParserResult::StateSync];
|
||||||
|
|
||||||
let expected2 = PsycParserResult::StateSync;
|
|
||||||
|
|
||||||
let mut parser = PsycParser::new();
|
let mut parser = PsycParser::new();
|
||||||
|
|
||||||
parser.set_buffer(&test_data);
|
parser.set_buffer(&test_data);
|
||||||
|
|
||||||
{
|
assert_eq!(parser.parse().unwrap(), expected[0]);
|
||||||
let result1 = parser.parse();
|
|
||||||
assert_eq!(result1, Ok(expected1));
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
assert_eq!(parser.parse().unwrap(), expected[1]);
|
||||||
let result2 = parser.parse();
|
|
||||||
assert_eq!(result2, Ok(expected2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_insufficient() {
|
fn test_insufficient() {
|
||||||
let test_data = ":_target\tpsyc://ve.symlynx.com/@blog\n\n:_nick\tlurchi\n|\n".to_string().into_bytes();
|
let test_data = ":_target\tpsyc://ve.symlynx.com/@blog\n\n:_nick\tlurchi\n|\n".to_string().into_bytes();
|
||||||
|
|
||||||
let expected1 = PsycParserResult::InsufficientData;
|
let expected = vec![PsycParserResult::InsufficientData,
|
||||||
let expected2 =PsycParserResult::RoutingModifier {
|
PsycParserResult::RoutingModifier {
|
||||||
operator: ':',
|
operator: ':',
|
||||||
name: &test_data[1 .. 8],
|
name: &test_data[1 .. 8],
|
||||||
value: &test_data[9 .. 36]
|
value: &test_data[9 .. 36]
|
||||||
};
|
},
|
||||||
let expected3 = PsycParserResult::InsufficientData;
|
PsycParserResult::InsufficientData,
|
||||||
let expected4 = PsycParserResult::EntityModifier{
|
PsycParserResult::EntityModifier{
|
||||||
operator: ':',
|
operator: ':',
|
||||||
name: &test_data[39 .. 44],
|
name: &test_data[39 .. 44],
|
||||||
value: &test_data[45 .. 51],
|
value: &test_data[45 .. 51],
|
||||||
};
|
},
|
||||||
let expected5 = PsycParserResult::Complete;
|
PsycParserResult::Complete];
|
||||||
|
|
||||||
let mut parser = PsycParser::new();
|
let mut parser = PsycParser::new();
|
||||||
|
|
||||||
|
parser.set_buffer(&test_data[.. 1]);
|
||||||
|
assert_eq!(parser.parse().unwrap(), expected[0]);
|
||||||
|
|
||||||
{
|
parser.set_buffer(&test_data[.. 46]);
|
||||||
parser.set_buffer(&test_data[.. 1]);
|
assert_eq!(parser.parse().unwrap(), expected[1]);
|
||||||
let result1 = parser.parse();
|
|
||||||
assert_eq!(result1, Ok(expected1));
|
parser.set_buffer(&test_data[.. 49]);
|
||||||
}
|
assert_eq!(parser.parse().unwrap(), expected[2]);
|
||||||
|
|
||||||
{
|
parser.set_buffer(&test_data);
|
||||||
parser.set_buffer(&test_data[.. 46]);
|
assert_eq!(parser.parse().unwrap(), expected[3]);
|
||||||
let result2 = parser.parse();
|
|
||||||
assert_eq!(result2, Ok(expected2));
|
assert_eq!(parser.parse().unwrap(), expected[4]);
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue