Skip to content

Commit

Permalink
Wip.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamiel committed Jul 18, 2022
1 parent 2de4005 commit c9a7d59
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/hurl_core/src/ast/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ impl Section {
SectionValue::Cookies(_) => "Cookies",
SectionValue::Captures(_) => "Captures",
SectionValue::MultipartFormData(_) => "MultipartFormData",
SectionValue::Options(_) => "Options",
}
}
}
Expand All @@ -221,6 +222,7 @@ pub enum SectionValue {
Cookies(Vec<Cookie>),
Captures(Vec<Capture>),
Asserts(Vec<Assert>),
Options(Vec<EntryOption>)
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -662,3 +664,33 @@ pub struct Variable {
pub name: String,
pub source_info: SourceInfo,
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum EntryOption {
Insecure {
name: OptionName,
value: OptionValue,
},
CaCertificate {
name: OptionName,
value: OptionValue,
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OptionName {
pub line_terminators: Vec<LineTerminator>,
pub space0: Whitespace,
pub name: String,
pub space1: Whitespace,
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum OptionValue {
Bool {
value: bool
},
String {
value: String
}
}
11 changes: 11 additions & 0 deletions packages/hurl_core/src/format/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ impl Htmlable for SectionValue {
buffer.push_str(item.to_html().as_str())
}
}
SectionValue::Options(items) => {
for item in items {
buffer.push_str(item.to_html().as_str())
}
}
}
buffer
}
Expand All @@ -226,6 +231,12 @@ impl Htmlable for KeyValue {
}
}

impl Htmlable for EntryOption {
fn to_html(&self) -> String {
"TODO".to_string()
}
}

impl Htmlable for MultipartParam {
fn to_html(&self) -> String {
match self {
Expand Down
1 change: 1 addition & 0 deletions packages/hurl_core/src/parser/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub enum ParseError {
InvalidCookieAttribute,
OddNumberOfHexDigits,
UrlIllegalCharacter(char),
OptionName {name: String},
}

impl Error {
Expand Down
40 changes: 40 additions & 0 deletions packages/hurl_core/src/parser/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fn request_section(reader: &mut Reader) -> ParseResult<'static, Section> {
"FormParams" => section_value_form_params(reader)?,
"MultipartFormData" => section_value_multipart_form_data(reader)?,
"Cookies" => section_value_cookies(reader)?,
"Options" => section_value_options(reader)?,
_ => {
return Err(Error {
pos: Pos {
Expand Down Expand Up @@ -150,6 +151,12 @@ fn section_value_asserts(reader: &mut Reader) -> ParseResult<'static, SectionVal
Ok(SectionValue::Asserts(asserts))
}

fn section_value_options(reader: &mut Reader) -> ParseResult<'static, SectionValue> {
let options = zero_or_more(option, reader)?;
Ok(SectionValue::Options(options))
}


fn cookie(reader: &mut Reader) -> ParseResult<'static, Cookie> {
// let start = reader.state.clone();
let line_terminators = optional_line_terminators(reader)?;
Expand Down Expand Up @@ -335,6 +342,39 @@ fn assert(reader: &mut Reader) -> ParseResult<'static, Assert> {
})
}

fn option(reader: &mut Reader) -> ParseResult<'static, EntryOption> {
choice(
vec![
option_insecure,
option_cacert,
],
reader,
)
}


fn option_insecure(reader: &mut Reader) -> ParseResult<'static, EntryOption> {
let start = reader.state.clone();
Err(Error {
pos: start.pos,
recoverable: false,
inner: ParseError::OptionName {
name: "insecure".to_string(),
},
})
}

fn option_cacert(reader: &mut Reader) -> ParseResult<'static, EntryOption> {
let start = reader.state.clone();
Err(Error {
pos: start.pos,
recoverable: false,
inner: ParseError::OptionName {
name: "cacert".to_string(),
},
})
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit c9a7d59

Please sign in to comment.