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 c9a7d59 commit 062e862
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 55 deletions.
5 changes: 5 additions & 0 deletions integration/tests_ok/options.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GET http://localhost:8000/options/hello
[Options]
insecure: true

HTTP/* 200
6 changes: 6 additions & 0 deletions integration/tests_ok/options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from app import app


@app.route("/options/hello")
def options_hello():
return "Hello!"
29 changes: 10 additions & 19 deletions packages/hurl_core/src/ast/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub enum SectionValue {
Cookies(Vec<Cookie>),
Captures(Vec<Capture>),
Asserts(Vec<Assert>),
Options(Vec<EntryOption>)
Options(Vec<EntryOption>),
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -667,30 +667,21 @@ pub struct Variable {

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

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

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum OptionValue {
Bool {
value: bool
},
String {
value: String
}
}
pub struct CaCertificateOption {
pub value: Template,
}
2 changes: 1 addition & 1 deletion packages/hurl_core/src/format/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl Htmlable for KeyValue {

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

Expand Down
2 changes: 1 addition & 1 deletion packages/hurl_core/src/parser/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub enum ParseError {
InvalidCookieAttribute,
OddNumberOfHexDigits,
UrlIllegalCharacter(char),
OptionName {name: String},
InvalidOption,
}

impl Error {
Expand Down
56 changes: 27 additions & 29 deletions packages/hurl_core/src/parser/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ fn section_value_options(reader: &mut Reader) -> ParseResult<'static, SectionVal
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 @@ -343,36 +342,35 @@ fn assert(reader: &mut Reader) -> ParseResult<'static, Assert> {
}

fn option(reader: &mut Reader) -> ParseResult<'static, EntryOption> {
choice(
vec![
option_insecure,
option_cacert,
],
reader,
)
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(),
},
})
let line_terminators = optional_line_terminators(reader)?;
let space0 = zero_or_more_spaces(reader)?;
try_literal("insecure", reader)?;
let space1 = zero_or_more_spaces(reader)?;
// Why recover? and not try_literal ?
recover(|reader1| literal(":", reader1), reader)?;
let space2 = zero_or_more_spaces(reader)?;
let value = unquoted_template(reader)?;
let line_terminator0 = line_terminator(reader)?;

let option = InsecureOption {
line_terminators,
space0,
space1,
space2,
value,
line_terminator0,
};

Ok(EntryOption::Insecure(option))
}

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(),
},
})
try_literal("cacert", reader)?;
unimplemented!()
}

#[cfg(test)]
Expand Down Expand Up @@ -517,9 +515,9 @@ mod tests {
quotes: false,
elements: vec![TemplateElement::String {
value: "Bar".to_string(),
encoded: "Bar".to_string()
encoded: "Bar".to_string(),
}],
source_info: SourceInfo::init(1, 6, 1, 9)
source_info: SourceInfo::init(1, 6, 1, 9),
}
);
}
Expand All @@ -532,7 +530,7 @@ mod tests {
error.pos,
Pos {
line: 1,
column: 11
column: 11,
}
);
assert!(!error.recoverable);
Expand Down Expand Up @@ -715,7 +713,7 @@ mod tests {
error.pos,
Pos {
line: 1,
column: 32
column: 32,
}
);
assert_eq!(
Expand Down
12 changes: 12 additions & 0 deletions packages/hurlfmt/src/format/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ impl Tokenizable for SectionValue {
items.iter().flat_map(|e| e.tokenize()).collect(),
);
}
SectionValue::Options(items) => {
add_tokens(
&mut tokens,
items.iter().flat_map(|e| e.tokenize()).collect(),
);
}
}
tokens
}
Expand Down Expand Up @@ -852,3 +858,9 @@ impl Tokenizable for JsonObjectElement {
tokens
}
}

impl Tokenizable for EntryOption {
fn tokenize(&self) -> Vec<Token> {
vec![]
}
}
28 changes: 23 additions & 5 deletions packages/hurlfmt/src/linter/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,23 @@ impl Lintable<SectionValue> for SectionValue {
SectionValue::Cookies(cookies) => {
SectionValue::Cookies(cookies.iter().map(|e| e.lint()).collect())
}
SectionValue::Options(options) => {
SectionValue::Options(options.iter().map(|e| e.lint()).collect())
}
}
}
}

fn section_value_index(section_value: SectionValue) -> u32 {
match section_value {
SectionValue::QueryParams(_) => 0,
SectionValue::BasicAuth(_) => 1,
SectionValue::FormParams(_) => 2,
SectionValue::MultipartFormData(_) => 3,
SectionValue::Cookies(_) => 3,
// Request sections
SectionValue::Options(_) => 0,
SectionValue::QueryParams(_) => 1,
SectionValue::BasicAuth(_) => 2,
SectionValue::FormParams(_) => 3,
SectionValue::MultipartFormData(_) => 4,
SectionValue::Cookies(_) => 5,
// Response sections
SectionValue::Captures(_) => 0,
SectionValue::Asserts(_) => 1,
}
Expand Down Expand Up @@ -525,6 +531,7 @@ impl Lintable<PredicateValue> for PredicateValue {
}
}
}

impl Lintable<RawString> for RawString {
fn errors(&self) -> Vec<Error> {
let errors = vec![];
Expand Down Expand Up @@ -801,6 +808,17 @@ impl Lintable<Template> for Template {
}
}

impl Lintable<EntryOption> for EntryOption {
fn errors(&self) -> Vec<Error> {
let errors = vec![];
errors
}

fn lint(&self) -> EntryOption {
self.clone()
}
}

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

0 comments on commit 062e862

Please sign in to comment.