parser: test_context
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
1987b44315
commit
4688712904
1 changed files with 17 additions and 22 deletions
|
@ -189,26 +189,15 @@ fn parse_client(s: Span) -> IResult<Span, (Name, Client)> {
|
|||
Ok((s, (String::from(name), client)))
|
||||
}
|
||||
|
||||
fn parse_clients(s: Span) -> IResult<Span, HashMap<Name, Client>> {
|
||||
fn parse_context(s: Span) -> IResult<Span, Context> {
|
||||
let (s, clients) = many0(parse_client)(s)?;
|
||||
let mut map: HashMap<Name, Client> = HashMap::new();
|
||||
let mut map: Context = HashMap::new();
|
||||
for (name, client) in clients {
|
||||
map.insert(name, client);
|
||||
map.insert(name, Entity::Client(client));
|
||||
}
|
||||
Ok((s, map))
|
||||
}
|
||||
|
||||
fn parse_context(s: Span) -> IResult<Span, Context> {
|
||||
let (s, clients) = parse_clients(s)?;
|
||||
Ok((
|
||||
s,
|
||||
clients
|
||||
.into_iter()
|
||||
.map(|(name, client)| (name, Entity::Client(client)))
|
||||
.collect::<HashMap<_, _>>(),
|
||||
))
|
||||
}
|
||||
|
||||
fn parse_sep(s: Span) -> IResult<Span, Token> {
|
||||
let (s, (pos, _)) = delimited(allspaces, tuple((position, many1(tag("-")))), allspaces)(s)?;
|
||||
Ok((s, Token { position: pos }))
|
||||
|
@ -458,7 +447,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_clients() {
|
||||
fn test_context() {
|
||||
let buf1 = r#"
|
||||
[Client] louise
|
||||
jid: louise@localhost
|
||||
|
@ -469,20 +458,26 @@ mod tests {
|
|||
password: password
|
||||
"#;
|
||||
|
||||
let mut clients: HashMap<Name, Client> = HashMap::new();
|
||||
clients.insert(
|
||||
let mut context: HashMap<Name, Entity> = HashMap::new();
|
||||
context.insert(
|
||||
String::from("louise"),
|
||||
Client::new(Jid::from_str("louise@localhost").unwrap(), "password"),
|
||||
Entity::Client(Client::new(
|
||||
Jid::from_str("louise@localhost").unwrap(),
|
||||
"password",
|
||||
)),
|
||||
);
|
||||
clients.insert(
|
||||
context.insert(
|
||||
String::from("須賀子"),
|
||||
Client::new(Jid::from_str("sugako@localhost").unwrap(), "password"),
|
||||
Entity::Client(Client::new(
|
||||
Jid::from_str("sugako@localhost").unwrap(),
|
||||
"password",
|
||||
)),
|
||||
);
|
||||
assert_eq!(
|
||||
parse_clients(buf1.into()),
|
||||
parse_context(buf1.into()),
|
||||
Ok((
|
||||
unsafe { LocatedSpan::new_from_raw_offset(123, 9, "", ()) },
|
||||
clients
|
||||
context
|
||||
))
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue