Skip to content

Commit

Permalink
Create new on SourceInfo and Pos.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamiel committed Nov 27, 2023
1 parent ce245c2 commit a8e7fe9
Show file tree
Hide file tree
Showing 55 changed files with 614 additions and 644 deletions.
4 changes: 2 additions & 2 deletions packages/hurl/src/output/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions packages/hurl/src/report/html/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -137,7 +137,7 @@ mod tests {
</pre>"#;

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,
}];
Expand Down
6 changes: 3 additions & 3 deletions packages/hurl/src/report/junit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(),
},
Expand All @@ -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,
)],
Expand Down
6 changes: 3 additions & 3 deletions packages/hurl/src/report/junit/testcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
},
Expand Down Expand Up @@ -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,
)],
Expand Down
8 changes: 4 additions & 4 deletions packages/hurl/src/runner/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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,
},
)],
Expand Down Expand Up @@ -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(())),
}
);
Expand Down
13 changes: 8 additions & 5 deletions packages/hurl/src/runner/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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,
});
Expand All @@ -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))
);
}
}
20 changes: 10 additions & 10 deletions packages/hurl/src/runner/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![],
Expand All @@ -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(),
Expand All @@ -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![],
Expand All @@ -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(),
Expand All @@ -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![],
Expand All @@ -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(),
Expand All @@ -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![],
Expand All @@ -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 {
Expand All @@ -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)),
},
},
},
Expand Down
9 changes: 6 additions & 3 deletions packages/hurl/src/runner/filter/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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!(
Expand All @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions packages/hurl/src/runner/filter/days_after_now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions packages/hurl/src/runner/filter/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ 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::*;

#[test]
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!(
Expand Down
4 changes: 2 additions & 2 deletions packages/hurl/src/runner/filter/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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![
Expand Down
4 changes: 2 additions & 2 deletions packages/hurl/src/runner/filter/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ 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::*;

#[test]
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!(
Expand Down
4 changes: 2 additions & 2 deletions packages/hurl/src/runner/filter/html_escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
Loading

0 comments on commit a8e7fe9

Please sign in to comment.