From a8e7fe92ba600b85c37e28dd6fad02f69957fa88 Mon Sep 17 00:00:00 2001 From: jcamiel Date: Mon, 27 Nov 2023 15:52:46 +0100 Subject: [PATCH] Create new on SourceInfo and Pos. --- packages/hurl/src/output/raw.rs | 4 +- packages/hurl/src/report/html/source.rs | 4 +- packages/hurl/src/report/junit/mod.rs | 6 +- packages/hurl/src/report/junit/testcase.rs | 6 +- packages/hurl/src/runner/assert.rs | 8 +- packages/hurl/src/runner/body.rs | 13 +- packages/hurl/src/runner/capture.rs | 20 +-- packages/hurl/src/runner/filter/count.rs | 9 +- .../hurl/src/runner/filter/days_after_now.rs | 8 +- packages/hurl/src/runner/filter/decode.rs | 4 +- packages/hurl/src/runner/filter/eval.rs | 4 +- packages/hurl/src/runner/filter/format.rs | 4 +- .../hurl/src/runner/filter/html_escape.rs | 4 +- .../hurl/src/runner/filter/html_unescape.rs | 4 +- packages/hurl/src/runner/filter/jsonpath.rs | 10 +- packages/hurl/src/runner/filter/nth.rs | 8 +- packages/hurl/src/runner/filter/regex.rs | 24 ++-- packages/hurl/src/runner/filter/replace.rs | 12 +- packages/hurl/src/runner/filter/split.rs | 10 +- packages/hurl/src/runner/filter/to_date.rs | 16 ++- packages/hurl/src/runner/filter/to_int.rs | 6 +- packages/hurl/src/runner/filter/url_encode.rs | 4 +- packages/hurl/src/runner/json.rs | 29 ++-- packages/hurl/src/runner/multiline.rs | 8 +- packages/hurl/src/runner/multipart.rs | 14 +- packages/hurl/src/runner/options.rs | 14 +- packages/hurl/src/runner/predicate.rs | 45 +++--- packages/hurl/src/runner/query.rs | 116 ++++++++------- packages/hurl/src/runner/request.rs | 41 +++--- packages/hurl/src/runner/response.rs | 20 +-- packages/hurl/src/runner/template.rs | 17 ++- packages/hurl/src/util/logger.rs | 15 +- packages/hurl_core/src/ast/core.rs | 24 ++-- packages/hurl_core/src/ast/display.rs | 8 +- packages/hurl_core/src/ast/json.rs | 26 ++-- packages/hurl_core/src/format/html.rs | 10 +- packages/hurl_core/src/parser/bytes.rs | 4 +- packages/hurl_core/src/parser/cookiepath.rs | 20 +-- packages/hurl_core/src/parser/expr.rs | 17 +-- packages/hurl_core/src/parser/filename.rs | 6 +- packages/hurl_core/src/parser/filter.rs | 2 +- packages/hurl_core/src/parser/json.rs | 22 +-- packages/hurl_core/src/parser/key_string.rs | 12 +- packages/hurl_core/src/parser/multiline.rs | 98 ++++++------- packages/hurl_core/src/parser/parsers.rs | 72 ++++------ packages/hurl_core/src/parser/predicate.rs | 28 ++-- packages/hurl_core/src/parser/primitives.rs | 136 +++++++----------- packages/hurl_core/src/parser/query.rs | 38 ++--- packages/hurl_core/src/parser/sections.rs | 104 +++++++------- packages/hurl_core/src/parser/string.rs | 32 ++--- packages/hurl_core/src/parser/template.rs | 22 +-- packages/hurl_core/src/parser/url.rs | 12 +- packages/hurlfmt/src/format/json.rs | 30 ++-- packages/hurlfmt/src/linter/rules.rs | 24 ++-- packages/hurlfmt/tests/json.rs | 4 +- 55 files changed, 614 insertions(+), 644 deletions(-) diff --git a/packages/hurl/src/output/raw.rs b/packages/hurl/src/output/raw.rs index b6693e570a0..e0f39e6c175 100644 --- a/packages/hurl/src/output/raw.rs +++ b/packages/hurl/src/output/raw.rs @@ -15,7 +15,7 @@ * limitations under the License. * */ -use hurl_core::ast::SourceInfo; +use hurl_core::ast::{Pos, SourceInfo}; use hurl_core::error::Error; use crate::runner::HurlResult; @@ -54,7 +54,7 @@ pub fn write_body( // FIXME: we convert to a runner::Error to be able to use fixme // method. Can we do otherwise (without creating an artificial // error a first character). - let source_info = SourceInfo::new(0, 0, 0, 0); + let source_info = SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)); let error = runner::Error::new(source_info, e.into(), false); let message = error.fixme(); return Err(output::error::Error::new(&message)); diff --git a/packages/hurl/src/report/html/source.rs b/packages/hurl/src/report/html/source.rs index c2014e2312f..14bc0c7f421 100644 --- a/packages/hurl/src/report/html/source.rs +++ b/packages/hurl/src/report/html/source.rs @@ -83,7 +83,7 @@ fn underline_errors(content: &str, errors: &[RunnerError]) -> String { #[cfg(test)] mod tests { - use hurl_core::ast::SourceInfo; + use hurl_core::ast::{Pos, SourceInfo}; use super::*; use crate::runner::RunnerError::QueryHeaderNotFound; @@ -137,7 +137,7 @@ mod tests { "#; let errors = vec![RunnerError { - source_info: SourceInfo::new(2, 1, 2, 4), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(2, 4)), inner: QueryHeaderNotFound, assert: true, }]; diff --git a/packages/hurl/src/report/junit/mod.rs b/packages/hurl/src/report/junit/mod.rs index f7f7e815f8a..65dc3cf7085 100644 --- a/packages/hurl/src/report/junit/mod.rs +++ b/packages/hurl/src/report/junit/mod.rs @@ -128,7 +128,7 @@ fn create_testsuite(testcases: &[Testcase]) -> Element { #[cfg(test)] mod tests { - use hurl_core::ast::SourceInfo; + use hurl_core::ast::{Pos, SourceInfo}; use crate::report::junit::xml::XmlDocument; use crate::report::junit::{create_testsuite, Testcase}; @@ -157,7 +157,7 @@ mod tests { captures: vec![], asserts: vec![], errors: vec![Error::new( - SourceInfo::new(2, 10, 2, 13), + SourceInfo::new(Pos::new(2, 10), Pos::new(2, 13)), RunnerError::AssertStatus { actual: "404".to_string(), }, @@ -181,7 +181,7 @@ mod tests { captures: vec![], asserts: vec![], errors: vec![Error::new( - SourceInfo::new(1, 5, 1, 19), + SourceInfo::new(Pos::new(1, 5), Pos::new(1, 19)), RunnerError::HttpConnection("(6) Could not resolve host: unknown".to_string()), false, )], diff --git a/packages/hurl/src/report/junit/testcase.rs b/packages/hurl/src/report/junit/testcase.rs index ea8ad53d5e8..c2b86d8fe2e 100644 --- a/packages/hurl/src/report/junit/testcase.rs +++ b/packages/hurl/src/report/junit/testcase.rs @@ -84,7 +84,7 @@ impl Testcase { #[cfg(test)] mod test { - use hurl_core::ast::SourceInfo; + use hurl_core::ast::{Pos, SourceInfo}; use crate::report::junit::testcase::Testcase; use crate::report::junit::xml::XmlDocument; @@ -123,7 +123,7 @@ HTTP/1.0 200 captures: vec![], asserts: vec![], errors: vec![Error::new( - SourceInfo::new(2, 10, 2, 13), + SourceInfo::new(Pos::new(2, 10), Pos::new(2, 13)), RunnerError::AssertStatus { actual: "404".to_string(), }, @@ -162,7 +162,7 @@ HTTP/1.0 200 captures: vec![], asserts: vec![], errors: vec![Error::new( - SourceInfo::new(1, 5, 1, 19), + SourceInfo::new(Pos::new(1, 5), Pos::new(1, 19)), RunnerError::HttpConnection("(6) Could not resolve host: unknown".to_string()), false, )], diff --git a/packages/hurl/src/runner/assert.rs b/packages/hurl/src/runner/assert.rs index 7818a01dd9b..930dee9865b 100644 --- a/packages/hurl/src/runner/assert.rs +++ b/packages/hurl/src/runner/assert.rs @@ -175,13 +175,13 @@ pub mod tests { pub fn assert_count_user() -> Assert { let whitespace = Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }; let predicate = Predicate { not: false, space0: whitespace.clone(), predicate_func: PredicateFunc { - source_info: SourceInfo::new(1, 22, 1, 24), + source_info: SourceInfo::new(Pos::new(1, 22), Pos::new(1, 24)), value: PredicateFuncValue::Equal { space0: whitespace.clone(), value: PredicateValue::Number(hurl_core::ast::Number::Integer(3)), @@ -196,7 +196,7 @@ pub mod tests { filters: vec![( whitespace.clone(), Filter { - source_info: SourceInfo::new(1, 16, 1, 21), + source_info: SourceInfo::new(Pos::new(1, 16), Pos::new(1, 21)), value: FilterValue::Count, }, )], @@ -224,7 +224,7 @@ pub mod tests { ), AssertResult::Explicit { actual: Ok(Some(Value::Number(Number::Integer(3)))), - source_info: SourceInfo::new(1, 22, 1, 24), + source_info: SourceInfo::new(Pos::new(1, 22), Pos::new(1, 24)), predicate_result: Some(Ok(())), } ); diff --git a/packages/hurl/src/runner/body.rs b/packages/hurl/src/runner/body.rs index f0eba76b109..710efbb4ab1 100644 --- a/packages/hurl/src/runner/body.rs +++ b/packages/hurl/src/runner/body.rs @@ -95,14 +95,14 @@ mod tests { // file, data.bin; let whitespace = Whitespace { value: String::from(" "), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; let bytes = Bytes::File(File { space0: whitespace.clone(), filename: Filename { value: String::from("tests/data.bin"), - source_info: SourceInfo::new(1, 7, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 15)), }, space1: whitespace, }); @@ -122,14 +122,14 @@ mod tests { // file, data.bin; let whitespace = Whitespace { value: String::from(" "), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; let bytes = Bytes::File(File { space0: whitespace.clone(), filename: Filename { value: String::from("data.bin"), - source_info: SourceInfo::new(1, 7, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 15)), }, space1: whitespace, }); @@ -146,6 +146,9 @@ mod tests { value: "data.bin".to_string() } ); - assert_eq!(error.source_info, SourceInfo::new(1, 7, 1, 15)); + assert_eq!( + error.source_info, + SourceInfo::new(Pos::new(1, 7), Pos::new(1, 15)) + ); } } diff --git a/packages/hurl/src/runner/capture.rs b/packages/hurl/src/runner/capture.rs index e0e45ee903d..271b8dac368 100644 --- a/packages/hurl/src/runner/capture.rs +++ b/packages/hurl/src/runner/capture.rs @@ -77,7 +77,7 @@ pub mod tests { // non scalar value let whitespace = Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; Capture { line_terminators: vec![], @@ -88,7 +88,7 @@ pub mod tests { value: "UserCount".to_string(), encoded: "UserCount".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace.clone(), space2: whitespace.clone(), @@ -108,7 +108,7 @@ pub mod tests { // non scalar value let whitespace = Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; Capture { line_terminators: vec![], @@ -119,7 +119,7 @@ pub mod tests { value: "duration".to_string(), encoded: "duration".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace.clone(), space2: whitespace.clone(), @@ -140,7 +140,7 @@ pub mod tests { let variables = HashMap::new(); let whitespace = Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; let capture = Capture { line_terminators: vec![], @@ -151,7 +151,7 @@ pub mod tests { value: "count".to_string(), encoded: "count".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, filters: vec![], space1: whitespace.clone(), @@ -177,7 +177,7 @@ pub mod tests { // non scalar value let whitespace = Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; let _capture = Capture { line_terminators: vec![], @@ -188,14 +188,14 @@ pub mod tests { value: "???".to_string(), encoded: "???".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace.clone(), space2: whitespace.clone(), // xpath //user query: Query { - source_info: SourceInfo::new(1, 1, 1, 13), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 13)), value: QueryValue::Xpath { space0: whitespace.clone(), expr: Template { @@ -204,7 +204,7 @@ pub mod tests { value: "//user".to_string(), encoded: "//user".to_string(), }], - source_info: SourceInfo::new(1, 7, 1, 13), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 13)), }, }, }, diff --git a/packages/hurl/src/runner/filter/count.rs b/packages/hurl/src/runner/filter/count.rs index 7768d132580..3d2a90f4130 100644 --- a/packages/hurl/src/runner/filter/count.rs +++ b/packages/hurl/src/runner/filter/count.rs @@ -39,7 +39,7 @@ pub fn eval_count( #[cfg(test)] pub mod tests { use crate::runner::filter::eval::eval_filter; - use hurl_core::ast::{Filter, FilterValue, SourceInfo}; + use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo}; use std::collections::HashMap; use super::*; @@ -49,7 +49,7 @@ pub mod tests { let variables = HashMap::new(); let filter = Filter { - source_info: SourceInfo::new(1, 1, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 6)), value: FilterValue::Count, }; assert_eq!( @@ -71,7 +71,10 @@ pub mod tests { let error = eval_filter(&filter, &Value::Bool(true), &variables, false) .err() .unwrap(); - assert_eq!(error.source_info, SourceInfo::new(1, 1, 1, 6)); + assert_eq!( + error.source_info, + SourceInfo::new(Pos::new(1, 1), Pos::new(1, 6)) + ); assert_eq!( error.inner, RunnerError::FilterInvalidInput("boolean".to_string()) diff --git a/packages/hurl/src/runner/filter/days_after_now.rs b/packages/hurl/src/runner/filter/days_after_now.rs index db410f87d3c..6269db93108 100644 --- a/packages/hurl/src/runner/filter/days_after_now.rs +++ b/packages/hurl/src/runner/filter/days_after_now.rs @@ -44,7 +44,7 @@ pub mod tests { use crate::runner::filter::eval::eval_filter; use chrono::offset::Utc; use chrono::Duration; - use hurl_core::ast::{Filter, FilterValue, SourceInfo}; + use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo}; use std::collections::HashMap; use super::*; @@ -57,7 +57,7 @@ pub mod tests { assert_eq!( eval_filter( &Filter { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), value: FilterValue::DaysAfterNow, }, &Value::Date(now), @@ -73,7 +73,7 @@ pub mod tests { assert_eq!( eval_filter( &Filter { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), value: FilterValue::DaysAfterNow, }, &Value::Date(now_plus_30hours), @@ -87,7 +87,7 @@ pub mod tests { assert_eq!( eval_filter( &Filter { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), value: FilterValue::DaysBeforeNow, }, &Value::Date(now_plus_30hours), diff --git a/packages/hurl/src/runner/filter/decode.rs b/packages/hurl/src/runner/filter/decode.rs index a2107f85521..105a5b7886c 100644 --- a/packages/hurl/src/runner/filter/decode.rs +++ b/packages/hurl/src/runner/filter/decode.rs @@ -58,7 +58,7 @@ pub fn eval_decode( #[cfg(test)] pub mod tests { use crate::runner::filter::eval::eval_filter; - use hurl_core::ast::{Filter, FilterValue, SourceInfo}; + use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo}; use super::*; @@ -66,7 +66,7 @@ pub mod tests { pub fn eval_filter_url_decode() { let variables = HashMap::new(); let filter = Filter { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: FilterValue::UrlDecode, }; assert_eq!( diff --git a/packages/hurl/src/runner/filter/eval.rs b/packages/hurl/src/runner/filter/eval.rs index 5232a5856ed..b929671eecb 100644 --- a/packages/hurl/src/runner/filter/eval.rs +++ b/packages/hurl/src/runner/filter/eval.rs @@ -119,7 +119,7 @@ pub fn eval_filter( pub mod tests { use crate::runner::filter::eval::eval_filters; use crate::runner::{Number, Value}; - use hurl_core::ast::{Filter, FilterValue, SourceInfo}; + use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo}; use std::collections::HashMap; #[test] @@ -129,7 +129,7 @@ pub mod tests { assert_eq!( eval_filters( &vec![Filter { - source_info: SourceInfo::new(1, 1, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 6)), value: FilterValue::Count, }], &Value::List(vec![ diff --git a/packages/hurl/src/runner/filter/format.rs b/packages/hurl/src/runner/filter/format.rs index 20601bcdf36..91225b5a0f7 100644 --- a/packages/hurl/src/runner/filter/format.rs +++ b/packages/hurl/src/runner/filter/format.rs @@ -46,7 +46,7 @@ pub fn eval_format( #[cfg(test)] pub mod tests { use crate::runner::filter::eval::eval_filter; - use hurl_core::ast::{Filter, FilterValue, SourceInfo}; + use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo}; use super::*; @@ -54,7 +54,7 @@ pub mod tests { pub fn eval_filter_url_decode() { let variables = HashMap::new(); let filter = Filter { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: FilterValue::UrlDecode, }; assert_eq!( diff --git a/packages/hurl/src/runner/filter/html_escape.rs b/packages/hurl/src/runner/filter/html_escape.rs index 6850e79355c..6bcec36975e 100644 --- a/packages/hurl/src/runner/filter/html_escape.rs +++ b/packages/hurl/src/runner/filter/html_escape.rs @@ -42,14 +42,14 @@ pub fn eval_html_escape( pub mod tests { use crate::runner::filter::eval::eval_filter; use crate::runner::Value; - use hurl_core::ast::{Filter, FilterValue, SourceInfo}; + use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo}; use std::collections::HashMap; #[test] pub fn eval_filter_html_escape() { let variables = HashMap::new(); let filter = Filter { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), value: FilterValue::HtmlEscape, }; diff --git a/packages/hurl/src/runner/filter/html_unescape.rs b/packages/hurl/src/runner/filter/html_unescape.rs index 52f92a34af5..7f38a5f32b4 100644 --- a/packages/hurl/src/runner/filter/html_unescape.rs +++ b/packages/hurl/src/runner/filter/html_unescape.rs @@ -42,14 +42,14 @@ pub fn eval_html_unescape( pub mod tests { use crate::runner::filter::eval::eval_filter; use crate::runner::Value; - use hurl_core::ast::{Filter, FilterValue, SourceInfo}; + use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo}; use std::collections::HashMap; #[test] pub fn eval_filter_html_unescape() { let variables = HashMap::new(); let filter = Filter { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), value: FilterValue::HtmlUnescape, }; diff --git a/packages/hurl/src/runner/filter/jsonpath.rs b/packages/hurl/src/runner/filter/jsonpath.rs index 28a910ece4b..7c809840951 100644 --- a/packages/hurl/src/runner/filter/jsonpath.rs +++ b/packages/hurl/src/runner/filter/jsonpath.rs @@ -77,7 +77,9 @@ pub fn eval_jsonpath_string( #[cfg(test)] pub mod tests { - use hurl_core::ast::{Filter, FilterValue, SourceInfo, Template, TemplateElement, Whitespace}; + use hurl_core::ast::{ + Filter, FilterValue, Pos, SourceInfo, Template, TemplateElement, Whitespace, + }; use std::collections::HashMap; use crate::runner::filter::eval::eval_filter; @@ -88,7 +90,7 @@ pub mod tests { let variables = HashMap::new(); let filter = Filter { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), value: FilterValue::JsonPath { expr: Template { delimiter: Some('"'), @@ -96,11 +98,11 @@ pub mod tests { value: "$.message".to_string(), encoded: "$.message".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }, }; diff --git a/packages/hurl/src/runner/filter/nth.rs b/packages/hurl/src/runner/filter/nth.rs index 109efbec2dc..6ad8648b046 100644 --- a/packages/hurl/src/runner/filter/nth.rs +++ b/packages/hurl/src/runner/filter/nth.rs @@ -48,19 +48,19 @@ pub fn eval_nth( pub mod tests { use crate::runner::filter::eval::eval_filter; use crate::runner::{Error, Number, RunnerError, Value}; - use hurl_core::ast::{Filter, FilterValue, SourceInfo, Whitespace}; + use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo, Whitespace}; use std::collections::HashMap; #[test] pub fn eval_filter_nth() { let variables = HashMap::new(); let filter = Filter { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), value: FilterValue::Nth { n: 2, space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }, }; @@ -94,7 +94,7 @@ pub mod tests { .err() .unwrap(), Error::new( - SourceInfo::new(1, 1, 1, 1), + SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), RunnerError::FilterInvalidInput("Out of bound - size is 2".to_string()), false ) diff --git a/packages/hurl/src/runner/filter/regex.rs b/packages/hurl/src/runner/filter/regex.rs index 7f982b85c3b..f94e61552a0 100644 --- a/packages/hurl/src/runner/filter/regex.rs +++ b/packages/hurl/src/runner/filter/regex.rs @@ -53,7 +53,7 @@ pub mod tests { use crate::runner::filter::eval::eval_filter; use crate::runner::{RunnerError, Value}; use hurl_core::ast::{ - Filter, FilterValue, RegexValue, SourceInfo, Template, TemplateElement, Whitespace, + Filter, FilterValue, Pos, RegexValue, SourceInfo, Template, TemplateElement, Whitespace, }; #[test] fn eval_filter_regex() { @@ -61,10 +61,10 @@ pub mod tests { let variables = HashMap::new(); let whitespace = Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; let filter = Filter { - source_info: SourceInfo::new(1, 1, 1, 20), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 20)), value: FilterValue::Regex { space0: whitespace, value: RegexValue::Template(Template { @@ -73,7 +73,7 @@ pub mod tests { value: "Hello (.*)!".to_string(), encoded: "Hello (.*)!".to_string(), }], - source_info: SourceInfo::new(1, 7, 1, 20), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 20)), }), }, }; @@ -92,7 +92,10 @@ pub mod tests { let error = eval_filter(&filter, &Value::Bool(true), &variables, false) .err() .unwrap(); - assert_eq!(error.source_info, SourceInfo::new(1, 1, 1, 20)); + assert_eq!( + error.source_info, + SourceInfo::new(Pos::new(1, 1), Pos::new(1, 20)) + ); assert_eq!( error.inner, RunnerError::FilterInvalidInput("boolean".to_string()) @@ -104,10 +107,10 @@ pub mod tests { let variables = HashMap::new(); let whitespace = Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; let filter = Filter { - source_info: SourceInfo::new(1, 1, 1, 20), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 20)), value: FilterValue::Regex { space0: whitespace, value: RegexValue::Template(Template { @@ -116,7 +119,7 @@ pub mod tests { value: "???".to_string(), encoded: "???".to_string(), }], - source_info: SourceInfo::new(1, 7, 1, 20), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 20)), }), }, }; @@ -128,7 +131,10 @@ pub mod tests { ) .err() .unwrap(); - assert_eq!(error.source_info, SourceInfo::new(1, 7, 1, 20)); + assert_eq!( + error.source_info, + SourceInfo::new(Pos::new(1, 7), Pos::new(1, 20)) + ); assert_eq!(error.inner, RunnerError::InvalidRegex); } } diff --git a/packages/hurl/src/runner/filter/replace.rs b/packages/hurl/src/runner/filter/replace.rs index 46edba3b735..9d8e51dca27 100644 --- a/packages/hurl/src/runner/filter/replace.rs +++ b/packages/hurl/src/runner/filter/replace.rs @@ -51,7 +51,7 @@ pub mod tests { use crate::runner::filter::eval::eval_filter; use crate::runner::Value; use hurl_core::ast::{ - Filter, FilterValue, RegexValue, SourceInfo, Template, TemplateElement, Whitespace, + Filter, FilterValue, Pos, RegexValue, SourceInfo, Template, TemplateElement, Whitespace, }; use std::collections::HashMap; @@ -59,7 +59,7 @@ pub mod tests { pub fn eval_filter_replace() { let variables = HashMap::new(); let filter = Filter { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), value: FilterValue::Replace { old_value: RegexValue::Template(Template { delimiter: None, @@ -67,7 +67,7 @@ pub mod tests { value: "\\s+".to_string(), encoded: ",".to_string(), }], - source_info: SourceInfo::new(1, 7, 1, 20), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 20)), }), new_value: Template { delimiter: Some('"'), @@ -75,15 +75,15 @@ pub mod tests { value: ",".to_string(), encoded: ",".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }, }; diff --git a/packages/hurl/src/runner/filter/split.rs b/packages/hurl/src/runner/filter/split.rs index c495bd74044..be7ac0da2a4 100644 --- a/packages/hurl/src/runner/filter/split.rs +++ b/packages/hurl/src/runner/filter/split.rs @@ -50,14 +50,16 @@ pub mod tests { use crate::runner::filter::eval::eval_filter; use crate::runner::Value; - use hurl_core::ast::{Filter, FilterValue, SourceInfo, Template, TemplateElement, Whitespace}; + use hurl_core::ast::{ + Filter, FilterValue, Pos, SourceInfo, Template, TemplateElement, Whitespace, + }; use std::collections::HashMap; #[test] pub fn eval_filter_split() { let variables = HashMap::new(); let filter = Filter { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), value: FilterValue::Split { sep: Template { delimiter: Some('"'), @@ -65,11 +67,11 @@ pub mod tests { value: ",".to_string(), encoded: ",".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }, }; diff --git a/packages/hurl/src/runner/filter/to_date.rs b/packages/hurl/src/runner/filter/to_date.rs index 8f00f0ab789..5149b020b1f 100644 --- a/packages/hurl/src/runner/filter/to_date.rs +++ b/packages/hurl/src/runner/filter/to_date.rs @@ -56,7 +56,9 @@ pub mod tests { use crate::runner::filter::eval::eval_filter; use crate::runner::Value; use chrono::{DateTime, NaiveDate, Utc}; - use hurl_core::ast::{Filter, FilterValue, SourceInfo, Template, TemplateElement, Whitespace}; + use hurl_core::ast::{ + Filter, FilterValue, Pos, SourceInfo, Template, TemplateElement, Whitespace, + }; use std::collections::HashMap; #[test] @@ -64,7 +66,7 @@ pub mod tests { let variables = HashMap::new(); let filter = Filter { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), value: FilterValue::ToDate { fmt: Template { delimiter: Some('"'), @@ -72,11 +74,11 @@ pub mod tests { value: "%Y %b %d %H:%M:%S%.3f %z".to_string(), encoded: "%Y %b %d %H:%M:%S%.3f %z".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }, }; @@ -99,7 +101,7 @@ pub mod tests { ); let filter = Filter { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), value: FilterValue::ToDate { fmt: Template { delimiter: Some('"'), @@ -107,11 +109,11 @@ pub mod tests { value: "%a, %d %b %Y %H:%M:%S GMT".to_string(), encoded: "%a, %d %b %Y %H:%M:%S GMT".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }, }; diff --git a/packages/hurl/src/runner/filter/to_int.rs b/packages/hurl/src/runner/filter/to_int.rs index a16b4cedc11..a08bc66816c 100644 --- a/packages/hurl/src/runner/filter/to_int.rs +++ b/packages/hurl/src/runner/filter/to_int.rs @@ -47,14 +47,14 @@ pub mod tests { use crate::runner::filter::eval::eval_filter; use crate::runner::{Number, RunnerError, Value}; - use hurl_core::ast::{Filter, FilterValue, SourceInfo}; + use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo}; use std::collections::HashMap; #[test] pub fn eval_filter_to_int() { let variables = HashMap::new(); let filter = Filter { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), value: FilterValue::ToInt, }; assert_eq!( @@ -96,7 +96,7 @@ pub mod tests { pub fn eval_filter_to_int_error() { let variables = HashMap::new(); let filter = Filter { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), value: FilterValue::ToInt, }; let err = eval_filter( diff --git a/packages/hurl/src/runner/filter/url_encode.rs b/packages/hurl/src/runner/filter/url_encode.rs index 54a1c4979cb..d3ebb9bc34b 100644 --- a/packages/hurl/src/runner/filter/url_encode.rs +++ b/packages/hurl/src/runner/filter/url_encode.rs @@ -51,14 +51,14 @@ pub mod tests { use crate::runner::filter::eval::eval_filter; use crate::runner::Value; - use hurl_core::ast::{Filter, FilterValue, SourceInfo}; + use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo}; use std::collections::HashMap; #[test] pub fn eval_filter_url_encode() { let variables = HashMap::new(); let filter = Filter { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: FilterValue::UrlEncode, }; assert_eq!( diff --git a/packages/hurl/src/runner/json.rs b/packages/hurl/src/runner/json.rs index 19bdb41bc2d..140836a3bc7 100644 --- a/packages/hurl/src/runner/json.rs +++ b/packages/hurl/src/runner/json.rs @@ -193,15 +193,15 @@ mod tests { TemplateElement::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 15, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 15), Pos::new(1, 15)), }, variable: Variable { name: "name".to_string(), - source_info: SourceInfo::new(1, 15, 1, 19), + source_info: SourceInfo::new(Pos::new(1, 15), Pos::new(1, 19)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 19, 1, 19), + source_info: SourceInfo::new(Pos::new(1, 19), Pos::new(1, 19)), }, }), TemplateElement::String { @@ -209,7 +209,7 @@ mod tests { encoded: "!".to_string(), }, ], - source_info: SourceInfo::new(1, 2, 1, 22), + source_info: SourceInfo::new(Pos::new(1, 2), Pos::new(1, 22)), }) } @@ -224,7 +224,7 @@ mod tests { value: "firstName".to_string(), encoded: "firstName".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, space1: String::new(), space2: " ".to_string(), @@ -234,7 +234,7 @@ mod tests { value: "John".to_string(), encoded: "John".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }), space3: "\n".to_string(), }], @@ -269,7 +269,10 @@ mod tests { let error = eval_json_value(&json_hello_world_value(), &variables, true) .err() .unwrap(); - assert_eq!(error.source_info, SourceInfo::new(1, 15, 1, 19)); + assert_eq!( + error.source_info, + SourceInfo::new(Pos::new(1, 15), Pos::new(1, 19)) + ); assert_eq!( error.inner, RunnerError::TemplateVariableNotDefined { @@ -330,7 +333,7 @@ mod tests { encoded: "Hi".to_string(), value: "Hi".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; assert_eq!( eval_json_value( @@ -392,7 +395,7 @@ mod tests { value: "\n".to_string(), encoded: "\\n".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }), &variables, true @@ -413,7 +416,7 @@ mod tests { value: "\n".to_string(), encoded: "\\n".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, &variables, ) @@ -436,12 +439,12 @@ mod tests { space0: whitespace(), variable: Variable { name: "quote".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace(), }), ], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, &variables, ) @@ -453,7 +456,7 @@ mod tests { fn whitespace() -> Whitespace { Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } diff --git a/packages/hurl/src/runner/multiline.rs b/packages/hurl/src/runner/multiline.rs index f73af2753b2..8ac60b485ab 100644 --- a/packages/hurl/src/runner/multiline.rs +++ b/packages/hurl/src/runner/multiline.rs @@ -60,7 +60,7 @@ mod tests { use std::collections::HashMap; use hurl_core::ast::{ - GraphQl, GraphQlVariables, JsonObjectElement, JsonValue, MultilineString, SourceInfo, + GraphQl, GraphQlVariables, JsonObjectElement, JsonValue, MultilineString, Pos, SourceInfo, Template, TemplateElement, Whitespace, }; @@ -69,19 +69,19 @@ mod tests { fn whitespace() -> Whitespace { Whitespace { value: String::from(" "), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } fn newline() -> Whitespace { Whitespace { value: String::from("\n"), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } fn empty_source_info() -> SourceInfo { - SourceInfo::new(0, 0, 0, 0) + SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)) } #[test] diff --git a/packages/hurl/src/runner/multipart.rs b/packages/hurl/src/runner/multipart.rs index 6a2e4954402..0e2b878c96b 100644 --- a/packages/hurl/src/runner/multipart.rs +++ b/packages/hurl/src/runner/multipart.rs @@ -94,7 +94,7 @@ mod tests { pub fn whitespace() -> Whitespace { Whitespace { value: String::from(" "), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } @@ -119,7 +119,7 @@ mod tests { value: "upload1".to_string(), encoded: "upload1".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace(), space2: whitespace(), @@ -127,7 +127,7 @@ mod tests { space0: whitespace(), filename: Filename { value: "hello.txt".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace(), space2: whitespace(), @@ -157,7 +157,7 @@ mod tests { space0: whitespace(), filename: Filename { value: "hello.txt".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace(), space2: whitespace(), @@ -171,7 +171,7 @@ mod tests { space0: whitespace(), filename: Filename { value: "hello.html".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace(), space2: whitespace(), @@ -185,7 +185,7 @@ mod tests { space0: whitespace(), filename: Filename { value: "hello.txt".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace(), space2: whitespace(), @@ -199,7 +199,7 @@ mod tests { space0: whitespace(), filename: Filename { value: "hello".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace(), space2: whitespace(), diff --git a/packages/hurl/src/runner/options.rs b/packages/hurl/src/runner/options.rs index 5c3ccd9cdea..37e84cc9ab7 100644 --- a/packages/hurl/src/runner/options.rs +++ b/packages/hurl/src/runner/options.rs @@ -353,7 +353,7 @@ fn eval_variable_value( #[cfg(test)] mod tests { - use hurl_core::ast::{Expr, SourceInfo, Variable, Whitespace}; + use hurl_core::ast::{Expr, Pos, SourceInfo, Variable, Whitespace}; use super::*; use crate::runner::RunnerError; @@ -363,15 +363,15 @@ mod tests { BooleanOption::Expression(Expr { space0: Whitespace { value: "".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, variable: Variable { name: "verbose".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: Whitespace { value: "".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }) } @@ -381,15 +381,15 @@ mod tests { NaturalOption::Expression(Expr { space0: Whitespace { value: "".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, variable: Variable { name: "retry".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: Whitespace { value: "".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }) } diff --git a/packages/hurl/src/runner/predicate.rs b/packages/hurl/src/runner/predicate.rs index 925220076f4..04b7d7ff7a6 100644 --- a/packages/hurl/src/runner/predicate.rs +++ b/packages/hurl/src/runner/predicate.rs @@ -53,11 +53,10 @@ pub fn eval_predicate( ) -> PredicateResult { let assert_result = eval_predicate_func(&predicate.predicate_func, variables, value.as_ref())?; + // Column error is set to 0 to disable the error display of "^----" let source_info = SourceInfo::new( - predicate.space0.source_info.start.line, - 0, - predicate.space0.source_info.start.line, - 0, + Pos::new(predicate.space0.source_info.start.line, 0), + Pos::new(predicate.space0.source_info.start.line, 0), ); if assert_result.type_mismatch { @@ -869,7 +868,7 @@ mod tests { fn whitespace() -> Whitespace { Whitespace { value: String::from(" "), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } @@ -889,7 +888,7 @@ mod tests { let variables = HashMap::new(); let whitespace = Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 1, 0, 0), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(0, 0)), }; let predicate = Predicate { @@ -901,7 +900,7 @@ mod tests { value: PredicateValue::Number(hurl_core::ast::Number::Integer(10)), operator: false, }, - source_info: SourceInfo::new(1, 11, 1, 12), + source_info: SourceInfo::new(Pos::new(1, 11), Pos::new(1, 12)), }, }; @@ -921,7 +920,10 @@ mod tests { type_mismatch: false, } ); - assert_eq!(error.source_info, SourceInfo::new(1, 0, 1, 0)); + assert_eq!( + error.source_info, + SourceInfo::new(Pos::new(1, 0), Pos::new(1, 0)) + ); assert!(eval_predicate( &predicate, @@ -1009,7 +1011,7 @@ mod tests { // value: Some(Unit) | None let pred_func = PredicateFunc { value: PredicateFuncValue::Exist, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; let value = Some(&Value::Unit); @@ -1134,18 +1136,18 @@ mod tests { elements: vec![TemplateElement::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 11, 1, 11), + source_info: SourceInfo::new(Pos::new(1, 11), Pos::new(1, 11)), }, variable: Variable { name: String::from("base_url"), - source_info: SourceInfo::new(1, 11, 1, 19), + source_info: SourceInfo::new(Pos::new(1, 11), Pos::new(1, 19)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 19, 1, 19), + source_info: SourceInfo::new(Pos::new(1, 19), Pos::new(1, 19)), }, })], - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }; // predicate: `== "{{base_url}}"` @@ -1160,7 +1162,10 @@ mod tests { name: String::from("base_url") } ); - assert_eq!(error.source_info, SourceInfo::new(1, 11, 1, 19)); + assert_eq!( + error.source_info, + SourceInfo::new(Pos::new(1, 11), Pos::new(1, 19)) + ); // predicate: `== "{{base_url}}"` // value: "http://localhost:8000" @@ -1307,7 +1312,7 @@ mod tests { not: true, space0: whitespace(), predicate_func: PredicateFunc { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: PredicateFuncValue::Equal { space0: whitespace(), operator: false, @@ -1331,7 +1336,7 @@ mod tests { not: true, space0: whitespace(), predicate_func: PredicateFunc { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: PredicateFuncValue::StartWith { space0: whitespace(), value: PredicateValue::String(Template { @@ -1340,7 +1345,7 @@ mod tests { value: "toto".to_string(), encoded: "toto".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }), }, }, @@ -1396,7 +1401,7 @@ mod tests { not: false, space0: whitespace(), predicate_func: PredicateFunc { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: PredicateFuncValue::Equal { space0: whitespace(), value: PredicateValue::Null, @@ -1420,7 +1425,7 @@ mod tests { not: true, space0: whitespace(), predicate_func: PredicateFunc { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: PredicateFuncValue::Equal { space0: whitespace(), operator: false, @@ -1443,7 +1448,7 @@ mod tests { inner: regex::Regex::new(r#"a{3}"#).unwrap(), }); let value = Value::String("aa".to_string()); - let source_info = SourceInfo::new(0, 0, 0, 0); + let source_info = SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)); let assert_result = eval_match(&expected, source_info, &variables, &value).unwrap(); assert!(!assert_result.success); assert!(!assert_result.type_mismatch); diff --git a/packages/hurl/src/runner/query.rs b/packages/hurl/src/runner/query.rs index 6cdb8c893d4..0a599f41ae6 100644 --- a/packages/hurl/src/runner/query.rs +++ b/packages/hurl/src/runner/query.rs @@ -322,10 +322,10 @@ pub mod tests { // xpath ??? let whitespace = Whitespace { value: String::from(" "), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; Query { - source_info: SourceInfo::new(1, 1, 1, 13), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 13)), value: QueryValue::Xpath { space0: whitespace, expr: Template { @@ -334,7 +334,7 @@ pub mod tests { value: "???".to_string(), encoded: "???".to_string(), }], - source_info: SourceInfo::new(1, 7, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 10)), }, }, } @@ -343,10 +343,10 @@ pub mod tests { pub fn xpath_count_user_query() -> Query { let whitespace = Whitespace { value: String::from(" "), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; Query { - source_info: SourceInfo::new(1, 1, 1, 13), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 13)), value: QueryValue::Xpath { space0: whitespace, expr: Template { @@ -355,7 +355,7 @@ pub mod tests { value: "count(//user)".to_string(), encoded: "count(//user)".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }, } @@ -364,10 +364,10 @@ pub mod tests { pub fn xpath_users() -> Query { let whitespace = Whitespace { value: String::from(" "), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; Query { - source_info: SourceInfo::new(1, 1, 1, 13), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 13)), value: QueryValue::Xpath { space0: whitespace, expr: Template { @@ -376,7 +376,7 @@ pub mod tests { value: "//user".to_string(), encoded: "/user".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }, } @@ -385,11 +385,11 @@ pub mod tests { pub fn jsonpath_success() -> Query { // jsonpath $.success Query { - source_info: SourceInfo::new(1, 1, 1, 19), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 19)), value: QueryValue::Jsonpath { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 9, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 9), Pos::new(1, 10)), }, expr: Template { elements: vec![TemplateElement::String { @@ -397,7 +397,7 @@ pub mod tests { encoded: String::from("$.success"), }], delimiter: Some('"'), - source_info: SourceInfo::new(1, 10, 1, 19), + source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 19)), }, }, } @@ -406,11 +406,11 @@ pub mod tests { pub fn jsonpath_errors() -> Query { // jsonpath $.errors Query { - source_info: SourceInfo::new(1, 1, 1, 19), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 19)), value: QueryValue::Jsonpath { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 9, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 9), Pos::new(1, 10)), }, expr: Template { elements: vec![TemplateElement::String { @@ -418,7 +418,7 @@ pub mod tests { encoded: String::from("$.errors"), }], delimiter: Some('"'), - source_info: SourceInfo::new(1, 10, 1, 18), + source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 18)), }, }, } @@ -427,11 +427,11 @@ pub mod tests { pub fn jsonpath_duration() -> Query { // jsonpath $.errors Query { - source_info: SourceInfo::new(1, 1, 1, 19), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 19)), value: QueryValue::Jsonpath { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 9, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 9), Pos::new(1, 10)), }, expr: Template { elements: vec![TemplateElement::String { @@ -439,7 +439,7 @@ pub mod tests { encoded: String::from("$.duration"), }], delimiter: Some('"'), - source_info: SourceInfo::new(1, 10, 1, 18), + source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 18)), }, }, } @@ -448,11 +448,11 @@ pub mod tests { pub fn regex_name() -> Query { // regex "Hello ([a-zA-Z]+)!" Query { - source_info: SourceInfo::new(1, 1, 1, 26), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 26)), value: QueryValue::Regex { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 6, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 7)), }, value: RegexValue::Template(Template { delimiter: Some('"'), @@ -460,7 +460,7 @@ pub mod tests { value: "Hello ([a-zA-Z]+)!".to_string(), encoded: "Hello ([a-zA-Z]+)!".to_string(), }], - source_info: SourceInfo::new(1, 7, 1, 26), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 26)), }), }, } @@ -469,11 +469,11 @@ pub mod tests { pub fn regex_invalid() -> Query { // regex ???" Query { - source_info: SourceInfo::new(1, 1, 1, 26), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 26)), value: QueryValue::Regex { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 6, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 7)), }, value: RegexValue::Template(Template { delimiter: Some('"'), @@ -481,7 +481,7 @@ pub mod tests { value: "???".to_string(), encoded: "???".to_string(), }], - source_info: SourceInfo::new(1, 7, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 10)), }), }, } @@ -515,7 +515,7 @@ pub mod tests { assert_eq!( eval_query( &Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: QueryValue::Status, }, &variables, @@ -532,11 +532,11 @@ pub mod tests { let variables = HashMap::new(); // header Custom let query_header = Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: QueryValue::Header { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 7, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 8)), }, name: Template { delimiter: Some('"'), @@ -544,7 +544,7 @@ pub mod tests { value: "Custom".to_string(), encoded: "Custom".to_string(), }], - source_info: SourceInfo::new(2, 8, 2, 14), + source_info: SourceInfo::new(Pos::new(2, 8), Pos::new(2, 14)), }, }, }; @@ -562,11 +562,11 @@ pub mod tests { // header Content-Type let variables = HashMap::new(); let query_header = Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: QueryValue::Header { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 7, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 8)), }, name: Template { delimiter: Some('"'), @@ -574,7 +574,7 @@ pub mod tests { value: "Content-Type".to_string(), encoded: "Content-Type".to_string(), }], - source_info: SourceInfo::new(1, 8, 1, 16), + source_info: SourceInfo::new(Pos::new(1, 8), Pos::new(1, 16)), }, }, }; @@ -591,7 +591,7 @@ pub mod tests { let variables = HashMap::new(); let space = Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; let response = http::Response { headers: vec![ @@ -602,7 +602,7 @@ pub mod tests { // cookie "LSID" let query = Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: QueryValue::Cookie { space0: space.clone(), expr: CookiePath { @@ -612,7 +612,7 @@ pub mod tests { value: "LSID".to_string(), encoded: "LSID".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, attribute: None, }, @@ -625,7 +625,7 @@ pub mod tests { // cookie "LSID[Path]" let query = Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: QueryValue::Cookie { space0: space.clone(), expr: CookiePath { @@ -635,7 +635,7 @@ pub mod tests { value: "LSID".to_string(), encoded: "LSID".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, attribute: Some(CookieAttribute { space0: space.clone(), @@ -652,7 +652,7 @@ pub mod tests { // cookie "LSID[Secure]" let query = Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: QueryValue::Cookie { space0: space.clone(), expr: CookiePath { @@ -662,7 +662,7 @@ pub mod tests { value: "LSID".to_string(), encoded: "LSID".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, attribute: Some(CookieAttribute { space0: space.clone(), @@ -679,7 +679,7 @@ pub mod tests { // cookie "LSID[Domain]" let query = Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: QueryValue::Cookie { space0: space.clone(), expr: CookiePath { @@ -689,7 +689,7 @@ pub mod tests { value: "LSID".to_string(), encoded: "LSID".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, attribute: Some(CookieAttribute { space0: space.clone(), @@ -790,7 +790,7 @@ pub mod tests { assert_eq!( eval_query( &Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: QueryValue::Body, }, &variables, @@ -802,7 +802,7 @@ pub mod tests { ); let error = eval_query( &Query { - source_info: SourceInfo::new(1, 1, 1, 2), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 2)), value: QueryValue::Body, }, &variables, @@ -810,7 +810,10 @@ pub mod tests { ) .err() .unwrap(); - assert_eq!(error.source_info, SourceInfo::new(1, 1, 1, 2)); + assert_eq!( + error.source_info, + SourceInfo::new(Pos::new(1, 1), Pos::new(1, 2)) + ); assert_eq!( error.inner, RunnerError::InvalidDecoding { @@ -843,11 +846,11 @@ pub mod tests { let variables = HashMap::new(); // xpath ^^^ let query = Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: QueryValue::Xpath { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 6, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 7)), }, expr: Template { delimiter: Some('"'), @@ -855,7 +858,7 @@ pub mod tests { value: "^^^".to_string(), encoded: "^^^".to_string(), }], - source_info: SourceInfo::new(1, 7, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 10)), }, }, }; @@ -897,10 +900,10 @@ pub mod tests { // $x("normalize-space(/html/head/meta/@charset)") let whitespace = Whitespace { value: String::from(" "), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; Query { - source_info: SourceInfo::new(1, 1, 1, 13), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 13)), value: QueryValue::Xpath { space0: whitespace, expr: Template { @@ -909,7 +912,7 @@ pub mod tests { value: "normalize-space(/html/head/meta/@charset)".to_string(), encoded: "normalize-space(/html/head/meta/@charset)".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }, } @@ -936,11 +939,11 @@ pub mod tests { // jsonpath xxx let jsonpath_query = Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: QueryValue::Jsonpath { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 9, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 9), Pos::new(1, 10)), }, expr: Template { elements: vec![TemplateElement::String { @@ -948,7 +951,7 @@ pub mod tests { encoded: String::from("xxx"), }], delimiter: Some('"'), - source_info: SourceInfo::new(1, 10, 1, 13), + source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 13)), }, }, }; @@ -1038,7 +1041,10 @@ pub mod tests { let error = eval_query(®ex_invalid(), &variables, &http::hello_http_response()) .err() .unwrap(); - assert_eq!(error.source_info, SourceInfo::new(1, 7, 1, 10)); + assert_eq!( + error.source_info, + SourceInfo::new(Pos::new(1, 7), Pos::new(1, 10)) + ); assert_eq!(error.inner, RunnerError::InvalidRegex); } @@ -1048,7 +1054,7 @@ pub mod tests { assert_eq!( eval_query( &Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: QueryValue::Bytes, }, &variables, @@ -1066,7 +1072,7 @@ pub mod tests { assert_eq!( eval_query( &Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: QueryValue::Sha256 {}, }, &variables, diff --git a/packages/hurl/src/runner/request.rs b/packages/hurl/src/runner/request.rs index eaa6f9fe0c6..03994596abf 100644 --- a/packages/hurl/src/runner/request.rs +++ b/packages/hurl/src/runner/request.rs @@ -175,7 +175,7 @@ mod tests { fn whitespace() -> Whitespace { Whitespace { value: String::from(" "), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } @@ -196,7 +196,7 @@ mod tests { space0: whitespace(), variable: Variable { name: String::from("base_url"), - source_info: SourceInfo::new(1, 7, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 15)), }, space1: whitespace(), }), @@ -206,13 +206,13 @@ mod tests { }, ], delimiter: None, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, line_terminator0: line_terminator, headers: vec![], sections: vec![], body: None, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } @@ -250,7 +250,7 @@ mod tests { encoded: String::from("http://localhost:8000/querystring-params"), }], delimiter: None, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, line_terminator0: line_terminator.clone(), headers: vec![], @@ -266,7 +266,7 @@ mod tests { value: "param1".to_string(), encoded: "param1".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, Template { delimiter: None, @@ -274,11 +274,11 @@ mod tests { space0: whitespace(), variable: Variable { name: String::from("param1"), - source_info: SourceInfo::new(1, 7, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 15)), }, space1: whitespace(), })], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, ), simple_key_value( @@ -288,7 +288,7 @@ mod tests { value: "param2".to_string(), encoded: "param2".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, Template { delimiter: None, @@ -296,14 +296,14 @@ mod tests { value: "a b".to_string(), encoded: "a b".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, ), ]), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }], body: None, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } @@ -313,7 +313,10 @@ mod tests { let error = eval_request(&hello_request(), &variables, &ContextDir::default()) .err() .unwrap(); - assert_eq!(error.source_info, SourceInfo::new(1, 7, 1, 15)); + assert_eq!( + error.source_info, + SourceInfo::new(Pos::new(1, 7), Pos::new(1, 15)) + ); assert_eq!( error.inner, RunnerError::TemplateVariableNotDefined { @@ -360,7 +363,7 @@ mod tests { space0: whitespace(), comment: Some(Comment { value: "@cookie_storage_clear".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }), newline: whitespace(), }], @@ -373,13 +376,13 @@ mod tests { encoded: String::from("http://localhost"), },], delimiter: None, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, line_terminator0: line_terminator, headers: vec![], sections: vec![], body: None, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), })); } @@ -401,7 +404,7 @@ mod tests { value: "@cookie_storage_set: localhost\tFALSE\t/\tFALSE\t0\tcookie1\tvalueA" .to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }), newline: whitespace(), }], @@ -414,13 +417,13 @@ mod tests { encoded: String::from("http://localhost"), },], delimiter: None, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, line_terminator0: line_terminator, headers: vec![], sections: vec![], body: None, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }) ); } diff --git a/packages/hurl/src/runner/response.rs b/packages/hurl/src/runner/response.rs index 82404465aaf..3629c9b3a3b 100644 --- a/packages/hurl/src/runner/response.rs +++ b/packages/hurl/src/runner/response.rs @@ -344,7 +344,7 @@ mod tests { pub fn user_response() -> Response { let whitespace = Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }; let line_terminator = LineTerminator { space0: whitespace.clone(), @@ -356,12 +356,12 @@ mod tests { line_terminators: vec![], version: Version { value: VersionValue::Version1, - source_info: SourceInfo::new(2, 1, 2, 9), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(2, 9)), }, space0: whitespace.clone(), status: Status { value: StatusValue::Specific(200), - source_info: SourceInfo::new(2, 10, 2, 13), + source_info: SourceInfo::new(Pos::new(2, 10), Pos::new(2, 13)), }, space1: whitespace.clone(), line_terminator0: line_terminator.clone(), @@ -372,18 +372,18 @@ mod tests { space0: whitespace.clone(), line_terminator0: line_terminator.clone(), value: SectionValue::Asserts(vec![assert::tests::assert_count_user()]), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, Section { line_terminators: vec![], space0: whitespace, line_terminator0: line_terminator, value: SectionValue::Captures(vec![capture::tests::user_count_capture()]), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, ], body: None, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } @@ -400,9 +400,9 @@ mod tests { ), vec![AssertResult::Explicit { actual: Ok(Some(Value::Number(Number::Integer(2)))), - source_info: SourceInfo::new(1, 22, 1, 24), + source_info: SourceInfo::new(Pos::new(1, 22), Pos::new(1, 24)), predicate_result: Some(Err(Error::new( - SourceInfo::new(1, 0, 1, 0), + SourceInfo::new(Pos::new(1, 0), Pos::new(1, 0)), RunnerError::AssertFailure { actual: "int <2>".to_string(), expected: "int <3>".to_string(), @@ -422,12 +422,12 @@ mod tests { AssertResult::Version { actual: String::from("HTTP/1.0"), expected: String::from("HTTP/1.0"), - source_info: SourceInfo::new(2, 1, 2, 9), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(2, 9)), }, AssertResult::Status { actual: 200, expected: 200, - source_info: SourceInfo::new(2, 10, 2, 13), + source_info: SourceInfo::new(Pos::new(2, 10), Pos::new(2, 13)), }, ] ); diff --git a/packages/hurl/src/runner/template.rs b/packages/hurl/src/runner/template.rs index ff93a17e0e1..44cb1bc1882 100644 --- a/packages/hurl/src/runner/template.rs +++ b/packages/hurl/src/runner/template.rs @@ -96,15 +96,15 @@ mod tests { TemplateElement::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 3, 1, 3), + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 3)), }, variable: Variable { name: "name".to_string(), - source_info: SourceInfo::new(1, 3, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 7)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 7, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 7)), }, }) } @@ -145,7 +145,10 @@ mod tests { let error = eval_template_element(&template_element_expression(), &variables) .err() .unwrap(); - assert_eq!(error.source_info, SourceInfo::new(1, 3, 1, 7)); + assert_eq!( + error.source_info, + SourceInfo::new(Pos::new(1, 3), Pos::new(1, 7)) + ); assert_eq!( error.inner, RunnerError::UnrenderableVariable { @@ -162,15 +165,15 @@ mod tests { let expr = Expr { space0: Whitespace { value: "".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, variable: Variable { name: "status".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: Whitespace { value: "".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }; assert_eq!( diff --git a/packages/hurl/src/util/logger.rs b/packages/hurl/src/util/logger.rs index a42d6ea75a8..db91eb4f41d 100644 --- a/packages/hurl/src/util/logger.rs +++ b/packages/hurl/src/util/logger.rs @@ -679,7 +679,7 @@ fn get_lines(text: &str) -> Vec<&str> { #[cfg(test)] pub mod tests { - use hurl_core::ast::SourceInfo; + use hurl_core::ast::{Pos, SourceInfo}; use super::*; use crate::runner; @@ -701,7 +701,11 @@ HTTP/1.0 200 let inner = runner::RunnerError::AssertStatus { actual: "404".to_string(), }; - let error = runner::Error::new(SourceInfo::new(2, 10, 2, 13), inner, true); + let error = runner::Error::new( + SourceInfo::new(Pos::new(2, 10), Pos::new(2, 13)), + inner, + true, + ); assert_eq!( error_string(filename, content, &error, false), r#"Assert status code @@ -722,7 +726,7 @@ xpath "strong(//head/title)" == "Hello" "#; let filename = "test.hurl"; let error = runner::Error::new( - SourceInfo::new(4, 7, 4, 29), + SourceInfo::new(Pos::new(4, 7), Pos::new(4, 29)), runner::RunnerError::QueryInvalidXpathEval, true, ); @@ -746,7 +750,7 @@ jsonpath "$.count" >= 5 "#; let filename = "test.hurl"; let error = runner::Error { - source_info: SourceInfo::new(4, 0, 4, 0), + source_info: SourceInfo::new(Pos::new(4, 0), Pos::new(4, 0)), inner: runner::RunnerError::AssertFailure { actual: "int <2>".to_string(), expected: "greater than int <5>".to_string(), @@ -778,7 +782,8 @@ HTTP/1.0 200 actual: "

Hello

\n\n".to_string(), expected: "

Hello

\n".to_string(), }; - let error = runner::Error::new(SourceInfo::new(3, 4, 4, 1), inner, true); + let error = + runner::Error::new(SourceInfo::new(Pos::new(3, 4), Pos::new(4, 1)), inner, true); assert_eq!( error_string(filename, content, &error, false), r#"Assert body value diff --git a/packages/hurl_core/src/ast/core.rs b/packages/hurl_core/src/ast/core.rs index 1a5370f9960..45f05c28a56 100644 --- a/packages/hurl_core/src/ast/core.rs +++ b/packages/hurl_core/src/ast/core.rs @@ -665,6 +665,12 @@ pub struct Pos { pub column: usize, } +impl Pos { + pub fn new(line: usize, column: usize) -> Pos { + Pos { line, column } + } +} + #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct SourceInfo { pub start: Pos, @@ -672,22 +678,8 @@ pub struct SourceInfo { } impl SourceInfo { - pub fn new( - start_line: usize, - start_col: usize, - end_line: usize, - end_column: usize, - ) -> SourceInfo { - SourceInfo { - start: Pos { - line: start_line, - column: start_col, - }, - end: Pos { - line: end_line, - column: end_column, - }, - } + pub fn new(start: Pos, end: Pos) -> SourceInfo { + SourceInfo { start, end } } } diff --git a/packages/hurl_core/src/ast/display.rs b/packages/hurl_core/src/ast/display.rs index aa491563188..59c9a1c297a 100644 --- a/packages/hurl_core/src/ast/display.rs +++ b/packages/hurl_core/src/ast/display.rs @@ -294,7 +294,7 @@ mod tests { fn whitespace() -> Whitespace { Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } @@ -303,7 +303,7 @@ mod tests { space0: whitespace(), variable: Variable { name: "name".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace(), } @@ -323,7 +323,7 @@ mod tests { encoded: "!".to_string(), }, ], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } @@ -378,7 +378,7 @@ mod tests { value: "LSID".to_string(), encoded: "unused".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, attribute: Some(CookieAttribute { space0: whitespace(), diff --git a/packages/hurl_core/src/ast/json.rs b/packages/hurl_core/src/ast/json.rs index 949b1b478a1..03d622f7ec0 100644 --- a/packages/hurl_core/src/ast/json.rs +++ b/packages/hurl_core/src/ast/json.rs @@ -216,7 +216,7 @@ impl TemplateElement { #[cfg(test)] mod tests { use super::*; - use crate::ast::{SourceInfo, TemplateElement, Variable, Whitespace}; + use crate::ast::{Pos, SourceInfo, TemplateElement, Variable, Whitespace}; #[test] fn test_to_string() { @@ -225,15 +225,15 @@ mod tests { Value::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, variable: Variable { name: "x".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }) .to_string() @@ -247,7 +247,7 @@ mod tests { value: "hello".to_string(), encoded: "hello".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }) .to_string() ); @@ -304,7 +304,7 @@ mod tests { value: "id".to_string(), encoded: "id".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, space1: String::new(), space2: " ".to_string(), @@ -323,15 +323,15 @@ mod tests { TemplateElement::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, variable: Variable { name: "name".to_string(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, }) .encoded(), @@ -343,18 +343,18 @@ mod tests { elements: vec![TemplateElement::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, variable: Variable { name: "name".to_string(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, })], - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), } .encoded(), "{{name}}".to_string() diff --git a/packages/hurl_core/src/format/html.rs b/packages/hurl_core/src/format/html.rs index 8f2c1921edf..0b96f04cd3f 100644 --- a/packages/hurl_core/src/format/html.rs +++ b/packages/hurl_core/src/format/html.rs @@ -901,7 +901,7 @@ mod tests { value: String::new(), encoded: "unused".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }); let mut fmt = HtmlFormatter::new(); fmt.fmt_multiline_string(&multiline_string, false); @@ -922,7 +922,7 @@ mod tests { value: "hello".to_string(), encoded: "unused".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }); let mut fmt = HtmlFormatter::new(); fmt.fmt_multiline_string(&multiline_string, false); @@ -960,7 +960,7 @@ mod tests { value: "line1\nline2\n".to_string(), encoded: "unused".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }); let mut fmt = HtmlFormatter::new(); @@ -1025,7 +1025,7 @@ mod tests { value: "id".to_string(), encoded: "id".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: String::new(), space2: " ".to_string(), @@ -1053,7 +1053,7 @@ mod tests { value: "\n".to_string(), encoded: "\\n".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }); fmt.fmt_json_value(&value); assert_eq!( diff --git a/packages/hurl_core/src/parser/bytes.rs b/packages/hurl_core/src/parser/bytes.rs index cb9bdf9471d..3d5b959cf3e 100644 --- a/packages/hurl_core/src/parser/bytes.rs +++ b/packages/hurl_core/src/parser/bytes.rs @@ -129,7 +129,7 @@ mod tests { Bytes::Json(JsonValue::String(Template { delimiter: Some('"'), elements: vec![], - source_info: SourceInfo::new(1, 2, 1, 2), + source_info: SourceInfo::new(Pos::new(1, 2), Pos::new(1, 2)), })) ); assert_eq!(reader.state.cursor, 2); @@ -198,7 +198,7 @@ mod tests { value: "foo".to_string(), encoded: "foo".to_string() }], - source_info: SourceInfo::new(1, 1, 1, 6) + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 6)) }) ); assert_eq!(reader.state.cursor, 5); diff --git a/packages/hurl_core/src/parser/cookiepath.rs b/packages/hurl_core/src/parser/cookiepath.rs index 6b6e24755a9..ec6369b4f15 100644 --- a/packages/hurl_core/src/parser/cookiepath.rs +++ b/packages/hurl_core/src/parser/cookiepath.rs @@ -83,7 +83,7 @@ mod tests { value: "cookie1".to_string(), encoded: "cookie1".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 8)), }, attribute: None, } @@ -103,17 +103,17 @@ mod tests { value: "cookie1".to_string(), encoded: "cookie1".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 8)), }, attribute: Some(CookieAttribute { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 9, 1, 9), + source_info: SourceInfo::new(Pos::new(1, 9), Pos::new(1, 9)), }, name: CookieAttributeName::Domain("Domain".to_string()), space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 15, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 15), Pos::new(1, 15)), }, }), } @@ -132,28 +132,28 @@ mod tests { elements: vec![TemplateElement::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 3, 1, 3), + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 3)), }, variable: Variable { name: "name".to_string(), - source_info: SourceInfo::new(1, 3, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 7)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 7, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 7)), }, })], - source_info: SourceInfo::new(1, 1, 1, 9), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 9)), }, attribute: Some(CookieAttribute { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 10, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 10)), }, name: CookieAttributeName::Domain("Domain".to_string()), space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 16, 1, 16), + source_info: SourceInfo::new(Pos::new(1, 16), Pos::new(1, 16)), }, }), } diff --git a/packages/hurl_core/src/parser/expr.rs b/packages/hurl_core/src/parser/expr.rs index 05dd6595adc..68267a6be6a 100644 --- a/packages/hurl_core/src/parser/expr.rs +++ b/packages/hurl_core/src/parser/expr.rs @@ -67,12 +67,7 @@ fn variable_name(reader: &mut Reader) -> ParseResult { } Ok(Variable { name, - source_info: SourceInfo::new( - start.pos.line, - start.pos.column, - reader.state.pos.line, - reader.state.pos.column, - ), + source_info: SourceInfo::new(start.pos, reader.state.pos), }) } @@ -89,15 +84,15 @@ mod tests { Expr { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 3, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 4)), }, variable: Variable { name: String::from("name"), - source_info: SourceInfo::new(1, 4, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 8)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 8, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 8), Pos::new(1, 8)), }, } ); @@ -138,7 +133,7 @@ mod tests { variable_name(&mut reader).unwrap(), Variable { name: String::from("name"), - source_info: SourceInfo::new(1, 1, 1, 5), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 5)), } ); @@ -147,7 +142,7 @@ mod tests { variable_name(&mut reader).unwrap(), Variable { name: String::from("my-id"), - source_info: SourceInfo::new(1, 1, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 6)), } ); } diff --git a/packages/hurl_core/src/parser/filename.rs b/packages/hurl_core/src/parser/filename.rs index d7a9ee4dd8a..b800ef618d1 100644 --- a/packages/hurl_core/src/parser/filename.rs +++ b/packages/hurl_core/src/parser/filename.rs @@ -57,7 +57,7 @@ mod tests { parse(&mut reader).unwrap(), Filename { value: String::from("data/data.bin"), - source_info: SourceInfo::new(1, 1, 1, 14), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 14)), } ); assert_eq!(reader.state.cursor, 13); @@ -67,7 +67,7 @@ mod tests { parse(&mut reader).unwrap(), Filename { value: String::from("data.bin"), - source_info: SourceInfo::new(1, 1, 1, 9), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 9)), } ); assert_eq!(reader.state.cursor, 8); @@ -80,7 +80,7 @@ mod tests { parse(&mut reader).unwrap(), Filename { value: String::from("file with spaces"), - source_info: SourceInfo::new(1, 1, 1, 19), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 19)), } ); assert_eq!(reader.state.cursor, 18); diff --git a/packages/hurl_core/src/parser/filter.rs b/packages/hurl_core/src/parser/filter.rs index a5f382d497b..884e5e2e847 100644 --- a/packages/hurl_core/src/parser/filter.rs +++ b/packages/hurl_core/src/parser/filter.rs @@ -211,7 +211,7 @@ mod tests { assert_eq!( filter(&mut reader).unwrap(), Filter { - source_info: SourceInfo::new(1, 1, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 6)), value: FilterValue::Count, } ); diff --git a/packages/hurl_core/src/parser/json.rs b/packages/hurl_core/src/parser/json.rs index c94343af10f..b9eb55b8bfa 100644 --- a/packages/hurl_core/src/parser/json.rs +++ b/packages/hurl_core/src/parser/json.rs @@ -486,15 +486,15 @@ mod tests { TemplateElement::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 15, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 15), Pos::new(1, 15)), }, variable: Variable { name: "name".to_string(), - source_info: SourceInfo::new(1, 15, 1, 19), + source_info: SourceInfo::new(Pos::new(1, 15), Pos::new(1, 19)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 19, 1, 19), + source_info: SourceInfo::new(Pos::new(1, 19), Pos::new(1, 19)), }, }), TemplateElement::String { @@ -502,7 +502,7 @@ mod tests { encoded: "!".to_string(), }, ], - source_info: SourceInfo::new(1, 2, 1, 22), + source_info: SourceInfo::new(Pos::new(1, 2), Pos::new(1, 22)), }) } @@ -514,7 +514,7 @@ mod tests { JsonValue::String(Template { delimiter: Some('"'), elements: vec![], - source_info: SourceInfo::new(1, 2, 1, 2), + source_info: SourceInfo::new(Pos::new(1, 2), Pos::new(1, 2)), }) ); assert_eq!(reader.state.cursor, 2); @@ -532,7 +532,7 @@ mod tests { value: "{}".to_string(), encoded: "{}".to_string(), }], - source_info: SourceInfo::new(1, 2, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 2), Pos::new(1, 4)), }) ); assert_eq!(reader.state.cursor, 4); @@ -752,15 +752,15 @@ mod tests { JsonValue::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 3, 1, 3) + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 3)) }, variable: Variable { name: "n".to_string(), - source_info: SourceInfo::new(1, 3, 1, 4) + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 4)) }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 4, 1, 4) + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 4)) } }) ); @@ -883,7 +883,7 @@ mod tests { value: "a".to_string(), encoded: "a".to_string() }], - source_info: SourceInfo::new(2, 4, 2, 5) + source_info: SourceInfo::new(Pos::new(2, 4), Pos::new(2, 5)) }, space1: String::new(), space2: " ".to_string(), @@ -931,7 +931,7 @@ mod tests { value: "a".to_string(), encoded: "a".to_string() }], - source_info: SourceInfo::new(1, 2, 1, 3) + source_info: SourceInfo::new(Pos::new(1, 2), Pos::new(1, 3)) }, space1: String::new(), space2: " ".to_string(), diff --git a/packages/hurl_core/src/parser/key_string.rs b/packages/hurl_core/src/parser/key_string.rs index 0e5af4890aa..b5a6060e73c 100644 --- a/packages/hurl_core/src/parser/key_string.rs +++ b/packages/hurl_core/src/parser/key_string.rs @@ -171,7 +171,7 @@ mod tests { value: "aaa:".to_string(), encoded: "aaa\\:".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 6)), } ); assert_eq!(reader.state.cursor, 5); @@ -185,7 +185,7 @@ mod tests { value: "$top".to_string(), encoded: "$top".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 5), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 5)), } ); assert_eq!(reader.state.cursor, 4); @@ -199,7 +199,7 @@ mod tests { value: "key :".to_string(), encoded: "key\\u{20}\\u{3a}".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 16), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 16)), } ); assert_eq!(reader.state.cursor, 15); @@ -213,7 +213,7 @@ mod tests { value: "values[0]".to_string(), encoded: "values\\u{5b}0\\u{5d}".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 20), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 20)), } ); assert_eq!(reader.state.cursor, 19); @@ -227,7 +227,7 @@ mod tests { value: "values[0]".to_string(), encoded: "values[0]".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 10)), } ); assert_eq!(reader.state.cursor, 9); @@ -241,7 +241,7 @@ mod tests { value: "[0]".to_string(), encoded: "\\u{5b}0\\u{5d}".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 14), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 14)), } ); assert_eq!(reader.state.cursor, 13); diff --git a/packages/hurl_core/src/parser/multiline.rs b/packages/hurl_core/src/parser/multiline.rs index 77189463075..8a95468a6e1 100644 --- a/packages/hurl_core/src/parser/multiline.rs +++ b/packages/hurl_core/src/parser/multiline.rs @@ -152,12 +152,7 @@ fn whitespace(reader: &mut Reader) -> ParseResult { if c == ' ' || c == '\t' || c == '\n' || c == '\r' { Ok(Whitespace { value: c.to_string(), - source_info: SourceInfo::new( - start.pos.line, - start.pos.column, - reader.state.pos.line, - reader.state.pos.column, - ), + source_info: SourceInfo::new(start.pos, reader.state.pos), }) } else { Err(Error { @@ -177,12 +172,7 @@ fn zero_or_more_whitespaces(reader: &mut Reader) -> ParseResult { let s = v.iter().map(|x| x.value.clone()).collect(); Ok(Whitespace { value: s, - source_info: SourceInfo::new( - start.pos.line, - start.pos.column, - reader.state.pos.line, - reader.state.pos.column, - ), + source_info: SourceInfo::new(start.pos, reader.state.pos), }) } Err(e) => Err(e), @@ -294,11 +284,11 @@ mod tests { MultilineString::Text(Text { space: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 4, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 4)), }, newline: Whitespace { value: "\n".to_string(), - source_info: SourceInfo::new(1, 4, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(2, 1)), }, value: Template { delimiter: None, @@ -306,7 +296,7 @@ mod tests { value: "line1\nline2\nline3\n".to_string(), encoded: "line1\nline2\nline3\n".to_string(), }], - source_info: SourceInfo::new(2, 1, 5, 1), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(5, 1)), }, }) ); @@ -317,11 +307,11 @@ mod tests { MultilineString::Text(Text { space: Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 4, 1, 13), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 13)), }, newline: Whitespace { value: "\n".to_string(), - source_info: SourceInfo::new(1, 13, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 13), Pos::new(2, 1)), }, value: Template { delimiter: None, @@ -329,7 +319,7 @@ mod tests { value: "line1\nline2\nline3\n".to_string(), encoded: "line1\nline2\nline3\n".to_string(), }], - source_info: SourceInfo::new(2, 1, 5, 1), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(5, 1)), }, }) ); @@ -343,11 +333,11 @@ mod tests { MultilineString::Json(Text { space: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 8, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 8), Pos::new(1, 8)), }, newline: Whitespace { value: "\n".to_string(), - source_info: SourceInfo::new(1, 8, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 8), Pos::new(2, 1)), }, value: Template { delimiter: None, @@ -355,7 +345,7 @@ mod tests { value: "line1\nline2\nline3\n".to_string(), encoded: "line1\nline2\nline3\n".to_string(), }], - source_info: SourceInfo::new(2, 1, 5, 1), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(5, 1)), }, }) ); @@ -369,11 +359,11 @@ mod tests { MultilineString::GraphQl(GraphQl { space: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 11, 1, 11), + source_info: SourceInfo::new(Pos::new(1, 11), Pos::new(1, 11)), }, newline: Whitespace { value: "\n".to_string(), - source_info: SourceInfo::new(1, 11, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 11), Pos::new(2, 1)), }, value: Template { delimiter: None, @@ -381,7 +371,7 @@ mod tests { value: "line1\nline2\nline3\n".to_string(), encoded: "line1\nline2\nline3\n".to_string(), }], - source_info: SourceInfo::new(2, 1, 5, 1), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(5, 1)), }, variables: None, }) @@ -393,11 +383,11 @@ mod tests { MultilineString::GraphQl(GraphQl { space: Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 11, 1, 17), + source_info: SourceInfo::new(Pos::new(1, 11), Pos::new(1, 17)), }, newline: Whitespace { value: "\n".to_string(), - source_info: SourceInfo::new(1, 17, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 17), Pos::new(2, 1)), }, value: Template { delimiter: None, @@ -405,7 +395,7 @@ mod tests { value: "line1\nline2\nline3\n".to_string(), encoded: "line1\nline2\nline3\n".to_string(), }], - source_info: SourceInfo::new(2, 1, 5, 1), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(5, 1)), }, variables: None, }) @@ -433,7 +423,7 @@ mod tests { MultilineString::OneLineText(Template { delimiter: None, elements: vec![], - source_info: SourceInfo::new(1, 4, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 4)), }) ); @@ -443,16 +433,16 @@ mod tests { MultilineString::Text(Text { space: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 4, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 4)), }, newline: Whitespace { value: "\n".to_string(), - source_info: SourceInfo::new(1, 4, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(2, 1)), }, value: Template { delimiter: None, elements: vec![], - source_info: SourceInfo::new(2, 1, 2, 1), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(2, 1)), }, }) ); @@ -462,16 +452,16 @@ mod tests { MultilineString::Text(Text { space: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 4, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 4)), }, newline: Whitespace { value: "\r\n".to_string(), - source_info: SourceInfo::new(1, 4, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(2, 1)), }, value: Template { delimiter: None, elements: vec![], - source_info: SourceInfo::new(2, 1, 2, 1), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(2, 1)), }, }) ); @@ -488,7 +478,7 @@ mod tests { value: "Hello World!".to_string(), encoded: "Hello World!".to_string(), }], - source_info: SourceInfo::new(1, 4, 1, 16), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 16)), }) ); } @@ -504,7 +494,7 @@ mod tests { value: "base64_inline".to_string(), encoded: "base64_inline".to_string(), }], - source_info: SourceInfo::new(1, 4, 1, 17), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 17)), }) ); } @@ -517,11 +507,11 @@ mod tests { MultilineString::Text(Text { space: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 4, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 4)), }, newline: Whitespace { value: "\n".to_string(), - source_info: SourceInfo::new(1, 4, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(2, 1)), }, value: Template { delimiter: None, @@ -529,7 +519,7 @@ mod tests { value: "line1\nline2\nline3\n".to_string(), encoded: "line1\nline2\nline3\n".to_string(), }], - source_info: SourceInfo::new(2, 1, 5, 1), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(5, 1)), }, }) ); @@ -543,11 +533,11 @@ mod tests { MultilineString::Text(Text { space: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 4, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 4)), }, newline: Whitespace { value: "\n".to_string(), - source_info: SourceInfo::new(1, 4, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(2, 1)), }, value: Template { delimiter: None, @@ -555,7 +545,7 @@ mod tests { value: "\n".to_string(), encoded: "\n".to_string(), }], - source_info: SourceInfo::new(2, 1, 3, 1), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(3, 1)), }, }) ); @@ -567,11 +557,11 @@ mod tests { MultilineString::Text(Text { space: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 4, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 4)), }, newline: Whitespace { value: "\n".to_string(), - source_info: SourceInfo::new(1, 4, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(2, 1)), }, value: Template { delimiter: None, @@ -579,7 +569,7 @@ mod tests { value: "\r\n".to_string(), encoded: "\r\n".to_string(), }], - source_info: SourceInfo::new(2, 1, 3, 1), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(3, 1)), }, }) ); @@ -624,7 +614,7 @@ mod tests { Template { delimiter: None, elements: vec![], - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), } ); assert_eq!(reader.state.cursor, 3); @@ -638,7 +628,7 @@ mod tests { value: "hello".to_string(), encoded: "hello".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 6)), } ); assert_eq!(reader.state.cursor, 8); @@ -665,11 +655,11 @@ variables { MultilineString::GraphQl(GraphQl { space: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 11, 1, 11), + source_info: SourceInfo::new(Pos::new(1, 11), Pos::new(1, 11)), }, newline: Whitespace { value: "\n".to_string(), - source_info: SourceInfo::new(1, 11, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 11), Pos::new(2, 1)), }, value: Template { delimiter: None, @@ -678,12 +668,12 @@ variables { encoded: "query Human($name: String!) {\n human(name: $name) {\n name\n height(unit: FOOT)\n}\n\n".to_string() }], - source_info: SourceInfo::new(2, 1, 8, 1), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(8, 1)), }, variables: Some(GraphQlVariables { space: Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(8, 10, 8, 11), + source_info: SourceInfo::new(Pos::new(8, 10), Pos::new(8, 11)), }, value: JsonValue::Object { space0: "\n ".to_string(), @@ -697,7 +687,7 @@ variables { encoded: "name".to_string() } ], - source_info: SourceInfo::new(9, 4, 9, 8) + source_info: SourceInfo::new(Pos::new(9, 4), Pos::new(9, 8)) }, space1: String::new(), space2: " ".to_string(), @@ -709,14 +699,14 @@ variables { encoded: "Han Solo".to_string() } ], - source_info: SourceInfo::new(9, 12, 9, 20) + source_info: SourceInfo::new(Pos::new(9, 12), Pos::new(9, 20)) }), space3: "\n".to_string() }] }, whitespace: Whitespace { value: "\n".to_string(), - source_info: SourceInfo::new(10, 2, 11, 1) + source_info: SourceInfo::new(Pos::new(10, 2), Pos::new(11, 1)) } }) }) diff --git a/packages/hurl_core/src/parser/parsers.rs b/packages/hurl_core/src/parser/parsers.rs index e3a727db053..091fce16b95 100644 --- a/packages/hurl_core/src/parser/parsers.rs +++ b/packages/hurl_core/src/parser/parsers.rs @@ -57,14 +57,9 @@ fn request(reader: &mut Reader) -> ParseResult { let headers = zero_or_more(key_value, reader)?; let sections = request_sections(reader)?; let b = optional(body, reader)?; - let source_info = SourceInfo::new( - start.pos.line, - start.pos.column, - reader.state.pos.line, - reader.state.pos.column, - ); - - // check duplicated section + let source_info = SourceInfo::new(start.pos, reader.state.pos); + + // Check duplicated section let mut section_names = vec![]; for section in sections.clone() { if section_names.contains(§ion.name().to_string()) { @@ -113,12 +108,7 @@ fn response(reader: &mut Reader) -> ParseResult { headers, sections, body: b, - source_info: SourceInfo::new( - start.pos.line, - start.pos.column, - reader.state.pos.line, - reader.state.pos.column, - ), + source_info: SourceInfo::new(start.pos, reader.state.pos), }) } @@ -163,12 +153,7 @@ fn version(reader: &mut Reader) -> ParseResult { if try_literal(s, reader).is_ok() { return Ok(Version { value: value.clone(), - source_info: SourceInfo::new( - start.pos.line, - start.pos.column, - reader.state.pos.line, - reader.state.pos.column, - ), + source_info: SourceInfo::new(start.pos, reader.state.pos), }); } } @@ -180,12 +165,7 @@ fn version(reader: &mut Reader) -> ParseResult { } Some(' ') => Ok(Version { value: VersionAny, - source_info: SourceInfo::new( - start.pos.line, - start.pos.column, - reader.state.pos.line, - reader.state.pos.column, - ), + source_info: SourceInfo::new(start.pos, reader.state.pos), }), _ => Err(Error { pos: start.pos, @@ -293,12 +273,12 @@ mod tests { line_terminators: vec![], space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, method: Method("GET".to_string()), space1: Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 4, 1, 5), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 5)), }, url: Template { elements: vec![TemplateElement::String { @@ -306,23 +286,23 @@ mod tests { encoded: String::from("http://google.fr"), }], delimiter: None, - source_info: SourceInfo::new(1, 5, 1, 21), + source_info: SourceInfo::new(Pos::new(1, 5), Pos::new(1, 21)), }, line_terminator0: LineTerminator { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 21, 1, 21), + source_info: SourceInfo::new(Pos::new(1, 21), Pos::new(1, 21)), }, comment: None, newline: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 21, 1, 21), + source_info: SourceInfo::new(Pos::new(1, 21), Pos::new(1, 21)), }, }, headers: vec![], sections: vec![], body: None, - source_info: SourceInfo::new(1, 1, 1, 21), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 21)), }; assert_eq!(request(&mut reader).unwrap(), default_request); assert_eq!(reader.state.cursor, 20); @@ -332,12 +312,12 @@ mod tests { line_terminators: vec![], space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, method: Method("GET".to_string()), space1: Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 4, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 6)), }, url: Template { elements: vec![TemplateElement::String { @@ -345,26 +325,26 @@ mod tests { encoded: String::from("http://google.fr"), }], delimiter: None, - source_info: SourceInfo::new(1, 6, 1, 22), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 22)), }, line_terminator0: LineTerminator { space0: Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 22, 1, 23), + source_info: SourceInfo::new(Pos::new(1, 22), Pos::new(1, 23)), }, comment: Some(Comment { value: " comment".to_string(), - source_info: SourceInfo::new(1, 24, 1, 32), + source_info: SourceInfo::new(Pos::new(1, 24), Pos::new(1, 32)), }), newline: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 32, 1, 32), + source_info: SourceInfo::new(Pos::new(1, 32), Pos::new(1, 32)), }, }, headers: vec![], sections: vec![], body: None, - source_info: SourceInfo::new(1, 1, 1, 32), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 32)), }; assert_eq!(request(&mut reader).unwrap(), default_request); assert_eq!(reader.state.cursor, 31); @@ -391,15 +371,15 @@ mod tests { line_terminators: vec![], space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(2, 1, 2, 1), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(2, 1)), }, value: Bytes::MultilineString(MultilineString::Text(Text { space: Whitespace { value: String::new(), - source_info: SourceInfo::new(2, 4, 2, 4), + source_info: SourceInfo::new(Pos::new(2, 4), Pos::new(2, 4)), }, newline: Whitespace { - source_info: SourceInfo::new(2, 4, 3, 1), + source_info: SourceInfo::new(Pos::new(2, 4), Pos::new(3, 1)), value: "\n".to_string(), }, value: Template { @@ -408,18 +388,18 @@ mod tests { encoded: String::from("Hello World!\n"), }], delimiter: None, - source_info: SourceInfo::new(3, 1, 4, 1), + source_info: SourceInfo::new(Pos::new(3, 1), Pos::new(4, 1)), }, })), line_terminator0: LineTerminator { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(4, 4, 4, 4), + source_info: SourceInfo::new(Pos::new(4, 4), Pos::new(4, 4)), }, comment: None, newline: Whitespace { value: String::new(), - source_info: SourceInfo::new(4, 4, 4, 4), + source_info: SourceInfo::new(Pos::new(4, 4), Pos::new(4, 4)), }, }, } @@ -466,7 +446,7 @@ mod tests { value: "Hello".to_string(), encoded: "Hello".to_string(), }], - source_info: SourceInfo::new(2, 2, 2, 7), + source_info: SourceInfo::new(Pos::new(2, 2), Pos::new(2, 7)), })) ); diff --git a/packages/hurl_core/src/parser/predicate.rs b/packages/hurl_core/src/parser/predicate.rs index 611b821a7e0..5e42266abe2 100644 --- a/packages/hurl_core/src/parser/predicate.rs +++ b/packages/hurl_core/src/parser/predicate.rs @@ -385,7 +385,7 @@ mod tests { false, Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), } ) ); @@ -398,7 +398,7 @@ mod tests { true, Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 4, 1, 5), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 5)), } ) ); @@ -414,14 +414,14 @@ mod tests { not: true, space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 4, 1, 5), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 5)), }, predicate_func: PredicateFunc { - source_info: SourceInfo::new(1, 5, 1, 12), + source_info: SourceInfo::new(Pos::new(1, 5), Pos::new(1, 12)), value: PredicateFuncValue::Equal { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 7, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 8)), }, value: PredicateValue::Bool(true), operator: true, @@ -449,7 +449,7 @@ mod tests { value: PredicateValue::Bool(true), space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 3, 1, 5), + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 5)), }, operator: true, @@ -466,7 +466,7 @@ mod tests { })), space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 3, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 4)), }, operator: true, } @@ -479,7 +479,7 @@ mod tests { value: PredicateValue::Number(Number::Integer(2)), space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 3, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 4)), }, operator: true, }, @@ -495,11 +495,11 @@ mod tests { value: "Bob".to_string(), encoded: "Bob".to_string(), }], - source_info: SourceInfo::new(1, 4, 1, 9), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 9)), }), space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 3, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 4)), }, operator: true, } @@ -515,20 +515,20 @@ mod tests { value: PredicateValue::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 6, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 6)), }, variable: Variable { name: "count".to_string(), - source_info: SourceInfo::new(1, 6, 1, 11), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 11)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 11, 1, 11), + source_info: SourceInfo::new(Pos::new(1, 11), Pos::new(1, 11)), }, }), space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 3, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 4)), }, operator: true, } diff --git a/packages/hurl_core/src/parser/primitives.rs b/packages/hurl_core/src/parser/primitives.rs index 722b6a6b466..2390caef88a 100644 --- a/packages/hurl_core/src/parser/primitives.rs +++ b/packages/hurl_core/src/parser/primitives.rs @@ -34,12 +34,7 @@ pub fn space(reader: &mut Reader) -> ParseResult { if c == ' ' || c == '\t' { Ok(Whitespace { value: c.to_string(), - source_info: SourceInfo::new( - start.pos.line, - start.pos.column, - reader.state.pos.line, - reader.state.pos.column, - ), + source_info: SourceInfo::new(start.pos, reader.state.pos), }) } else { Err(Error { @@ -59,12 +54,7 @@ pub fn one_or_more_spaces(reader: &mut Reader) -> ParseResult { let s = v.iter().map(|x| x.value.clone()).collect(); Ok(Whitespace { value: s, - source_info: SourceInfo::new( - start.pos.line, - start.pos.column, - reader.state.pos.line, - reader.state.pos.column, - ), + source_info: SourceInfo::new(start.pos, reader.state.pos), }) } Err(e) => Err(e), @@ -79,12 +69,7 @@ pub fn zero_or_more_spaces(reader: &mut Reader) -> ParseResult { let s = v.iter().map(|x| x.value.clone()).collect(); Ok(Whitespace { value: s, - source_info: SourceInfo::new( - start.pos.line, - start.pos.column, - reader.state.pos.line, - reader.state.pos.column, - ), + source_info: SourceInfo::new(start.pos, reader.state.pos), }) } Err(e) => Err(e), @@ -98,12 +83,7 @@ pub fn line_terminator(reader: &mut Reader) -> ParseResult { let nl = if reader.is_eof() { Whitespace { value: String::new(), - source_info: SourceInfo::new( - reader.state.pos.line, - reader.state.pos.column, - reader.state.pos.line, - reader.state.pos.column, - ), + source_info: SourceInfo::new(reader.state.pos, reader.state.pos), } } else { match newline(reader) { @@ -244,22 +224,12 @@ pub fn newline(reader: &mut Reader) -> ParseResult { match try_literal("\r\n", reader) { Ok(_) => Ok(Whitespace { value: "\r\n".to_string(), - source_info: SourceInfo::new( - start.pos.line, - start.pos.column, - reader.state.pos.line, - reader.state.pos.column, - ), + source_info: SourceInfo::new(start.pos, reader.state.pos), }), Err(_) => match literal("\n", reader) { Ok(_) => Ok(Whitespace { value: "\n".to_string(), - source_info: SourceInfo::new( - start.pos.line, - start.pos.column, - reader.state.pos.line, - reader.state.pos.column, - ), + source_info: SourceInfo::new(start.pos, reader.state.pos), }), Err(_) => Err(Error { pos: start.pos, @@ -641,7 +611,7 @@ mod tests { space(&mut reader), Ok(Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 1, 1, 2), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 2)), }), ); assert_eq!(reader.state.cursor, 1); @@ -654,7 +624,7 @@ mod tests { one_or_more_spaces(&mut reader), Ok(Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 1, 1, 3), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 3)), }) ); @@ -670,7 +640,7 @@ mod tests { zero_or_more_spaces(&mut reader), Ok(Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 1, 1, 3), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 3)), }) ); assert_eq!(reader.state.cursor, 2); @@ -680,7 +650,7 @@ mod tests { zero_or_more_spaces(&mut reader), Ok(Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }) ); assert_eq!(reader.state.cursor, 0); @@ -690,7 +660,7 @@ mod tests { zero_or_more_spaces(&mut reader), Ok(Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 1, 1, 2), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 2)), }) ); assert_eq!(reader.state.cursor, 1); @@ -712,7 +682,7 @@ mod tests { comment(&mut reader), Ok(Comment { value: String::new(), - source_info: SourceInfo::new(1, 2, 1, 2), + source_info: SourceInfo::new(Pos::new(1, 2), Pos::new(1, 2)), }) ); @@ -721,7 +691,7 @@ mod tests { comment(&mut reader), Ok(Comment { value: " comment".to_string(), - source_info: SourceInfo::new(1, 2, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 2), Pos::new(1, 10)), }) ); assert_eq!(reader.state.cursor, 9); @@ -779,7 +749,7 @@ mod tests { newline(&mut reader).unwrap(), Whitespace { value: String::from("\n"), - source_info: SourceInfo::new(1, 1, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(2, 1)), } ); } @@ -793,7 +763,7 @@ mod tests { line_terminators: vec![], space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, key: Template { delimiter: None, @@ -801,15 +771,15 @@ mod tests { value: "message".to_string(), encoded: "message".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 8)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 8, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 8), Pos::new(1, 8)), }, space2: Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 9, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 9), Pos::new(1, 10)), }, value: Template { delimiter: None, @@ -821,15 +791,15 @@ mod tests { TemplateElement::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 18, 1, 18), + source_info: SourceInfo::new(Pos::new(1, 18), Pos::new(1, 18)), }, variable: Variable { name: "name".to_string(), - source_info: SourceInfo::new(1, 18, 1, 22), + source_info: SourceInfo::new(Pos::new(1, 18), Pos::new(1, 22)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 22, 1, 22), + source_info: SourceInfo::new(Pos::new(1, 22), Pos::new(1, 22)), }, }), TemplateElement::String { @@ -837,20 +807,20 @@ mod tests { encoded: "!".to_string(), }, ], - source_info: SourceInfo::new(1, 10, 1, 25), + source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 25)), }, line_terminator0: LineTerminator { space0: Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 25, 1, 26), + source_info: SourceInfo::new(Pos::new(1, 25), Pos::new(1, 26)), }, comment: Some(Comment { value: " comment".to_string(), - source_info: SourceInfo::new(1, 27, 1, 35), + source_info: SourceInfo::new(Pos::new(1, 27), Pos::new(1, 35)), }), newline: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 35, 1, 35), + source_info: SourceInfo::new(Pos::new(1, 35), Pos::new(1, 35)), }, }, } @@ -866,33 +836,33 @@ mod tests { line_terminators: vec![], space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, key: Template { delimiter: None, elements: vec![TemplateElement::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 3, 1, 3), + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 3)), }, variable: Variable { name: "key".to_string(), - source_info: SourceInfo::new(1, 3, 1, 6) + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 6)) }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 6, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 6)), }, })], - source_info: SourceInfo::new(1, 1, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 8)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 8, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 8), Pos::new(1, 8)), }, space2: Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 9, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 9), Pos::new(1, 10)), }, value: Template { delimiter: None, @@ -900,17 +870,17 @@ mod tests { value: "value".to_string(), encoded: "value".to_string(), }], - source_info: SourceInfo::new(1, 10, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 15)), }, line_terminator0: LineTerminator { space0: Whitespace { value: "".to_string(), - source_info: SourceInfo::new(1, 15, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 15), Pos::new(1, 15)), }, comment: None, newline: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 15, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 15), Pos::new(1, 15)), }, }, } @@ -1222,13 +1192,13 @@ mod tests { Hex { space0: Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 5, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 5), Pos::new(1, 6)), }, value: vec![255], encoded: "ff".to_string(), space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 8, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 8), Pos::new(1, 8)), }, } ); @@ -1239,13 +1209,13 @@ mod tests { Hex { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 5, 1, 5), + source_info: SourceInfo::new(Pos::new(1, 5), Pos::new(1, 5)), }, value: vec![1, 2, 3], encoded: "010203".to_string(), space1: Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 11, 1, 12), + source_info: SourceInfo::new(Pos::new(1, 11), Pos::new(1, 12)), }, } ); @@ -1327,15 +1297,15 @@ mod tests { File { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 6, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 6)), }, filename: Filename { value: String::from("data.xml"), - source_info: SourceInfo::new(1, 6, 1, 14), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 14)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 14, 1, 14), + source_info: SourceInfo::new(Pos::new(1, 14), Pos::new(1, 14)), }, } ); @@ -1346,15 +1316,15 @@ mod tests { File { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 6, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 7)), }, filename: Filename { value: String::from("filename1"), - source_info: SourceInfo::new(1, 7, 1, 16), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 16)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 16, 1, 16), + source_info: SourceInfo::new(Pos::new(1, 16), Pos::new(1, 16)), }, } ); @@ -1365,15 +1335,15 @@ mod tests { File { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 6, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 7)), }, filename: Filename { value: String::from("tmp/filename1"), - source_info: SourceInfo::new(1, 7, 1, 20), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 20)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 20, 1, 20), + source_info: SourceInfo::new(Pos::new(1, 20), Pos::new(1, 20)), }, } ); @@ -1384,15 +1354,15 @@ mod tests { File { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 6, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 7)), }, filename: Filename { value: String::from("tmp/filename with spaces.txt"), - source_info: SourceInfo::new(1, 7, 1, 37), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 37)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 37, 1, 37), + source_info: SourceInfo::new(Pos::new(1, 37), Pos::new(1, 37)), }, } ); @@ -1448,13 +1418,13 @@ mod tests { Base64 { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 8, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 8), Pos::new(1, 10)), }, value: vec![77, 97], encoded: String::from("T WE="), space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 15, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 15), Pos::new(1, 15)), }, } ); diff --git a/packages/hurl_core/src/parser/query.rs b/packages/hurl_core/src/parser/query.rs index ac7a20b5080..c04a9d1da42 100644 --- a/packages/hurl_core/src/parser/query.rs +++ b/packages/hurl_core/src/parser/query.rs @@ -226,7 +226,7 @@ mod tests { assert_eq!( query(&mut reader).unwrap(), Query { - source_info: SourceInfo::new(1, 1, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 7)), value: QueryValue::Status, } ); @@ -238,7 +238,7 @@ mod tests { assert_eq!( query(&mut reader).unwrap(), Query { - source_info: SourceInfo::new(1, 1, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 7)), value: QueryValue::Status, } ); @@ -252,7 +252,7 @@ mod tests { QueryValue::Header { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 7, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 8)), }, name: Template { delimiter: Some('"'), @@ -260,7 +260,7 @@ mod tests { value: "Foo".to_string(), encoded: "Foo".to_string(), }], - source_info: SourceInfo::new(1, 8, 1, 13), + source_info: SourceInfo::new(Pos::new(1, 8), Pos::new(1, 13)), }, } ); @@ -274,7 +274,7 @@ mod tests { QueryValue::Cookie { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 7, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 8)), }, expr: CookiePath { name: Template { @@ -283,17 +283,17 @@ mod tests { value: "Foo".to_string(), encoded: "Foo".to_string(), }], - source_info: SourceInfo::new(1, 9, 1, 12), + source_info: SourceInfo::new(Pos::new(1, 9), Pos::new(1, 12)), }, attribute: Some(CookieAttribute { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 13, 1, 13), + source_info: SourceInfo::new(Pos::new(1, 13), Pos::new(1, 13)), }, name: CookieAttributeName::Domain("Domain".to_string()), space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 19, 1, 19), + source_info: SourceInfo::new(Pos::new(1, 19), Pos::new(1, 19)), }, }), }, @@ -313,7 +313,7 @@ mod tests { QueryValue::Xpath { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 6, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 7)), }, expr: Template { delimiter: Some('"'), @@ -321,14 +321,14 @@ mod tests { value: String::from("normalize-space(//head/title)"), encoded: String::from("normalize-space(//head/title)"), }], - source_info: SourceInfo::new(1, 7, 1, 38), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 38)), }, }, ); let mut reader = Reader::new("xpath \"normalize-space(//div[contains(concat(' ',normalize-space(@class),' '),' monthly-price ')])\""); assert_eq!(xpath_query(&mut reader).unwrap(), QueryValue::Xpath { - space0: Whitespace { value: String::from(" "), source_info: SourceInfo::new(1, 6, 1, 7) }, + space0: Whitespace { value: String::from(" "), source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 7)) }, expr: Template { delimiter: Some('"'), elements: vec![ @@ -337,7 +337,7 @@ mod tests { encoded: String::from("normalize-space(//div[contains(concat(' ',normalize-space(@class),' '),' monthly-price ')])"), } ], - source_info: SourceInfo::new(1, 7, 1, 100), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 100)), }, }); @@ -351,7 +351,7 @@ mod tests { QueryValue::Jsonpath { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 9, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 9), Pos::new(1, 10)), }, expr: Template { elements: vec![TemplateElement::String { @@ -359,7 +359,7 @@ mod tests { encoded: "$['statusCode']".to_string(), }], delimiter: Some('"'), - source_info: SourceInfo::new(1, 10, 1, 27), + source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 27)), }, }, ); @@ -369,7 +369,7 @@ mod tests { QueryValue::Jsonpath { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 9, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 9), Pos::new(1, 10)), }, expr: Template { elements: vec![TemplateElement::String { @@ -377,7 +377,7 @@ mod tests { encoded: "$.success".to_string(), }], delimiter: Some('"'), - source_info: SourceInfo::new(1, 10, 1, 21), + source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 21)), }, }, ); @@ -389,7 +389,7 @@ mod tests { assert_eq!( query(&mut reader).unwrap(), Query { - source_info: SourceInfo::new(1, 1, 1, 5), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 5)), value: QueryValue::Body, } ); @@ -398,10 +398,10 @@ mod tests { vec![( Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 5, 1, 6) + source_info: SourceInfo::new(Pos::new(1, 5), Pos::new(1, 6)) }, Filter { - source_info: SourceInfo::new(1, 6, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 15)), value: FilterValue::UrlDecode, } )] diff --git a/packages/hurl_core/src/parser/sections.rs b/packages/hurl_core/src/parser/sections.rs index b181d59fa07..7162996ea29 100644 --- a/packages/hurl_core/src/parser/sections.rs +++ b/packages/hurl_core/src/parser/sections.rs @@ -378,31 +378,31 @@ mod tests { line_terminators: vec![], space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, line_terminator0: LineTerminator { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 10, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 10)), }, comment: None, newline: Whitespace { value: String::from("\n"), - source_info: SourceInfo::new(1, 10, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(2, 1)), }, }, value: SectionValue::Asserts(vec![Assert { line_terminators: vec![], space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(2, 1, 2, 1), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(2, 1)), }, query: Query { - source_info: SourceInfo::new(2, 1, 2, 18), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(2, 18)), value: QueryValue::Header { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(2, 7, 2, 8), + source_info: SourceInfo::new(Pos::new(2, 7), Pos::new(2, 8)), }, name: Template { delimiter: Some('"'), @@ -410,27 +410,27 @@ mod tests { value: "Location".to_string(), encoded: "Location".to_string(), }], - source_info: SourceInfo::new(2, 8, 2, 18), + source_info: SourceInfo::new(Pos::new(2, 8), Pos::new(2, 18)), }, }, }, filters: vec![], space1: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(2, 18, 2, 19), + source_info: SourceInfo::new(Pos::new(2, 18), Pos::new(2, 19)), }, predicate: Predicate { not: false, space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(2, 19, 2, 19), + source_info: SourceInfo::new(Pos::new(2, 19), Pos::new(2, 19)), }, predicate_func: PredicateFunc { - source_info: SourceInfo::new(2, 19, 2, 41), + source_info: SourceInfo::new(Pos::new(2, 19), Pos::new(2, 41)), value: PredicateFuncValue::Equal { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(2, 21, 2, 22), + source_info: SourceInfo::new(Pos::new(2, 21), Pos::new(2, 22)), }, value: PredicateValue::String(Template { delimiter: Some('"'), @@ -438,7 +438,7 @@ mod tests { value: "https://google.fr".to_string(), encoded: "https://google.fr".to_string(), }], - source_info: SourceInfo::new(2, 22, 2, 41), + source_info: SourceInfo::new(Pos::new(2, 22), Pos::new(2, 41)), }), operator: true, }, @@ -447,16 +447,16 @@ mod tests { line_terminator0: LineTerminator { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(2, 41, 2, 41), + source_info: SourceInfo::new(Pos::new(2, 41), Pos::new(2, 41)), }, comment: None, newline: Whitespace { value: String::from("\n"), - source_info: SourceInfo::new(2, 41, 3, 1), + source_info: SourceInfo::new(Pos::new(2, 41), Pos::new(3, 1)), }, }, }]), - source_info: SourceInfo::new(1, 1, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 10)), } ); } @@ -499,7 +499,7 @@ mod tests { value: "Bar".to_string(), encoded: "Bar".to_string(), }], - source_info: SourceInfo::new(1, 6, 1, 9), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 9)), } ); } @@ -532,19 +532,19 @@ mod tests { FileValue { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 6, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 6)), }, filename: Filename { value: "hello.txt".to_string(), - source_info: SourceInfo::new(1, 6, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 15)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 15, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 15), Pos::new(1, 15)), }, space2: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 16, 1, 16), + source_info: SourceInfo::new(Pos::new(1, 16), Pos::new(1, 16)), }, content_type: None, } @@ -555,19 +555,19 @@ mod tests { FileValue { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 6, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 6)), }, filename: Filename { value: "hello.txt".to_string(), - source_info: SourceInfo::new(1, 6, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 15)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 15, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 15), Pos::new(1, 15)), }, space2: Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(1, 16, 1, 17), + source_info: SourceInfo::new(Pos::new(1, 16), Pos::new(1, 17)), }, content_type: Some("text/html".to_string()), } @@ -611,17 +611,17 @@ mod tests { value: "url".to_string(), encoded: "url".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 4)), }, ); assert_eq!( capture0.query, Query { - source_info: SourceInfo::new(1, 6, 1, 23), + source_info: SourceInfo::new(Pos::new(1, 6), Pos::new(1, 23)), value: QueryValue::Header { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 12, 1, 13), + source_info: SourceInfo::new(Pos::new(1, 12), Pos::new(1, 13)), }, name: Template { delimiter: Some('"'), @@ -629,7 +629,7 @@ mod tests { value: "Location".to_string(), encoded: "Location".to_string(), }], - source_info: SourceInfo::new(1, 13, 1, 23), + source_info: SourceInfo::new(Pos::new(1, 13), Pos::new(1, 23)), }, }, } @@ -644,11 +644,11 @@ mod tests { assert_eq!( capture0.query, Query { - source_info: SourceInfo::new(1, 8, 1, 25), + source_info: SourceInfo::new(Pos::new(1, 8), Pos::new(1, 25)), value: QueryValue::Header { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 14, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 14), Pos::new(1, 15)), }, name: Template { delimiter: Some('"'), @@ -656,7 +656,7 @@ mod tests { value: "Location".to_string(), encoded: "Location".to_string(), }], - source_info: SourceInfo::new(1, 15, 1, 25), + source_info: SourceInfo::new(Pos::new(1, 15), Pos::new(1, 25)), }, }, } @@ -709,11 +709,11 @@ mod tests { assert_eq!( assert0.query, Query { - source_info: SourceInfo::new(1, 1, 1, 18), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 18)), value: QueryValue::Header { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 7, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 7), Pos::new(1, 8)), }, name: Template { delimiter: Some('"'), @@ -721,7 +721,7 @@ mod tests { value: "Location".to_string(), encoded: "Location".to_string(), }], - source_info: SourceInfo::new(1, 8, 1, 18), + source_info: SourceInfo::new(Pos::new(1, 8), Pos::new(1, 18)), }, }, } @@ -738,14 +738,14 @@ mod tests { not: false, space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 21, 1, 21), + source_info: SourceInfo::new(Pos::new(1, 21), Pos::new(1, 21)), }, predicate_func: PredicateFunc { - source_info: SourceInfo::new(1, 21, 1, 25), + source_info: SourceInfo::new(Pos::new(1, 21), Pos::new(1, 25)), value: PredicateFuncValue::Equal { space0: Whitespace { value: String::from(" "), - source_info: SourceInfo::new(1, 23, 1, 24), + source_info: SourceInfo::new(Pos::new(1, 23), Pos::new(1, 24)), }, value: PredicateValue::Number(Number::Integer(5)), operator: true, @@ -765,24 +765,24 @@ mod tests { line_terminators: vec![], space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, line_terminator0: LineTerminator { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 12, 1, 12), + source_info: SourceInfo::new(Pos::new(1, 12), Pos::new(1, 12)), }, comment: None, newline: Whitespace { value: String::from("\n"), - source_info: SourceInfo::new(1, 12, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 12), Pos::new(2, 1)), }, }, value: SectionValue::BasicAuth(Some(KeyValue { line_terminators: vec![], space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(2, 1, 2, 1) + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(2, 1)) }, key: Template { delimiter: None, @@ -790,15 +790,15 @@ mod tests { value: "user".to_string(), encoded: "user".to_string() }], - source_info: SourceInfo::new(2, 1, 2, 5), + source_info: SourceInfo::new(Pos::new(2, 1), Pos::new(2, 5)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(2, 5, 2, 5) + source_info: SourceInfo::new(Pos::new(2, 5), Pos::new(2, 5)) }, space2: Whitespace { value: String::new(), - source_info: SourceInfo::new(2, 6, 2, 6) + source_info: SourceInfo::new(Pos::new(2, 6), Pos::new(2, 6)) }, value: Template { delimiter: None, @@ -806,21 +806,21 @@ mod tests { value: "password".to_string(), encoded: "password".to_string() }], - source_info: SourceInfo::new(2, 6, 2, 14), + source_info: SourceInfo::new(Pos::new(2, 6), Pos::new(2, 14)), }, line_terminator0: LineTerminator { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(2, 14, 2, 14) + source_info: SourceInfo::new(Pos::new(2, 14), Pos::new(2, 14)) }, comment: None, newline: Whitespace { value: "\n".to_string(), - source_info: SourceInfo::new(2, 14, 3, 1) + source_info: SourceInfo::new(Pos::new(2, 14), Pos::new(3, 1)) }, }, })), - source_info: SourceInfo::new(1, 1, 1, 12), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 12)), } ); assert_eq!(reader.state.pos, Pos { line: 3, column: 1 }); @@ -832,21 +832,21 @@ mod tests { line_terminators: vec![], space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, line_terminator0: LineTerminator { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 12, 1, 12), + source_info: SourceInfo::new(Pos::new(1, 12), Pos::new(1, 12)), }, comment: None, newline: Whitespace { value: String::from("\n"), - source_info: SourceInfo::new(1, 12, 2, 1), + source_info: SourceInfo::new(Pos::new(1, 12), Pos::new(2, 1)), }, }, value: SectionValue::BasicAuth(None), - source_info: SourceInfo::new(1, 1, 1, 12), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 12)), } ); assert_eq!(reader.state.pos, Pos { line: 2, column: 1 }); diff --git a/packages/hurl_core/src/parser/string.rs b/packages/hurl_core/src/parser/string.rs index 95b3ffcb5d0..4d7536f33be 100644 --- a/packages/hurl_core/src/parser/string.rs +++ b/packages/hurl_core/src/parser/string.rs @@ -269,7 +269,7 @@ mod tests { Template { delimiter: None, elements: vec![], - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), } ); assert_eq!(reader.state.cursor, 0); @@ -286,7 +286,7 @@ mod tests { value: "a".to_string(), encoded: "a".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 2), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 2)), } ); assert_eq!(reader.state.cursor, 1); @@ -303,7 +303,7 @@ mod tests { value: "a#".to_string(), encoded: "a\\u{23}".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 8), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 8)), } ); assert_eq!(reader.state.cursor, 7); @@ -320,7 +320,7 @@ mod tests { value: "\"hi\"".to_string(), encoded: "\"hi\"".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 5), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 5)), } ); assert_eq!(reader.state.cursor, 4); @@ -341,15 +341,15 @@ mod tests { TemplateElement::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 14, 1, 14), + source_info: SourceInfo::new(Pos::new(1, 14), Pos::new(1, 14)), }, variable: Variable { name: "name".to_string(), - source_info: SourceInfo::new(1, 14, 1, 18), + source_info: SourceInfo::new(Pos::new(1, 14), Pos::new(1, 18)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 18, 1, 18), + source_info: SourceInfo::new(Pos::new(1, 18), Pos::new(1, 18)), }, }), TemplateElement::String { @@ -357,7 +357,7 @@ mod tests { encoded: "!".to_string(), }, ], - source_info: SourceInfo::new(1, 1, 1, 21), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 21)), } ); assert_eq!(reader.state.cursor, 20); @@ -371,7 +371,7 @@ mod tests { Template { delimiter: Some('"'), elements: vec![], - source_info: SourceInfo::new(1, 1, 1, 3), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 3)), } ); assert_eq!(reader.state.cursor, 2); @@ -385,7 +385,7 @@ mod tests { value: "a#".to_string(), encoded: "a#".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 5), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 5)), } ); assert_eq!(reader.state.cursor, 4); @@ -399,7 +399,7 @@ mod tests { value: "{0}".to_string(), encoded: "{0}".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 6)), } ); assert_eq!(reader.state.cursor, 5); @@ -417,7 +417,7 @@ mod tests { value: "\"hi\"".to_string(), encoded: "\\\"hi\\\"".to_string() }], - source_info: SourceInfo::new(1, 1, 1, 9), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 9)), } ); assert_eq!(reader.state.cursor, 8); @@ -456,7 +456,7 @@ mod tests { Template { delimiter: Some('`'), elements: vec![], - source_info: SourceInfo::new(1, 1, 1, 3), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 3)), } ); assert_eq!(reader.state.cursor, 2); @@ -470,7 +470,7 @@ mod tests { value: "foo#".to_string(), encoded: "foo#".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 7)), } ); assert_eq!(reader.state.cursor, 6); @@ -484,7 +484,7 @@ mod tests { value: "{0}".to_string(), encoded: "{0}".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 6), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 6)), } ); assert_eq!(reader.state.cursor, 5); @@ -502,7 +502,7 @@ mod tests { value: "`hi`".to_string(), encoded: "\\`hi\\`".to_string() }], - source_info: SourceInfo::new(1, 1, 1, 9), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 9)), } ); assert_eq!(reader.state.cursor, 8); diff --git a/packages/hurl_core/src/parser/template.rs b/packages/hurl_core/src/parser/template.rs index 6ded95b80f8..3c9a14f843d 100644 --- a/packages/hurl_core/src/parser/template.rs +++ b/packages/hurl_core/src/parser/template.rs @@ -142,7 +142,7 @@ mod tests { #[test] fn test_templatize_empty_string() { let encoded_string = EncodedString { - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), chars: vec![], }; assert_eq!(templatize(encoded_string).unwrap(), vec![]); @@ -152,7 +152,7 @@ mod tests { fn test_templatize_hello_world() { // Hi\u0020{{name}}! let encoded_string = EncodedString { - source_info: SourceInfo::new(1, 1, 1, 18), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 18)), chars: vec![ ('H', "H".to_string(), Pos { line: 1, column: 1 }), ('i', "i".to_string(), Pos { line: 1, column: 2 }), @@ -234,15 +234,15 @@ mod tests { TemplateElement::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 11, 1, 11), + source_info: SourceInfo::new(Pos::new(1, 11), Pos::new(1, 11)), }, variable: Variable { name: "name".to_string(), - source_info: SourceInfo::new(1, 11, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 11), Pos::new(1, 15)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 15, 1, 15), + source_info: SourceInfo::new(Pos::new(1, 15), Pos::new(1, 15)), }, }), TemplateElement::String { @@ -257,7 +257,7 @@ mod tests { fn test_templatize_expression_only() { // {{x}}! let encoded_string = EncodedString { - source_info: SourceInfo::new(1, 1, 1, 7), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 7)), chars: vec![ ('{', "{".to_string(), Pos { line: 1, column: 1 }), ('{', "{".to_string(), Pos { line: 1, column: 2 }), @@ -271,15 +271,15 @@ mod tests { vec![TemplateElement::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 3, 1, 3), + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 3)), }, variable: Variable { name: "x".to_string(), - source_info: SourceInfo::new(1, 3, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 3), Pos::new(1, 4)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 4, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 4), Pos::new(1, 4)), }, }),] ); @@ -290,7 +290,7 @@ mod tests { // missing closing // {{x let encoded_string = EncodedString { - source_info: SourceInfo::new(1, 1, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 4)), chars: vec![ ('{', "{".to_string(), Pos { line: 1, column: 1 }), ('{', "{".to_string(), Pos { line: 1, column: 2 }), @@ -313,7 +313,7 @@ mod tests { // \{\{ // This is a valid string "{{" let encoded_string = EncodedString { - source_info: SourceInfo::new(1, 1, 1, 4), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 4)), chars: vec![ ('{', "\\{".to_string(), Pos { line: 1, column: 1 }), ('{', "\\{".to_string(), Pos { line: 1, column: 2 }), diff --git a/packages/hurl_core/src/parser/url.rs b/packages/hurl_core/src/parser/url.rs index cd37993bf1b..f47199536b9 100644 --- a/packages/hurl_core/src/parser/url.rs +++ b/packages/hurl_core/src/parser/url.rs @@ -157,7 +157,7 @@ mod tests { encoded: String::from("http://google.fr"), }], delimiter: None, - source_info: SourceInfo::new(1, 1, 1, 17), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 17)), } ); assert_eq!(reader.state.cursor, 16); @@ -176,7 +176,7 @@ mod tests { ), }], delimiter: None, - source_info: SourceInfo::new(1, 1, 1, 57), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 57)), } ); assert_eq!(reader.state.cursor, 56); @@ -196,15 +196,15 @@ mod tests { TemplateElement::Expression(Expr { space0: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 10, 1, 10), + source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 10)), }, variable: Variable { name: String::from("host"), - source_info: SourceInfo::new(1, 10, 1, 14), + source_info: SourceInfo::new(Pos::new(1, 10), Pos::new(1, 14)), }, space1: Whitespace { value: String::new(), - source_info: SourceInfo::new(1, 14, 1, 14), + source_info: SourceInfo::new(Pos::new(1, 14), Pos::new(1, 14)), }, }), TemplateElement::String { @@ -213,7 +213,7 @@ mod tests { }, ], delimiter: None, - source_info: SourceInfo::new(1, 1, 1, 19), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 19)), } ); assert_eq!(reader.state.cursor, 18); diff --git a/packages/hurlfmt/src/format/json.rs b/packages/hurlfmt/src/format/json.rs index 80fb2b0c8a9..45f28c5a5a9 100644 --- a/packages/hurlfmt/src/format/json.rs +++ b/packages/hurlfmt/src/format/json.rs @@ -710,7 +710,7 @@ pub mod tests { fn whitespace() -> Whitespace { Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } @@ -736,7 +736,7 @@ pub mod tests { value: "http://example.com".to_string(), encoded: "not_used".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, line_terminator0: line_terminator(), headers: vec![KeyValue { @@ -748,7 +748,7 @@ pub mod tests { value: "Foo".to_string(), encoded: "unused".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace(), space2: whitespace(), @@ -758,13 +758,13 @@ pub mod tests { value: "Bar".to_string(), encoded: "unused".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, line_terminator0: line_terminator(), }], sections: vec![], body: None, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } .to_json(), JValue::Object(vec![ @@ -791,19 +791,19 @@ pub mod tests { line_terminators: vec![], version: Version { value: VersionValue::Version11, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space0: whitespace(), status: Status { value: StatusValue::Specific(200), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace(), line_terminator0: line_terminator(), headers: vec![], sections: vec![], body: None, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } .to_json(), JValue::Object(vec![ @@ -819,19 +819,19 @@ pub mod tests { line_terminators: vec![], version: Version { value: VersionValue::VersionAny, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space0: whitespace(), status: Status { value: StatusValue::Any, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace(), line_terminator0: line_terminator(), headers: vec![], sections: vec![], body: None, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } .to_json(), JValue::Object(vec![]) @@ -840,7 +840,7 @@ pub mod tests { fn header_query() -> Query { Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: QueryValue::Header { space0: whitespace(), name: Template { @@ -849,7 +849,7 @@ pub mod tests { value: "Content-Length".to_string(), encoded: "10".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }, } @@ -865,7 +865,7 @@ pub mod tests { value: "size".to_string(), encoded: "unused".to_string(), }], - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: whitespace(), space2: whitespace(), @@ -892,7 +892,7 @@ pub mod tests { not: false, space0: whitespace(), predicate_func: PredicateFunc { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: PredicateFuncValue::Equal { space0: whitespace(), value: PredicateValue::Number(Number::Integer(value)), diff --git a/packages/hurlfmt/src/linter/rules.rs b/packages/hurlfmt/src/linter/rules.rs index 1bf98fc789e..13269988207 100644 --- a/packages/hurlfmt/src/linter/rules.rs +++ b/packages/hurlfmt/src/linter/rules.rs @@ -81,7 +81,7 @@ fn lint_request(request: &Request) -> Request { let mut sections: Vec
= request.sections.iter().map(lint_section).collect(); sections.sort_by_key(|k| section_value_index(k.value.clone())); - let source_info = SourceInfo::new(0, 0, 0, 0); + let source_info = SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)); Request { line_terminators, space0, @@ -129,7 +129,7 @@ fn lint_response(response: &Response) -> Response { headers, sections, body, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } @@ -142,7 +142,7 @@ fn lint_section(section: &Section) -> Section { space0: empty_whitespace(), value, line_terminator0, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } @@ -227,7 +227,7 @@ fn lint_capture(capture: &Capture) -> Capture { fn lint_query(query: &Query) -> Query { Query { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: lint_query_value(&query.value), } } @@ -329,7 +329,7 @@ fn lint_predicate(predicate: &Predicate) -> Predicate { fn lint_predicate_func(predicate_func: &PredicateFunc) -> PredicateFunc { PredicateFunc { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: lint_predicate_func_value(&predicate_func.value), } } @@ -503,7 +503,7 @@ fn lint_file(file: &File) -> File { space0: empty_whitespace(), filename: Filename { value: file.filename.value.clone(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, space1: empty_whitespace(), } @@ -556,14 +556,14 @@ fn lint_file_param(file_param: &FileParam) -> FileParam { fn empty_whitespace() -> Whitespace { Whitespace { value: String::new(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } fn one_whitespace() -> Whitespace { Whitespace { value: " ".to_string(), - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } @@ -588,7 +588,7 @@ fn lint_line_terminator(line_terminator: &LineTerminator) -> LineTerminator { None => empty_whitespace(), Some(_) => Whitespace { value: line_terminator.clone().space0.value, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }, }; let comment = line_terminator.comment.as_ref().map(lint_comment); @@ -598,7 +598,7 @@ fn lint_line_terminator(line_terminator: &LineTerminator) -> LineTerminator { } else { "\n".to_string() }, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), }; LineTerminator { space0, @@ -614,7 +614,7 @@ fn lint_comment(comment: &Comment) -> Comment { } else { format!(" {}", comment.value) }, - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), } } @@ -628,7 +628,7 @@ fn lint_entry_option(entry_option: &EntryOption) -> EntryOption { fn lint_filter(filter: &Filter) -> Filter { Filter { - source_info: SourceInfo::new(0, 0, 0, 0), + source_info: SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)), value: lint_filter_value(&filter.value), } } diff --git a/packages/hurlfmt/tests/json.rs b/packages/hurlfmt/tests/json.rs index 9e51978356a..194fba0db28 100644 --- a/packages/hurlfmt/tests/json.rs +++ b/packages/hurlfmt/tests/json.rs @@ -54,7 +54,7 @@ fn value_boolean() -> BoxedStrategy { } fn value_string() -> BoxedStrategy { - let source_info = SourceInfo::new(0, 0, 0, 0); + let source_info = SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0)); let variable = Variable { name: "name".to_string(), source_info: source_info.clone(), @@ -223,7 +223,7 @@ fn value() -> BoxedStrategy { value: "key1".to_string(), encoded: "key1".to_string(), }], - source_info: SourceInfo::new(1, 1, 1, 1), + source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 1)), }, space1, space2,