This commit is contained in:
Joshua M. Clulow 2021-07-02 00:12:16 +00:00
parent 0ddb6bbb7c
commit c8027ac760
2 changed files with 32 additions and 24 deletions

View File

@ -980,8 +980,10 @@ fn gen(api: &OpenAPI, ts: &mut TypeSpace) -> Result<String> {
/* /*
* Perform the request. * Perform the request.
*/ */
a(&format!(" let res = self.client.{}(url)", a(&format!(
m.to_lowercase())); " let res = self.client.{}(url)",
m.to_lowercase()
));
if let Some(f) = &body_func { if let Some(f) = &body_func {
a(&format!(" .{}(body)", f)); a(&format!(" .{}(body)", f));
} }

View File

@ -109,40 +109,46 @@ fn parse_inner(t: &str) -> Result<Template> {
State::Parameter => bail!("unterminated parameter"), State::Parameter => bail!("unterminated parameter"),
} }
Ok(Template { components, }) Ok(Template { components })
} }
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::{parse, Component, Template};
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use super::{parse, Template, Component};
#[test] #[test]
fn basic() -> Result<()> { fn basic() -> Result<()> {
let trials = vec![ let trials = vec![
("/info", Template { (
components: vec![ "/info",
Component::Constant("info".into()), Template {
], components: vec![Component::Constant("info".into())],
}), },
("/measure/{number}", Template { ),
(
"/measure/{number}",
Template {
components: vec![ components: vec![
Component::Constant("measure".into()), Component::Constant("measure".into()),
Component::Parameter("number".into()), Component::Parameter("number".into()),
], ],
}), },
("/one/{two}/three", Template { ),
(
"/one/{two}/three",
Template {
components: vec![ components: vec![
Component::Constant("one".into()), Component::Constant("one".into()),
Component::Parameter("two".into()), Component::Parameter("two".into()),
Component::Constant("three".into()), Component::Constant("three".into()),
], ],
}), },
),
]; ];
for (path, want) in trials.iter() { for (path, want) in trials.iter() {
let t = parse(path) let t = parse(path).with_context(|| anyhow!("path {}", path))?;
.with_context(|| anyhow!("path {}", path))?;
assert_eq!(&t, want); assert_eq!(&t, want);
} }