Move hurl_core::ast::Pos to hurl_core::reader::Pos

This commit is contained in:
Jean-Christophe Amiel 2024-06-28 16:47:06 +02:00
parent 7743be6d0a
commit 345e98c72c
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
70 changed files with 123 additions and 76 deletions

View File

@ -60,7 +60,8 @@ fn requests_count(runs: &[HurlRun]) -> usize {
#[cfg(test)]
pub mod tests {
use hurl::runner::{EntryResult, HurlResult, Input};
use hurl_core::ast::{Pos, SourceInfo};
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
use super::*;

View File

@ -15,7 +15,8 @@
* limitations under the License.
*
*/
use hurl_core::ast::Pos;
use hurl_core::reader::Pos;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ParseError {

View File

@ -277,7 +277,7 @@ fn equal_string_predicate_func(reader: &mut Reader) -> ParseResult<PredicateFunc
#[cfg(test)]
mod tests {
use hurl_core::ast::Pos;
use hurl_core::reader::Pos;
// tests from https://cburgmer.github.io/json-path-comparison
use super::*;

View File

@ -206,7 +206,7 @@ pub fn whitespace(reader: &mut Reader) {
#[cfg(test)]
mod tests {
use super::*;
use hurl_core::ast::Pos;
use hurl_core::reader::Pos;
#[test]
fn test_natural() {

View File

@ -122,7 +122,8 @@ mod tests {
use crate::output::write_last_body;
use crate::runner::{EntryResult, HurlResult, Output};
use crate::util::term::{Stdout, WriteMode};
use hurl_core::ast::{Pos, SourceInfo};
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
use std::str::FromStr;
fn default_response() -> Response {

View File

@ -109,7 +109,8 @@ fn html_escape(text: &str) -> String {
mod tests {
use crate::report::html::nav::error_to_html;
use crate::runner::{RunnerError, RunnerErrorKind};
use hurl_core::ast::{Pos, SourceInfo};
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
#[test]
fn test_error_html() {

View File

@ -83,7 +83,8 @@ fn underline_errors(content: &str, errors: &[RunnerError]) -> String {
#[cfg(test)]
mod tests {
use hurl_core::ast::{Pos, SourceInfo};
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
use super::*;
use crate::runner::RunnerErrorKind::QueryHeaderNotFound;

View File

@ -147,7 +147,8 @@ fn create_testsuite(testcases: &[Testcase]) -> Element {
#[cfg(test)]
mod tests {
use crate::http::HttpError;
use hurl_core::ast::{Pos, SourceInfo};
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
use crate::report::junit::xml::XmlDocument;
use crate::report::junit::{create_testsuite, Testcase};

View File

@ -91,7 +91,8 @@ impl Testcase {
#[cfg(test)]
mod test {
use crate::http::HttpError;
use hurl_core::ast::{Pos, SourceInfo};
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
use crate::report::junit::testcase::Testcase;
use crate::report::junit::xml::XmlDocument;

View File

@ -178,6 +178,7 @@ pub fn eval_explicit_assert(
#[cfg(test)]
pub mod tests {
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
use std::path::Path;
use super::super::query;

View File

@ -93,6 +93,7 @@ mod tests {
use std::path::Path;
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
use super::*;

View File

@ -71,7 +71,8 @@ pub fn eval_capture(
#[cfg(test)]
pub mod tests {
use hurl_core::ast::{Pos, SourceInfo};
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
use self::super::super::query;
use super::*;

View File

@ -317,8 +317,9 @@ fn color_red_multiline_string(s: &str) -> StyledString {
mod tests {
use crate::http::HttpError;
use crate::runner::{RunnerError, RunnerErrorKind};
use hurl_core::ast::{Pos, SourceInfo};
use hurl_core::ast::SourceInfo;
use hurl_core::error::{error_string, split_lines, DisplaySourceError, OutputFormat};
use hurl_core::reader::Pos;
use hurl_core::text::Format;
#[test]

View File

@ -39,7 +39,8 @@ pub fn eval_count(
#[cfg(test)]
pub mod tests {
use crate::runner::filter::eval::eval_filter;
use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo};
use hurl_core::ast::{Filter, FilterValue, SourceInfo};
use hurl_core::reader::Pos;
use std::collections::HashMap;
use super::*;

View File

@ -44,7 +44,8 @@ pub mod tests {
use crate::runner::filter::eval::eval_filter;
use chrono::offset::Utc;
use chrono::Duration;
use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo};
use hurl_core::ast::{Filter, FilterValue, SourceInfo};
use hurl_core::reader::Pos;
use std::collections::HashMap;
use super::*;

View File

@ -57,7 +57,8 @@ pub fn eval_decode(
#[cfg(test)]
pub mod tests {
use crate::runner::filter::eval::eval_filter;
use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo};
use hurl_core::ast::{Filter, FilterValue, SourceInfo};
use hurl_core::reader::Pos;
use super::*;

View File

@ -122,7 +122,8 @@ 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, Pos, SourceInfo};
use hurl_core::ast::{Filter, FilterValue, SourceInfo};
use hurl_core::reader::Pos;
use std::collections::HashMap;
#[test]

View File

@ -46,7 +46,8 @@ pub fn eval_format(
#[cfg(test)]
pub mod tests {
use crate::runner::filter::eval::eval_filter;
use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo};
use hurl_core::ast::{Filter, FilterValue, SourceInfo};
use hurl_core::reader::Pos;
use super::*;

View File

@ -42,7 +42,8 @@ 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, Pos, SourceInfo};
use hurl_core::ast::{Filter, FilterValue, SourceInfo};
use hurl_core::reader::Pos;
use std::collections::HashMap;
#[test]

View File

@ -42,7 +42,8 @@ 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, Pos, SourceInfo};
use hurl_core::ast::{Filter, FilterValue, SourceInfo};
use hurl_core::reader::Pos;
use std::collections::HashMap;
#[test]

View File

@ -77,9 +77,8 @@ pub fn eval_jsonpath_string(
#[cfg(test)]
pub mod tests {
use hurl_core::ast::{
Filter, FilterValue, Pos, SourceInfo, Template, TemplateElement, Whitespace,
};
use hurl_core::ast::{Filter, FilterValue, SourceInfo, Template, TemplateElement, Whitespace};
use hurl_core::reader::Pos;
use std::collections::HashMap;
use crate::runner::filter::eval::eval_filter;

View File

@ -48,7 +48,8 @@ pub fn eval_nth(
pub mod tests {
use crate::runner::filter::eval::eval_filter;
use crate::runner::{Number, RunnerError, RunnerErrorKind, Value};
use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo, Whitespace};
use hurl_core::ast::{Filter, FilterValue, SourceInfo, Whitespace};
use hurl_core::reader::Pos;
use std::collections::HashMap;
#[test]

View File

@ -53,8 +53,10 @@ pub mod tests {
use crate::runner::filter::eval::eval_filter;
use crate::runner::{RunnerErrorKind, Value};
use hurl_core::ast::{
Filter, FilterValue, Pos, RegexValue, SourceInfo, Template, TemplateElement, Whitespace,
Filter, FilterValue, RegexValue, SourceInfo, Template, TemplateElement, Whitespace,
};
use hurl_core::reader::Pos;
#[test]
fn eval_filter_regex() {
// regex "Hello (.*)!"

View File

@ -51,8 +51,9 @@ pub mod tests {
use crate::runner::filter::eval::eval_filter;
use crate::runner::Value;
use hurl_core::ast::{
Filter, FilterValue, Pos, RegexValue, SourceInfo, Template, TemplateElement, Whitespace,
Filter, FilterValue, RegexValue, SourceInfo, Template, TemplateElement, Whitespace,
};
use hurl_core::reader::Pos;
use std::collections::HashMap;
#[test]

View File

@ -50,9 +50,8 @@ pub mod tests {
use crate::runner::filter::eval::eval_filter;
use crate::runner::Value;
use hurl_core::ast::{
Filter, FilterValue, Pos, SourceInfo, Template, TemplateElement, Whitespace,
};
use hurl_core::ast::{Filter, FilterValue, SourceInfo, Template, TemplateElement, Whitespace};
use hurl_core::reader::Pos;
use std::collections::HashMap;
#[test]

View File

@ -56,9 +56,8 @@ 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, Pos, SourceInfo, Template, TemplateElement, Whitespace,
};
use hurl_core::ast::{Filter, FilterValue, SourceInfo, Template, TemplateElement, Whitespace};
use hurl_core::reader::Pos;
use std::collections::HashMap;
#[test]

View File

@ -46,7 +46,8 @@ pub mod tests {
use crate::runner::filter::eval::eval_filter;
use crate::runner::{Number, RunnerErrorKind, Value};
use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo};
use hurl_core::ast::{Filter, FilterValue, SourceInfo};
use hurl_core::reader::Pos;
use std::collections::HashMap;
#[test]

View File

@ -47,7 +47,8 @@ pub mod tests {
use crate::runner::filter::eval::eval_filter;
use crate::runner::{Number, RunnerErrorKind, Value};
use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo};
use hurl_core::ast::{Filter, FilterValue, SourceInfo};
use hurl_core::reader::Pos;
use std::collections::HashMap;
#[test]

View File

@ -48,10 +48,10 @@ pub fn eval_url_encode(
#[cfg(test)]
pub mod tests {
use crate::runner::filter::eval::eval_filter;
use crate::runner::Value;
use hurl_core::ast::{Filter, FilterValue, Pos, SourceInfo};
use hurl_core::ast::{Filter, FilterValue, SourceInfo};
use hurl_core::reader::Pos;
use std::collections::HashMap;
#[test]

View File

@ -178,6 +178,7 @@ fn encode_json_char(c: char) -> String {
#[cfg(test)]
mod tests {
use hurl_core::ast::*;
use hurl_core::reader::Pos;
use super::super::error::RunnerErrorKind;
use super::*;

View File

@ -60,9 +60,10 @@ mod tests {
use std::collections::HashMap;
use hurl_core::ast::{
GraphQl, GraphQlVariables, JsonObjectElement, JsonValue, MultilineString, Pos, SourceInfo,
GraphQl, GraphQlVariables, JsonObjectElement, JsonValue, MultilineString, SourceInfo,
Template, TemplateElement, Whitespace,
};
use hurl_core::reader::Pos;
use crate::runner::multiline::eval_multiline;

View File

@ -95,6 +95,7 @@ pub fn file_value_content_type(
#[cfg(test)]
mod tests {
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
use super::*;

View File

@ -444,7 +444,8 @@ fn eval_number(number: &AstNumber) -> Value {
#[cfg(test)]
mod tests {
use hurl_core::ast::{Expr, Pos, SourceInfo, Variable, Whitespace};
use hurl_core::ast::{Expr, SourceInfo, Variable, Whitespace};
use hurl_core::reader::Pos;
use super::*;
use crate::runner::RunnerErrorKind;

View File

@ -19,6 +19,7 @@ use std::cmp::Ordering;
use std::collections::HashMap;
use hurl_core::ast::*;
use hurl_core::reader::Pos;
use crate::runner::error::RunnerError;
use crate::runner::predicate_value::{eval_predicate_value, eval_predicate_value_template};

View File

@ -354,7 +354,8 @@ impl Value {
pub mod tests {
use crate::http::{HeaderVec, HttpError, HttpVersion};
use hex_literal::hex;
use hurl_core::ast::{Pos, SourceInfo};
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
use super::*;

View File

@ -167,6 +167,7 @@ fn eval_method(method: &Method) -> http::Method {
#[cfg(test)]
mod tests {
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
use super::super::error::RunnerErrorKind;
use super::*;

View File

@ -366,6 +366,7 @@ mod tests {
use self::super::super::{assert, capture};
use super::*;
use crate::runner::Number;
use hurl_core::reader::Pos;
pub fn user_response() -> Response {
let whitespace = Whitespace {

View File

@ -15,7 +15,8 @@
* limitations under the License.
*
*/
use hurl_core::ast::{Pos, SourceInfo};
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
use crate::http::{Call, Cookie};
use crate::runner::error::RunnerError;

View File

@ -93,6 +93,7 @@ impl Value {
#[cfg(test)]
mod tests {
use hurl_core::ast::SourceInfo;
use hurl_core::reader::Pos;
use super::*;
use crate::runner::Number;

View File

@ -16,6 +16,7 @@
*
*/
use crate::ast::json;
use crate::reader::Pos;
use crate::typing::{Repeat, Retry};
///
@ -665,18 +666,6 @@ impl PartialEq for Regex {
}
impl Eq for Regex {}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Pos {
pub line: usize,
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,

View File

@ -290,6 +290,7 @@ impl PredicateFuncValue {
#[cfg(test)]
mod tests {
use super::*;
use crate::reader::Pos;
fn whitespace() -> Whitespace {
Whitespace {

View File

@ -216,7 +216,8 @@ impl TemplateElement {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::{Pos, SourceInfo, TemplateElement, Variable, Whitespace};
use crate::ast::{SourceInfo, TemplateElement, Variable, Whitespace};
use crate::reader::Pos;
#[test]
fn test_to_string() {

View File

@ -278,7 +278,7 @@ pub fn add_source_line(text: &mut StyledString, content: &[&str], line: usize) {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::Pos;
use crate::reader::Pos;
use crate::text::Style;
#[test]

View File

@ -916,6 +916,7 @@ fn pop_str(string: &mut String, suffix: &str) {
#[cfg(test)]
mod tests {
use super::*;
use crate::reader::Pos;
#[test]
fn test_multiline_string() {

View File

@ -77,6 +77,7 @@ fn string_bytes(reader: &mut Reader) -> ParseResult<Bytes> {
mod tests {
use super::super::error::*;
use super::*;
use crate::reader::Pos;
#[test]
fn test_bytes_json() {

View File

@ -69,7 +69,8 @@ fn cookiepath_attribute_name(reader: &mut Reader) -> ParseResult<CookieAttribute
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::{Pos, SourceInfo};
use crate::ast::SourceInfo;
use crate::reader::Pos;
#[test]
fn test_cookiepath_simple() {

View File

@ -15,11 +15,13 @@
* limitations under the License.
*
*/
use crate::ast::{Pos, SourceInfo};
use crate::error::DisplaySourceError;
use crate::text::{Style, StyledString};
use std::cmp;
use crate::ast::SourceInfo;
use crate::error::DisplaySourceError;
use crate::reader::Pos;
use crate::text::{Style, StyledString};
/// Represents a parser error.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ParseError {

View File

@ -69,7 +69,7 @@ fn variable_name(reader: &mut Reader) -> ParseResult<Variable> {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::Pos;
use crate::reader::Pos;
#[test]
fn test_expr() {

View File

@ -150,7 +150,7 @@ fn filename_escaped_char(reader: &mut Reader) -> ParseResult<char> {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::Pos;
use crate::reader::Pos;
#[test]
fn test_filename() {

View File

@ -157,7 +157,7 @@ fn filename_password_escaped_char(reader: &mut Reader) -> ParseResult<char> {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::Pos;
use crate::reader::Pos;
#[test]
fn test_filename_with_password() {

View File

@ -207,8 +207,8 @@ fn xpath_filter(reader: &mut Reader) -> ParseResult<FilterValue> {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::Pos;
use crate::parser::ParseErrorKind;
use crate::reader::Pos;
#[test]
fn test_count() {

View File

@ -15,13 +15,13 @@
* limitations under the License.
*
*/
use crate::ast::{JsonListElement, JsonObjectElement, JsonValue, Pos, SourceInfo, Template};
use crate::ast::{JsonListElement, JsonObjectElement, JsonValue, SourceInfo, Template};
use crate::parser::combinators::*;
use crate::parser::error::*;
use crate::parser::primitives::*;
use crate::parser::template::*;
use crate::parser::{expr, ParseResult};
use crate::reader::Reader;
use crate::reader::{Pos, Reader};
pub fn parse(reader: &mut Reader) -> ParseResult<JsonValue> {
choice(

View File

@ -151,8 +151,8 @@ fn key_string_escaped_char(reader: &mut Reader) -> ParseResult<char> {
#[cfg(test)]
mod tests {
use super::*;
use crate::reader::Pos;
#[test]
fn test_key_string() {

View File

@ -263,6 +263,7 @@ fn oneline_string_value(reader: &mut Reader) -> ParseResult<Template> {
#[cfg(test)]
mod tests {
use super::*;
use crate::reader::Pos;
#[test]
fn test_multiline_string_text() {

View File

@ -125,7 +125,7 @@ pub fn number(reader: &mut Reader) -> ParseResult<Number> {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::Pos;
use crate::reader::Pos;
#[test]
fn test_natural() {

View File

@ -418,7 +418,7 @@ fn variable_value(reader: &mut Reader) -> ParseResult<VariableValue> {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::Pos;
use crate::reader::Pos;
#[test]
fn test_option_insecure() {

View File

@ -195,6 +195,7 @@ fn body(reader: &mut Reader) -> ParseResult<Body> {
#[cfg(test)]
mod tests {
use super::*;
use crate::reader::Pos;
#[test]
fn test_hurl_file() {

View File

@ -382,7 +382,7 @@ fn is_number_predicate(reader: &mut Reader) -> ParseResult<PredicateFuncValue> {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::Pos;
use crate::reader::Pos;
#[test]
fn test_predicate_not() {

View File

@ -85,6 +85,7 @@ mod tests {
use super::*;
use crate::parser::ParseErrorKind;
use crate::reader::Pos;
#[test]
fn test_predicate_value() {

View File

@ -444,7 +444,7 @@ pub fn hex_digit(reader: &mut Reader) -> ParseResult<u32> {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::Pos;
use crate::reader::Pos;
#[test]
fn test_space() {

View File

@ -21,7 +21,7 @@ use crate::parser::cookiepath::cookiepath;
use crate::parser::primitives::*;
use crate::parser::string::*;
use crate::parser::{ParseError, ParseErrorKind, ParseResult};
use crate::reader::Reader;
use crate::reader::{Pos, Reader};
pub fn query(reader: &mut Reader) -> ParseResult<Query> {
let start = reader.state.pos;

View File

@ -24,7 +24,7 @@ use crate::parser::primitives::*;
use crate::parser::query::query;
use crate::parser::string::*;
use crate::parser::{filename, key_string, option, ParseResult};
use crate::reader::Reader;
use crate::reader::{Pos, Reader};
pub fn request_sections(reader: &mut Reader) -> ParseResult<Vec<Section>> {
let sections = zero_or_more(request_section, reader)?;
@ -320,7 +320,6 @@ fn assert(reader: &mut Reader) -> ParseResult<Assert> {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::Pos;
#[test]
fn test_section_name() {

View File

@ -253,6 +253,7 @@ fn hex_value(reader: &mut Reader) -> ParseResult<u32> {
#[cfg(test)]
mod tests {
use crate::reader::Pos;
use std::time::SystemTime;
use super::*;

View File

@ -15,10 +15,10 @@
* limitations under the License.
*
*/
use crate::ast::{Expr, Pos, SourceInfo, TemplateElement};
use crate::ast::{Expr, SourceInfo, TemplateElement};
use crate::parser::primitives::{literal, try_literal};
use crate::parser::{error, expr, ParseResult};
use crate::reader::{Reader, ReaderState};
use crate::reader::{Pos, Reader, ReaderState};
pub struct EncodedString {
pub source_info: SourceInfo,

View File

@ -129,6 +129,7 @@ fn url_prefix_valid(reader: &mut Reader) -> bool {
#[cfg(test)]
mod tests {
use super::*;
use crate::reader::Pos;
#[test]
fn test_url() {

View File

@ -214,7 +214,7 @@ unsafe extern "C" fn on_end_element(
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::Pos;
use crate::reader::Pos;
#[test]
fn parse_xml_brute_force_errors() {

View File

@ -17,8 +17,6 @@
*/
use std::cmp::min;
use crate::ast::Pos;
/// Represents a text reader.
///
/// The `Reader` implements methods to read a stream of text. A reader manages
@ -43,6 +41,22 @@ pub struct Reader {
pub state: ReaderState,
}
/// Represents a line and column position in a reader.
///
/// Index are 1-based.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Pos {
pub line: usize,
pub column: usize,
}
impl Pos {
/// Creates a new position.
pub fn new(line: usize, column: usize) -> Pos {
Pos { line, column }
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct ReaderState {
pub cursor: usize,

View File

@ -779,6 +779,7 @@ impl ToJson for Comment {
#[cfg(test)]
pub mod tests {
use super::*;
use hurl_core::reader::Pos;
fn whitespace() -> Whitespace {
Whitespace {

View File

@ -16,6 +16,7 @@
*
*/
use hurl_core::ast::*;
use hurl_core::reader::Pos;
use crate::linter::core::{Error, LinterError};

View File

@ -20,7 +20,7 @@ use std::fs;
use hurl_core::ast::*;
use hurl_core::parser::parse_json;
use hurl_core::reader::Reader;
use hurl_core::reader::{Pos, Reader};
use hurlfmt::format::{Token, Tokenizable};
use proptest::prelude::prop::test_runner::TestRunner;
use proptest::prelude::*;