diff --git a/packages/hurl/src/runner/body.rs b/packages/hurl/src/runner/body.rs index ffe313390..9ff75ebca 100644 --- a/packages/hurl/src/runner/body.rs +++ b/packages/hurl/src/runner/body.rs @@ -46,8 +46,8 @@ pub fn eval_bytes( let value = eval_multiline(value, variables)?; Ok(http::Body::Text(value)) } - Bytes::Xml { value, .. } => Ok(http::Body::Text(value.clone())), - Bytes::Json { value, .. } => { + Bytes::Xml(value) => Ok(http::Body::Text(value.clone())), + Bytes::Json(value) => { let value = eval_json_value(value, variables)?; Ok(http::Body::Text(value)) } diff --git a/packages/hurl/src/runner/response.rs b/packages/hurl/src/runner/response.rs index 07c6fe65b..56bc68632 100644 --- a/packages/hurl/src/runner/response.rs +++ b/packages/hurl/src/runner/response.rs @@ -124,14 +124,7 @@ pub fn eval_asserts( asserts } -/// Check the body of an actual HTTP response against a spec body. -/// -/// # Arguments -/// -/// * `spec_body` - The spec HTTP response body -/// * `variables` - A map of input variables -/// * `http_response` - The actual HTTP response -/// * `context_dir` - The context directory for files +/// Check the body of an actual HTTP response against a spec body, given a set of variables. fn eval_implicit_body_asserts( spec_body: &Body, variables: &HashMap, @@ -139,7 +132,7 @@ fn eval_implicit_body_asserts( context_dir: &ContextDir, ) -> AssertResult { match &spec_body.value { - Bytes::Json { value } => { + Bytes::Json(value) => { let expected = match eval_json_value(value, variables) { Ok(s) => Ok(Value::String(s)), Err(e) => Err(e), @@ -161,7 +154,7 @@ fn eval_implicit_body_asserts( source_info: spec_body.space0.source_info.clone(), } } - Bytes::Xml { value } => { + Bytes::Xml(value) => { let expected = Ok(Value::String(value.to_string())); let actual = match http_response.text() { Ok(s) => Ok(Value::String(s)), diff --git a/packages/hurl_core/src/ast/core.rs b/packages/hurl_core/src/ast/core.rs index 15b4caa96..f0382ca53 100644 --- a/packages/hurl_core/src/ast/core.rs +++ b/packages/hurl_core/src/ast/core.rs @@ -624,8 +624,8 @@ pub struct LineTerminator { #[derive(Clone, Debug, PartialEq, Eq)] pub enum Bytes { - Json { value: json::Value }, - Xml { value: String }, + Json(json::Value), + Xml(String), MultilineString(MultilineString), Base64(Base64), File(File), diff --git a/packages/hurl_core/src/format/html.rs b/packages/hurl_core/src/format/html.rs index 38cb15bcc..7b9ef6ede 100644 --- a/packages/hurl_core/src/format/html.rs +++ b/packages/hurl_core/src/format/html.rs @@ -930,9 +930,9 @@ impl Htmlable for Bytes { Bytes::Base64(value) => format!("{}", value.to_html()), Bytes::File(value) => format!("{}", value.to_html()), Bytes::Hex(value) => format!("{}", value.to_html()), - Bytes::Json { value } => value.to_html(), + Bytes::Json(value) => value.to_html(), Bytes::MultilineString(value) => value.to_html(), - Bytes::Xml { value } => xml_html(value), + Bytes::Xml(value) => xml_html(value), } } } diff --git a/packages/hurl_core/src/parser/bytes.rs b/packages/hurl_core/src/parser/bytes.rs index 4880323a5..1a7071f0b 100644 --- a/packages/hurl_core/src/parser/bytes.rs +++ b/packages/hurl_core/src/parser/bytes.rs @@ -42,14 +42,14 @@ pub fn bytes(reader: &mut Reader) -> ParseResult<'static, Bytes> { fn xml_bytes(reader: &mut Reader) -> ParseResult<'static, Bytes> { match xml::parse(reader) { Err(e) => Err(e), - Ok(value) => Ok(Bytes::Xml { value }), + Ok(value) => Ok(Bytes::Xml(value)), } } fn json_bytes(reader: &mut Reader) -> ParseResult<'static, Bytes> { match parse_json(reader) { Err(e) => Err(e), - Ok(value) => Ok(Bytes::Json { value }), + Ok(value) => Ok(Bytes::Json(value)), } } @@ -79,62 +79,54 @@ mod tests { let mut reader = Reader::init("[1,2,3] "); assert_eq!( bytes(&mut reader).unwrap(), - Bytes::Json { - value: JsonValue::List { - space0: "".to_string(), - elements: vec![ - JsonListElement { - space0: "".to_string(), - value: JsonValue::Number("1".to_string()), - space1: "".to_string() - }, - JsonListElement { - space0: "".to_string(), - value: JsonValue::Number("2".to_string()), - space1: "".to_string() - }, - JsonListElement { - space0: "".to_string(), - value: JsonValue::Number("3".to_string()), - space1: "".to_string() - }, - ], - } - } + Bytes::Json(JsonValue::List { + space0: "".to_string(), + elements: vec![ + JsonListElement { + space0: "".to_string(), + value: JsonValue::Number("1".to_string()), + space1: "".to_string(), + }, + JsonListElement { + space0: "".to_string(), + value: JsonValue::Number("2".to_string()), + space1: "".to_string(), + }, + JsonListElement { + space0: "".to_string(), + value: JsonValue::Number("3".to_string()), + space1: "".to_string(), + }, + ], + }) ); assert_eq!(reader.state.cursor, 7); let mut reader = Reader::init("{ } "); assert_eq!( bytes(&mut reader).unwrap(), - Bytes::Json { - value: JsonValue::Object { - space0: " ".to_string(), - elements: vec![], - } - } + Bytes::Json(JsonValue::Object { + space0: " ".to_string(), + elements: vec![], + }) ); assert_eq!(reader.state.cursor, 3); let mut reader = Reader::init("true"); assert_eq!( bytes(&mut reader).unwrap(), - Bytes::Json { - value: JsonValue::Boolean(true) - } + Bytes::Json(JsonValue::Boolean(true)) ); assert_eq!(reader.state.cursor, 4); let mut reader = Reader::init("\"\" x"); assert_eq!( bytes(&mut reader).unwrap(), - Bytes::Json { - value: JsonValue::String(Template { - delimiter: Some('"'), - elements: vec![], - source_info: SourceInfo::new(1, 2, 1, 2), - }) - } + Bytes::Json(JsonValue::String(Template { + delimiter: Some('"'), + elements: vec![], + source_info: SourceInfo::new(1, 2, 1, 2), + })) ); assert_eq!(reader.state.cursor, 2); } @@ -144,9 +136,7 @@ mod tests { let mut reader = Reader::init(""); assert_eq!( bytes(&mut reader).unwrap(), - Bytes::Xml { - value: String::from("") - } + Bytes::Xml(String::from("")) ); } @@ -189,9 +179,7 @@ mod tests { let mut reader = Reader::init("100"); assert_eq!( json_bytes(&mut reader).unwrap(), - Bytes::Json { - value: JsonValue::Number("100".to_string()) - } + Bytes::Json(JsonValue::Number("100".to_string())) ); } } diff --git a/packages/hurl_core/src/parser/parsers.rs b/packages/hurl_core/src/parser/parsers.rs index d43a1a559..80079b071 100644 --- a/packages/hurl_core/src/parser/parsers.rs +++ b/packages/hurl_core/src/parser/parsers.rs @@ -227,7 +227,7 @@ fn status(reader: &mut Reader) -> ParseResult<'static, Status> { pos: start, recoverable: false, inner: ParseError::Status {}, - }) + }); } }, }; @@ -429,7 +429,7 @@ mod tests { }], delimiter: None, source_info: SourceInfo::new(3, 1, 4, 1), - } + }, })), line_terminator0: LineTerminator { space0: Whitespace { @@ -453,28 +453,26 @@ mod tests { assert_eq!(r.method, Method::Post); assert_eq!( r.body.unwrap().value, - Bytes::Json { - value: JsonValue::List { - space0: "".to_string(), - elements: vec![ - JsonListElement { - space0: "".to_string(), - value: JsonValue::Number("1".to_string()), - space1: "".to_string(), - }, - JsonListElement { - space0: "".to_string(), - value: JsonValue::Number("2".to_string()), - space1: "".to_string(), - }, - JsonListElement { - space0: "".to_string(), - value: JsonValue::Number("3".to_string()), - space1: "".to_string(), - }, - ], - } - } + Bytes::Json(JsonValue::List { + space0: "".to_string(), + elements: vec![ + JsonListElement { + space0: "".to_string(), + value: JsonValue::Number("1".to_string()), + space1: "".to_string(), + }, + JsonListElement { + space0: "".to_string(), + value: JsonValue::Number("2".to_string()), + space1: "".to_string(), + }, + JsonListElement { + space0: "".to_string(), + value: JsonValue::Number("3".to_string()), + space1: "".to_string(), + }, + ], + }) ); let mut reader = Reader::init("POST http://localhost:8000/post-json-string\n\"Hello\""); @@ -482,16 +480,14 @@ mod tests { assert_eq!(r.method, Method::Post); assert_eq!( r.body.unwrap().value, - Bytes::Json { - value: JsonValue::String(Template { - delimiter: Some('"'), - elements: vec![TemplateElement::String { - value: "Hello".to_string(), - encoded: "Hello".to_string(), - }], - source_info: SourceInfo::new(2, 2, 2, 7), - }) - } + Bytes::Json(JsonValue::String(Template { + delimiter: Some('"'), + elements: vec![TemplateElement::String { + value: "Hello".to_string(), + encoded: "Hello".to_string(), + }], + source_info: SourceInfo::new(2, 2, 2, 7), + })) ); let mut reader = Reader::init("POST http://localhost:8000/post-json-number\n100"); @@ -499,9 +495,7 @@ mod tests { assert_eq!(r.method, Method::Post); assert_eq!( r.body.unwrap().value, - Bytes::Json { - value: JsonValue::Number("100".to_string()) - } + Bytes::Json(JsonValue::Number("100".to_string())) ); } @@ -571,28 +565,26 @@ mod tests { assert_eq!(b.line_terminators.len(), 0); assert_eq!( b.value, - Bytes::Json { - value: JsonValue::List { - space0: "".to_string(), - elements: vec![ - JsonListElement { - space0: "".to_string(), - value: JsonValue::Number("1".to_string()), - space1: "".to_string(), - }, - JsonListElement { - space0: "".to_string(), - value: JsonValue::Number("2".to_string()), - space1: "".to_string(), - }, - JsonListElement { - space0: "".to_string(), - value: JsonValue::Number("3".to_string()), - space1: "".to_string(), - }, - ], - } - } + Bytes::Json(JsonValue::List { + space0: "".to_string(), + elements: vec![ + JsonListElement { + space0: "".to_string(), + value: JsonValue::Number("1".to_string()), + space1: "".to_string(), + }, + JsonListElement { + space0: "".to_string(), + value: JsonValue::Number("2".to_string()), + space1: "".to_string(), + }, + JsonListElement { + space0: "".to_string(), + value: JsonValue::Number("3".to_string()), + space1: "".to_string(), + }, + ], + }) ); assert_eq!(reader.state.cursor, 8); @@ -601,12 +593,10 @@ mod tests { assert_eq!(b.line_terminators.len(), 0); assert_eq!( b.value, - Bytes::Json { - value: JsonValue::Object { - space0: "".to_string(), - elements: vec![], - } - } + Bytes::Json(JsonValue::Object { + space0: "".to_string(), + elements: vec![], + }) ); assert_eq!(reader.state.cursor, 2); @@ -615,12 +605,10 @@ mod tests { assert_eq!(b.line_terminators.len(), 1); assert_eq!( b.value, - Bytes::Json { - value: JsonValue::Object { - space0: "".to_string(), - elements: vec![], - } - } + Bytes::Json(JsonValue::Object { + space0: "".to_string(), + elements: vec![], + }) ); assert_eq!(reader.state.cursor, 24); diff --git a/packages/hurlfmt/src/format/json.rs b/packages/hurlfmt/src/format/json.rs index 9ec69f7b7..2553d8e51 100644 --- a/packages/hurlfmt/src/format/json.rs +++ b/packages/hurlfmt/src/format/json.rs @@ -133,11 +133,11 @@ impl ToJson for Bytes { Bytes::Base64(value) => value.to_json(), Bytes::Hex(value) => value.to_json(), Bytes::File(value) => value.to_json(), - Bytes::Json { value } => JValue::Object(vec![ + Bytes::Json(value) => JValue::Object(vec![ ("type".to_string(), JValue::String("json".to_string())), ("value".to_string(), value.to_json()), ]), - Bytes::Xml { value } => JValue::Object(vec![ + Bytes::Xml(value) => JValue::Object(vec![ ("type".to_string(), JValue::String("xml".to_string())), ("value".to_string(), JValue::String(value.clone())), ]), diff --git a/packages/hurlfmt/src/format/token.rs b/packages/hurlfmt/src/format/token.rs index e719ebbdf..e8984e78e 100644 --- a/packages/hurlfmt/src/format/token.rs +++ b/packages/hurlfmt/src/format/token.rs @@ -160,22 +160,12 @@ impl Tokenizable for Bytes { fn tokenize(&self) -> Vec { let mut tokens: Vec = vec![]; match self { - Bytes::Json { value } => tokens.append(&mut value.tokenize()), - Bytes::Xml { value } => { - tokens.push(Token::String(value.to_string())); - } - Bytes::MultilineString(value) => { - tokens.append(&mut value.tokenize()); - } - Bytes::Base64(value) => { - tokens.append(&mut value.tokenize()); - } - Bytes::Hex(value) => { - tokens.append(&mut value.tokenize()); - } - Bytes::File(value) => { - tokens.append(&mut value.tokenize()); - } + Bytes::Json(value) => tokens.append(&mut value.tokenize()), + Bytes::Xml(value) => tokens.push(Token::String(value.to_string())), + Bytes::MultilineString(value) => tokens.append(&mut value.tokenize()), + Bytes::Base64(value) => tokens.append(&mut value.tokenize()), + Bytes::Hex(value) => tokens.append(&mut value.tokenize()), + Bytes::File(value) => tokens.append(&mut value.tokenize()), } tokens } diff --git a/packages/hurlfmt/src/linter/rules.rs b/packages/hurlfmt/src/linter/rules.rs index d8c37cc4e..af0d8065c 100644 --- a/packages/hurlfmt/src/linter/rules.rs +++ b/packages/hurlfmt/src/linter/rules.rs @@ -602,20 +602,13 @@ impl Lintable for Bytes { } fn lint(&self) -> Bytes { - //let space0 = Whitespace { value: String::from(""), source_info: SourceInfo::init(0, 0, 0, 0) }; - //let value = self.value.lint(); - //let line_terminator0 = self.clone().line_terminator0; match self { Bytes::File(value) => Bytes::File(value.lint()), Bytes::Base64(value) => Bytes::Base64(value.lint()), Bytes::Hex(value) => Bytes::Hex(value.lint()), - Bytes::Json { value } => Bytes::Json { - value: value.clone(), - }, + Bytes::Json(value) => Bytes::Json(value.clone()), Bytes::MultilineString(value) => Bytes::MultilineString(value.lint()), - Bytes::Xml { value } => Bytes::Xml { - value: value.clone(), - }, + Bytes::Xml(value) => Bytes::Xml(value.clone()), } } }