diff --git a/src/parsers.rs b/src/parsers.rs index a6d241e..e3269a6 100644 --- a/src/parsers.rs +++ b/src/parsers.rs @@ -189,26 +189,15 @@ fn parse_client(s: Span) -> IResult { Ok((s, (String::from(name), client))) } -fn parse_clients(s: Span) -> IResult> { +fn parse_context(s: Span) -> IResult { let (s, clients) = many0(parse_client)(s)?; - let mut map: HashMap = 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 { - let (s, clients) = parse_clients(s)?; - Ok(( - s, - clients - .into_iter() - .map(|(name, client)| (name, Entity::Client(client))) - .collect::>(), - )) -} - fn parse_sep(s: Span) -> IResult { 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 = HashMap::new(); - clients.insert( + let mut context: HashMap = 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 )) ); }