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.
*/
a(&format!(" let res = self.client.{}(url)",
m.to_lowercase()));
a(&format!(
" let res = self.client.{}(url)",
m.to_lowercase()
));
if let Some(f) = &body_func {
a(&format!(" .{}(body)", f));
}

View File

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