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