-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the parser now differentiates between different kinds of properties that may occur multiple times in a component and will no longer override them with each other.
- Loading branch information
Showing
4 changed files
with
121 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,15 +131,26 @@ impl From<Component<'_>> for Other { | |
|
||
impl From<Component<'_>> for InnerComponent { | ||
fn from(component: Component) -> Self { | ||
Self { | ||
let mut from_component = Self { | ||
properties: component | ||
.properties | ||
.into_iter() | ||
.map(|p| (p.name.clone().into_owned().into(), p.into())) | ||
.iter() | ||
.filter(|p| !p.is_multi_property()) | ||
.map(|p| (p.name.clone().into_owned().into(), p.to_owned().into())) | ||
.collect(), | ||
components: component.components.into_iter().map(Other::from).collect(), | ||
multi_properties: Default::default(), | ||
}; | ||
|
||
for p in component | ||
.properties | ||
.into_iter() | ||
.filter(Property::is_multi_property) | ||
{ | ||
from_component.insert_multi(p); | ||
} | ||
|
||
from_component | ||
} | ||
} | ||
|
||
|
@@ -271,6 +282,18 @@ pub fn component<'a, E: ParseError<&'a str> + ContextError<&'a str>>( | |
)) | ||
} | ||
|
||
#[cfg(test)] | ||
pub fn inner_component<'a, E: ParseError<&'a str> + ContextError<&'a str>>( | ||
input: &'a str, | ||
) -> IResult<&'a str, InnerComponent, E> { | ||
match component::<(_, _)>(input) { | ||
Ok(result) => { | ||
return Ok((result.0, InnerComponent::from(result.1))); | ||
} | ||
Err(_e) => todo!(), | ||
}; | ||
} | ||
|
||
#[test] | ||
fn test_components() { | ||
assert_parser!(component, "BEGIN:FOO\nEND:FOO", Component::new_empty("FOO")); | ||
|
@@ -424,6 +447,60 @@ END:VEVENT | |
); | ||
} | ||
|
||
#[test] | ||
fn test_multi_properties() { | ||
let multi_properties = From::from([( | ||
"ATTENDEE".into(), | ||
vec![ | ||
Property { | ||
name: "ATTENDEE".into(), | ||
val: "mailto:[email protected]".into(), | ||
params: vec![ | ||
Parameter { | ||
key: "EMAIL".into(), | ||
val: Some("\"[email protected]\"".into()), | ||
}, | ||
Parameter { | ||
key: "CUTYPE".into(), | ||
val: Some("INDIVIDUAL".into()), | ||
}, | ||
], | ||
} | ||
.into(), | ||
Property { | ||
name: "ATTENDEE".into(), | ||
val: "mailto:[email protected]".into(), | ||
params: vec![ | ||
Parameter { | ||
key: "EMAIL".into(), | ||
val: Some("\"[email protected]\"".into()), | ||
}, | ||
Parameter { | ||
key: "CUTYPE".into(), | ||
val: Some("INDIVIDUAL".into()), | ||
}, | ||
], | ||
} | ||
.into(), | ||
], | ||
)]); | ||
|
||
assert_parser!( | ||
inner_component, | ||
r#" | ||
BEGIN:VEVENT | ||
ATTENDEE;CUTYPE=INDIVIDUAL;EMAIL="[email protected]":mailto:[email protected] | ||
ATTENDEE;CUTYPE=INDIVIDUAL;EMAIL="[email protected]":mailto:[email protected] | ||
END:VEVENT | ||
"#, | ||
InnerComponent { | ||
properties: Default::default(), | ||
multi_properties, | ||
components: vec![] | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_faulty_component() { | ||
use nom::error::{ErrorKind::*, VerboseErrorKind::*}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters