From 76b45a1ed1b2c7ab88ae2a1a3d86a5ebf41d74fa Mon Sep 17 00:00:00 2001 From: Jean-Christophe Amiel Date: Mon, 1 Jul 2024 15:52:13 +0200 Subject: [PATCH] Make Reader fields private. --- packages/hurl/src/jsonpath/parser/parse.rs | 92 +++++++------- .../hurl/src/jsonpath/parser/primitives.rs | 50 ++++---- packages/hurl/src/runner/json.rs | 6 +- packages/hurl_core/src/combinator.rs | 18 ++- packages/hurl_core/src/parser/base64.rs | 22 ++-- packages/hurl_core/src/parser/bytes.rs | 10 +- packages/hurl_core/src/parser/cookiepath.rs | 14 +-- packages/hurl_core/src/parser/expr.rs | 4 +- packages/hurl_core/src/parser/filename.rs | 24 ++-- .../hurl_core/src/parser/filename_password.rs | 18 ++- packages/hurl_core/src/parser/filter.rs | 13 +- packages/hurl_core/src/parser/json.rs | 110 ++++++++--------- packages/hurl_core/src/parser/key_string.rs | 41 +++---- packages/hurl_core/src/parser/multiline.rs | 56 ++++----- packages/hurl_core/src/parser/number.rs | 42 +++---- packages/hurl_core/src/parser/option.rs | 30 ++--- packages/hurl_core/src/parser/parsers.rs | 68 +++++------ packages/hurl_core/src/parser/predicate.rs | 32 ++--- packages/hurl_core/src/parser/primitives.rs | 106 ++++++++--------- packages/hurl_core/src/parser/query.rs | 18 +-- packages/hurl_core/src/parser/sections.rs | 53 ++++----- packages/hurl_core/src/parser/string.rs | 112 ++++++++---------- packages/hurl_core/src/parser/template.rs | 8 +- packages/hurl_core/src/parser/url.rs | 35 +++--- packages/hurl_core/src/parser/xml.rs | 24 ++-- packages/hurl_core/src/reader.rs | 78 +++++++----- 26 files changed, 533 insertions(+), 551 deletions(-) diff --git a/packages/hurl/src/jsonpath/parser/parse.rs b/packages/hurl/src/jsonpath/parser/parse.rs index ef98b56fa..5c4f2b170 100644 --- a/packages/hurl/src/jsonpath/parser/parse.rs +++ b/packages/hurl/src/jsonpath/parser/parse.rs @@ -34,7 +34,7 @@ fn query(reader: &mut Reader) -> ParseResult { let selectors = zero_or_more(selector, reader)?; if !reader.is_eof() { let kind = ParseErrorKind::Expecting("eof".to_string()); - let error = ParseError::new(reader.cursor.pos, false, kind); + let error = ParseError::new(reader.cursor().pos, false, kind); return Err(error); } Ok(Query { selectors }) @@ -58,7 +58,7 @@ fn selector(reader: &mut Reader) -> ParseResult { } fn selector_array_index_or_array_indices(reader: &mut Reader) -> Result { - let initial_state = reader.cursor; + let initial_state = reader.cursor(); try_left_bracket(reader)?; let mut indexes = vec![]; let i = match natural(reader) { @@ -70,7 +70,7 @@ fn selector_array_index_or_array_indices(reader: &mut Reader) -> Result { @@ -80,15 +80,15 @@ fn selector_array_index_or_array_indices(reader: &mut Reader) -> Result Result fn selector_array_slice(reader: &mut Reader) -> Result { try_left_bracket(reader)?; - let state = reader.cursor; + let save = reader.cursor(); let start = match integer(reader) { Err(_) => { - reader.cursor = state; + reader.seek(save); None } Ok(v) => Some(v), }; if try_literal(":", reader).is_err() { let kind = ParseErrorKind::Expecting(":".to_string()); - let error = ParseError::new(state.pos, true, kind); + let error = ParseError::new(save.pos, true, kind); return Err(error); }; - let state = reader.cursor; + let save = reader.cursor(); let end = match integer(reader) { Err(_) => { - reader.cursor = state; + reader.seek(save); None } Ok(v) => Some(v), @@ -145,7 +145,7 @@ fn selector_object_key_bracket(reader: &mut Reader) -> Result { let kind = ParseErrorKind::Expecting("value string".to_string()); - let error = ParseError::new(reader.cursor.pos, true, kind); + let error = ParseError::new(reader.cursor().pos, true, kind); Err(error) } Ok(v) => { @@ -158,7 +158,7 @@ fn selector_object_key_bracket(reader: &mut Reader) -> Result Result { if reader.peek() != Some('.') { let kind = ParseErrorKind::Expecting("[ or .".to_string()); - let error = ParseError::new(reader.cursor.pos, true, kind); + let error = ParseError::new(reader.cursor().pos, true, kind); return Err(error); }; _ = reader.read(); @@ -166,7 +166,7 @@ fn selector_object_key(reader: &mut Reader) -> Result { let s = reader.read_while(|c| c.is_alphanumeric() || *c == '_' || *c == '-'); if s.is_empty() { let kind = ParseErrorKind::Expecting("empty value".to_string()); - let error = ParseError::new(reader.cursor.pos, false, kind); + let error = ParseError::new(reader.cursor().pos, false, kind); return Err(error); } Ok(Selector::NameChild(s)) @@ -189,9 +189,9 @@ fn selector_recursive_key(reader: &mut Reader) -> Result { } fn try_left_bracket(reader: &mut Reader) -> Result<(), ParseError> { - let start = reader.cursor; + let start = reader.cursor(); if literal(".[", reader).is_err() { - reader.cursor = start; + reader.seek(start); try_literal("[", reader)?; } Ok(()) @@ -209,11 +209,11 @@ fn predicate(reader: &mut Reader) -> ParseResult { // @.key>=value GreaterThanOrEqual(Key, Value) literal("@.", reader)?; // assume key value for the time being let key = key_path(reader)?; - let state = reader.cursor; + let save = reader.cursor(); let func = match predicate_func(reader) { Ok(f) => f, Err(_) => { - reader.cursor = state; + reader.seek(save); PredicateFunc::KeyExist } }; @@ -291,11 +291,11 @@ mod tests { let mut reader = Reader::new("[xxx"); assert!(try_left_bracket(&mut reader).is_ok()); - assert_eq!(reader.cursor.offset, 1); + assert_eq!(reader.cursor().offset, 1); let mut reader = Reader::new(".[xxx"); assert!(try_left_bracket(&mut reader).is_ok()); - assert_eq!(reader.cursor.offset, 2); + assert_eq!(reader.cursor().offset, 2); } #[test] @@ -372,7 +372,7 @@ mod tests { func: PredicateFunc::KeyExist, }) ); - assert_eq!(reader.cursor.offset, 11); + assert_eq!(reader.cursor().offset, 11); // Filter equal on string with single quotes let mut reader = Reader::new("[?(@.key=='value')]"); @@ -383,7 +383,7 @@ mod tests { func: PredicateFunc::EqualString("value".to_string()), }) ); - assert_eq!(reader.cursor.offset, 19); + assert_eq!(reader.cursor().offset, 19); let mut reader = Reader::new(".[?(@.key=='value')]"); assert_eq!( selector(&mut reader).unwrap(), @@ -392,7 +392,7 @@ mod tests { func: PredicateFunc::EqualString("value".to_string()), }) ); - assert_eq!(reader.cursor.offset, 20); + assert_eq!(reader.cursor().offset, 20); let mut reader = Reader::new("[?(@.price<10)]"); assert_eq!( @@ -405,7 +405,7 @@ mod tests { }), }) ); - assert_eq!(reader.cursor.offset, 15); + assert_eq!(reader.cursor().offset, 15); } #[test] @@ -415,40 +415,40 @@ mod tests { selector(&mut reader).unwrap(), Selector::RecursiveKey("book".to_string()) ); - assert_eq!(reader.cursor.offset, 6); + assert_eq!(reader.cursor().offset, 6); } #[test] pub fn test_selector_array_index() { let mut reader = Reader::new("[2]"); assert_eq!(selector(&mut reader).unwrap(), Selector::ArrayIndex(2)); - assert_eq!(reader.cursor.offset, 3); + assert_eq!(reader.cursor().offset, 3); let mut reader = Reader::new("[0,1]"); assert_eq!( selector(&mut reader).unwrap(), Selector::ArrayIndices(vec![0, 1]) ); - assert_eq!(reader.cursor.offset, 5); + assert_eq!(reader.cursor().offset, 5); // you don't need to keep the exact string // this is not part of the AST let mut reader = Reader::new(".[2]"); assert_eq!(selector(&mut reader).unwrap(), Selector::ArrayIndex(2)); - assert_eq!(reader.cursor.offset, 4); + assert_eq!(reader.cursor().offset, 4); } #[test] pub fn test_selector_wildcard() { let mut reader = Reader::new("[*]"); assert_eq!(selector(&mut reader).unwrap(), Selector::ArrayWildcard); - assert_eq!(reader.cursor.offset, 3); + assert_eq!(reader.cursor().offset, 3); // you don't need to keep the exact string // this is not part of the AST let mut reader = Reader::new(".[*]"); assert_eq!(selector(&mut reader).unwrap(), Selector::ArrayWildcard); - assert_eq!(reader.cursor.offset, 4); + assert_eq!(reader.cursor().offset, 4); } #[test] @@ -461,7 +461,7 @@ mod tests { end: None }) ); - assert_eq!(reader.cursor.offset, 4); + assert_eq!(reader.cursor().offset, 4); let mut reader = Reader::new("[-1:]"); assert_eq!( @@ -471,7 +471,7 @@ mod tests { end: None }) ); - assert_eq!(reader.cursor.offset, 5); + assert_eq!(reader.cursor().offset, 5); let mut reader = Reader::new("[:2]"); assert_eq!( @@ -481,7 +481,7 @@ mod tests { end: Some(2) }) ); - assert_eq!(reader.cursor.offset, 4); + assert_eq!(reader.cursor().offset, 4); } #[test] @@ -491,21 +491,21 @@ mod tests { selector(&mut reader).unwrap(), Selector::NameChild("key".to_string()) ); - assert_eq!(reader.cursor.offset, 7); + assert_eq!(reader.cursor().offset, 7); let mut reader = Reader::new(".['key']"); assert_eq!( selector(&mut reader).unwrap(), Selector::NameChild("key".to_string()) ); - assert_eq!(reader.cursor.offset, 8); + assert_eq!(reader.cursor().offset, 8); let mut reader = Reader::new("['key1']"); assert_eq!( selector(&mut reader).unwrap(), Selector::NameChild("key1".to_string()) ); - assert_eq!(reader.cursor.offset, 8); + assert_eq!(reader.cursor().offset, 8); } #[test] @@ -515,14 +515,14 @@ mod tests { selector(&mut reader).unwrap(), Selector::NameChild("key".to_string()) ); - assert_eq!(reader.cursor.offset, 4); + assert_eq!(reader.cursor().offset, 4); let mut reader = Reader::new(".key1"); assert_eq!( selector(&mut reader).unwrap(), Selector::NameChild("key1".to_string()) ); - assert_eq!(reader.cursor.offset, 5); + assert_eq!(reader.cursor().offset, 5); } #[test] @@ -583,7 +583,7 @@ mod tests { predicate_func(&mut reader).unwrap(), PredicateFunc::Equal(Number { int: 2, decimal: 0 }) ); - assert_eq!(reader.cursor.offset, 3); + assert_eq!(reader.cursor().offset, 3); let mut reader = Reader::new("==2.1"); assert_eq!( @@ -593,7 +593,7 @@ mod tests { decimal: 100_000_000_000_000_000 }) ); - assert_eq!(reader.cursor.offset, 5); + assert_eq!(reader.cursor().offset, 5); let mut reader = Reader::new("== 2.1 "); assert_eq!( @@ -603,41 +603,41 @@ mod tests { decimal: 100_000_000_000_000_000 }) ); - assert_eq!(reader.cursor.offset, 7); + assert_eq!(reader.cursor().offset, 7); let mut reader = Reader::new("=='hello'"); assert_eq!( predicate_func(&mut reader).unwrap(), PredicateFunc::EqualString("hello".to_string()) ); - assert_eq!(reader.cursor.offset, 9); + assert_eq!(reader.cursor().offset, 9); let mut reader = Reader::new(">5"); assert_eq!( predicate_func(&mut reader).unwrap(), PredicateFunc::GreaterThan(Number { int: 5, decimal: 0 }) ); - assert_eq!(reader.cursor.offset, 2); + assert_eq!(reader.cursor().offset, 2); let mut reader = Reader::new(">=5"); assert_eq!( predicate_func(&mut reader).unwrap(), PredicateFunc::GreaterThanOrEqual(Number { int: 5, decimal: 0 }) ); - assert_eq!(reader.cursor.offset, 3); + assert_eq!(reader.cursor().offset, 3); let mut reader = Reader::new("<5"); assert_eq!( predicate_func(&mut reader).unwrap(), PredicateFunc::LessThan(Number { int: 5, decimal: 0 }) ); - assert_eq!(reader.cursor.offset, 2); + assert_eq!(reader.cursor().offset, 2); let mut reader = Reader::new("<=5"); assert_eq!( predicate_func(&mut reader).unwrap(), PredicateFunc::LessThanOrEqual(Number { int: 5, decimal: 0 }) ); - assert_eq!(reader.cursor.offset, 3); + assert_eq!(reader.cursor().offset, 3); } } diff --git a/packages/hurl/src/jsonpath/parser/primitives.rs b/packages/hurl/src/jsonpath/parser/primitives.rs index d551dbbbe..97d135d78 100644 --- a/packages/hurl/src/jsonpath/parser/primitives.rs +++ b/packages/hurl/src/jsonpath/parser/primitives.rs @@ -20,7 +20,7 @@ use crate::jsonpath::parser::error::{ParseError, ParseErrorKind, ParseResult}; use hurl_core::reader::Reader; pub fn natural(reader: &mut Reader) -> ParseResult { - let start = reader.cursor; + let start = reader.cursor(); if reader.is_eof() { let kind = ParseErrorKind::Expecting("natural".to_string()); @@ -34,7 +34,7 @@ pub fn natural(reader: &mut Reader) -> ParseResult { return Err(error); } - let save = reader.cursor; + let save = reader.cursor(); let s = reader.read_while(|c| c.is_ascii_digit()); // if the first digit is zero, you should not have any more digits @@ -64,14 +64,14 @@ pub fn number(reader: &mut Reader) -> ParseResult { _ = reader.read(); if reader.is_eof() { let kind = ParseErrorKind::Expecting("natural".to_string()); - let error = ParseError::new(reader.cursor.pos, false, kind); + let error = ParseError::new(reader.cursor().pos, false, kind); return Err(error); } let s = reader.read_while(|c| c.is_ascii_digit()); if s.is_empty() { let kind = ParseErrorKind::Expecting("natural".to_string()); - let error = ParseError::new(reader.cursor.pos, false, kind); + let error = ParseError::new(reader.cursor().pos, false, kind); return Err(error); } format!("{s:0<18}").parse().unwrap() @@ -89,7 +89,7 @@ pub fn string_value(reader: &mut Reader) -> Result { match reader.read() { None => { let kind = ParseErrorKind::Expecting("'".to_string()); - let error = ParseError::new(reader.cursor.pos, false, kind); + let error = ParseError::new(reader.cursor().pos, false, kind); return Err(error); } Some('\'') => break, @@ -101,7 +101,7 @@ pub fn string_value(reader: &mut Reader) -> Result { } _ => { let kind = ParseErrorKind::Expecting("'".to_string()); - let error = ParseError::new(reader.cursor.pos, false, kind); + let error = ParseError::new(reader.cursor().pos, false, kind); return Err(error); } } @@ -126,13 +126,13 @@ pub fn key_name(reader: &mut Reader) -> Result { c } else { let kind = ParseErrorKind::Expecting("key".to_string()); - let error = ParseError::new(reader.cursor.pos, false, kind); + let error = ParseError::new(reader.cursor().pos, false, kind); return Err(error); } } None => { let kind = ParseErrorKind::Expecting("key".to_string()); - let error = ParseError::new(reader.cursor.pos, false, kind); + let error = ParseError::new(reader.cursor().pos, false, kind); return Err(error); } }; @@ -157,7 +157,7 @@ pub fn literal(s: &str, reader: &mut Reader) -> ParseResult<()> { // does not return a value // non recoverable reader // => use combinator recover to make it recoverable - let start = reader.cursor; + let start = reader.cursor(); if reader.is_eof() { let kind = ParseErrorKind::Expecting(s.to_string()); let error = ParseError::new(start.pos, false, kind); @@ -211,15 +211,15 @@ mod tests { fn test_natural() { let mut reader = Reader::new("0"); assert_eq!(natural(&mut reader).unwrap(), 0); - assert_eq!(reader.cursor.offset, 1); + assert_eq!(reader.cursor().offset, 1); let mut reader = Reader::new("0."); assert_eq!(natural(&mut reader).unwrap(), 0); - assert_eq!(reader.cursor.offset, 1); + assert_eq!(reader.cursor().offset, 1); let mut reader = Reader::new("10x"); assert_eq!(natural(&mut reader).unwrap(), 10); - assert_eq!(reader.cursor.offset, 2); + assert_eq!(reader.cursor().offset, 2); } #[test] @@ -265,11 +265,11 @@ mod tests { fn test_number() { let mut reader = Reader::new("1"); assert_eq!(number(&mut reader).unwrap(), Number { int: 1, decimal: 0 }); - assert_eq!(reader.cursor.offset, 1); + assert_eq!(reader.cursor().offset, 1); let mut reader = Reader::new("1.0"); assert_eq!(number(&mut reader).unwrap(), Number { int: 1, decimal: 0 }); - assert_eq!(reader.cursor.offset, 3); + assert_eq!(reader.cursor().offset, 3); let mut reader = Reader::new("-1.0"); assert_eq!( @@ -279,7 +279,7 @@ mod tests { decimal: 0 } ); - assert_eq!(reader.cursor.offset, 4); + assert_eq!(reader.cursor().offset, 4); let mut reader = Reader::new("1.1"); assert_eq!( @@ -289,7 +289,7 @@ mod tests { decimal: 100_000_000_000_000_000 } ); - assert_eq!(reader.cursor.offset, 3); + assert_eq!(reader.cursor().offset, 3); let mut reader = Reader::new("1.100"); assert_eq!( @@ -299,7 +299,7 @@ mod tests { decimal: 100_000_000_000_000_000 } ); - assert_eq!(reader.cursor.offset, 5); + assert_eq!(reader.cursor().offset, 5); let mut reader = Reader::new("1.01"); assert_eq!( @@ -309,7 +309,7 @@ mod tests { decimal: 10_000_000_000_000_000 } ); - assert_eq!(reader.cursor.offset, 4); + assert_eq!(reader.cursor().offset, 4); let mut reader = Reader::new("1.010"); assert_eq!( @@ -319,7 +319,7 @@ mod tests { decimal: 10_000_000_000_000_000 } ); - assert_eq!(reader.cursor.offset, 5); + assert_eq!(reader.cursor().offset, 5); let mut reader = Reader::new("-0.333333333333333333"); assert_eq!( @@ -329,7 +329,7 @@ mod tests { decimal: 333_333_333_333_333_333 } ); - assert_eq!(reader.cursor.offset, 21); + assert_eq!(reader.cursor().offset, 21); } #[test] @@ -415,28 +415,28 @@ mod tests { fn test_literal() { let mut reader = Reader::new("hello"); assert_eq!(literal("hello", &mut reader), Ok(())); - assert_eq!(reader.cursor.offset, 5); + assert_eq!(reader.cursor().offset, 5); let mut reader = Reader::new("hello "); assert_eq!(literal("hello", &mut reader), Ok(())); - assert_eq!(reader.cursor.offset, 6); + assert_eq!(reader.cursor().offset, 6); let mut reader = Reader::new(""); let error = literal("hello", &mut reader).err().unwrap(); assert_eq!(error.pos, Pos { line: 1, column: 1 }); assert_eq!(error.kind, ParseErrorKind::Expecting("hello".to_string())); - assert_eq!(reader.cursor.offset, 0); + assert_eq!(reader.cursor().offset, 0); let mut reader = Reader::new("hi"); let error = literal("hello", &mut reader).err().unwrap(); assert_eq!(error.pos, Pos { line: 1, column: 1 }); assert_eq!(error.kind, ParseErrorKind::Expecting("hello".to_string())); - assert_eq!(reader.cursor.offset, 2); + assert_eq!(reader.cursor().offset, 2); let mut reader = Reader::new("he"); let error = literal("hello", &mut reader).err().unwrap(); assert_eq!(error.pos, Pos { line: 1, column: 1 }); assert_eq!(error.kind, ParseErrorKind::Expecting("hello".to_string())); - assert_eq!(reader.cursor.offset, 2); + assert_eq!(reader.cursor().offset, 2); } } diff --git a/packages/hurl/src/runner/json.rs b/packages/hurl/src/runner/json.rs index 1ab513d36..1d515f614 100644 --- a/packages/hurl/src/runner/json.rs +++ b/packages/hurl/src/runner/json.rs @@ -71,15 +71,15 @@ pub fn eval_json_value( // The String can only be null, a bool, a number // It will be easier when your variables value have a type let mut reader = Reader::new(s.as_str()); - let start = reader.cursor; + let start = reader.cursor(); if parse_json_number(&mut reader).is_ok() { return Ok(s); } - reader.cursor = start; + reader.seek(start); if parse_json_boolean(&mut reader).is_ok() { return Ok(s); } - reader.cursor = start; + reader.seek(start); if parse_json_null(&mut reader).is_ok() { return Ok(s); } diff --git a/packages/hurl_core/src/combinator.rs b/packages/hurl_core/src/combinator.rs index afeb7f82b..5925725e3 100644 --- a/packages/hurl_core/src/combinator.rs +++ b/packages/hurl_core/src/combinator.rs @@ -38,12 +38,12 @@ pub fn optional(f: ParseFunc, reader: &mut Reader) -> Result Ok(Some(r)), Err(e) => { if e.is_recoverable() { - reader.cursor = start; + reader.seek(start); Ok(None) } else { Err(e) @@ -81,7 +81,7 @@ where { let mut v = Vec::new(); loop { - let initial_state = reader.cursor; + let initial_state = reader.cursor(); if reader.is_eof() { return Ok(v); } @@ -92,8 +92,7 @@ where } Err(e) => { return if e.is_recoverable() { - reader.cursor.pos = initial_state.pos; - reader.cursor.offset = initial_state.offset; + reader.seek(initial_state); Ok(v) } else { Err(e) @@ -112,15 +111,14 @@ where Ok(first) => { let mut v = vec![first]; loop { - let initial_state = reader.cursor; + let initial_state = reader.cursor(); match f(reader) { Ok(r) => { v.push(r); } Err(e) => { return if e.is_recoverable() { - reader.cursor.pos = initial_state.pos; - reader.cursor.offset = initial_state.offset; + reader.seek(initial_state); Ok(v) } else { Err(e) @@ -141,13 +139,13 @@ where E: ParseError, { for (pos, f) in fs.iter().enumerate() { - let start = reader.cursor; + let start = reader.cursor(); if pos == fs.len() - 1 { return f(reader); } match f(reader) { Err(err) if err.is_recoverable() => { - reader.cursor = start; + reader.seek(start); continue; } x => return x, diff --git a/packages/hurl_core/src/parser/base64.rs b/packages/hurl_core/src/parser/base64.rs index c31692983..66c84530f 100644 --- a/packages/hurl_core/src/parser/base64.rs +++ b/packages/hurl_core/src/parser/base64.rs @@ -31,7 +31,7 @@ pub fn parse(reader: &mut Reader) -> Vec { if !pad.is_empty() { break; } - let save = reader.cursor; + let save = reader.cursor(); match reader.read() { None => { break; @@ -39,7 +39,7 @@ pub fn parse(reader: &mut Reader) -> Vec { Some(' ') | Some('\n') | Some('\t') => {} Some(c) => match value(c) { None => { - reader.cursor = save; + reader.seek(save); break; } Some(v) => { @@ -142,13 +142,13 @@ fn padding(reader: &mut Reader) -> String { // consume padding can not fail let mut buf = String::new(); loop { - let save = reader.cursor; + let save = reader.cursor(); match reader.read() { Some('=') => { buf.push('='); } _ => { - reader.cursor = save; + reader.seek(save); break; } } @@ -183,27 +183,27 @@ mod tests { fn test_decode_one_block() { let mut reader = Reader::new(""); assert_eq!(parse(&mut reader), vec![] as Vec); - assert_eq!(reader.cursor.offset, 0); + assert_eq!(reader.cursor().offset, 0); let mut reader = Reader::new("AA==;"); assert_eq!(parse(&mut reader), vec![0]); - assert_eq!(reader.cursor.offset, 4); + assert_eq!(reader.cursor().offset, 4); let mut reader = Reader::new("AA"); assert_eq!(parse(&mut reader), vec![0]); - assert_eq!(reader.cursor.offset, 2); + assert_eq!(reader.cursor().offset, 2); let mut reader = Reader::new("AA;"); assert_eq!(parse(&mut reader), vec![0]); - assert_eq!(reader.cursor.offset, 2); + assert_eq!(reader.cursor().offset, 2); let mut reader = Reader::new("TWE=;"); assert_eq!(parse(&mut reader), vec![77, 97]); - assert_eq!(reader.cursor.offset, 4); + assert_eq!(reader.cursor().offset, 4); let mut reader = Reader::new("TWFu;"); assert_eq!(parse(&mut reader), vec![77, 97, 110]); - assert_eq!(reader.cursor.offset, 4); + assert_eq!(reader.cursor().offset, 4); } /* @@ -246,7 +246,7 @@ mod tests { fn test_decode_with_whitespace() { let mut reader = Reader::new("TW E=\n;"); assert_eq!(parse(&mut reader), vec![77, 97]); - assert_eq!(reader.cursor.offset, 5); + assert_eq!(reader.cursor().offset, 5); } #[test] diff --git a/packages/hurl_core/src/parser/bytes.rs b/packages/hurl_core/src/parser/bytes.rs index 5bb834f07..ddc63f155 100644 --- a/packages/hurl_core/src/parser/bytes.rs +++ b/packages/hurl_core/src/parser/bytes.rs @@ -105,7 +105,7 @@ mod tests { ], }) ); - assert_eq!(reader.cursor.offset, 7); + assert_eq!(reader.cursor().offset, 7); let mut reader = Reader::new("{ } "); assert_eq!( @@ -115,14 +115,14 @@ mod tests { elements: vec![], }) ); - assert_eq!(reader.cursor.offset, 3); + assert_eq!(reader.cursor().offset, 3); let mut reader = Reader::new("true"); assert_eq!( bytes(&mut reader).unwrap(), Bytes::Json(JsonValue::Boolean(true)) ); - assert_eq!(reader.cursor.offset, 4); + assert_eq!(reader.cursor().offset, 4); let mut reader = Reader::new("\"\" x"); assert_eq!( @@ -133,7 +133,7 @@ mod tests { source_info: SourceInfo::new(Pos::new(1, 2), Pos::new(1, 2)), })) ); - assert_eq!(reader.cursor.offset, 2); + assert_eq!(reader.cursor().offset, 2); } #[test] @@ -202,6 +202,6 @@ mod tests { source_info: SourceInfo::new(Pos::new(1, 1), Pos::new(1, 6)) }) ); - assert_eq!(reader.cursor.offset, 5); + assert_eq!(reader.cursor().offset, 5); } } diff --git a/packages/hurl_core/src/parser/cookiepath.rs b/packages/hurl_core/src/parser/cookiepath.rs index ab3ce5c45..95d1bd55f 100644 --- a/packages/hurl_core/src/parser/cookiepath.rs +++ b/packages/hurl_core/src/parser/cookiepath.rs @@ -24,7 +24,7 @@ use crate::parser::ParseResult; use crate::reader::Reader; pub fn cookiepath(reader: &mut Reader) -> ParseResult { - let start = reader.cursor.pos; + let start = reader.cursor().pos; // We create a specialized reader for the templated, error and created structures are // relative tho the main reader. @@ -49,7 +49,7 @@ fn cookiepath_attribute(reader: &mut Reader) -> ParseResult { } fn cookiepath_attribute_name(reader: &mut Reader) -> ParseResult { - let start = reader.cursor.pos; + let start = reader.cursor().pos; let s = reader.read_while(|c| c.is_alphabetic() || *c == '-'); match s.to_lowercase().as_str() { "value" => Ok(CookieAttributeName::Value(s)), @@ -91,7 +91,7 @@ mod tests { attribute: None, } ); - assert_eq!(reader.cursor.offset, 7); + assert_eq!(reader.cursor().offset, 7); } #[test] @@ -121,7 +121,7 @@ mod tests { }), } ); - assert_eq!(reader.cursor.offset, 15); + assert_eq!(reader.cursor().offset, 15); } #[test] @@ -161,7 +161,7 @@ mod tests { }), } ); - assert_eq!(reader.cursor.offset, 16); + assert_eq!(reader.cursor().offset, 16); } #[test] @@ -206,14 +206,14 @@ mod tests { cookiepath_attribute_name(&mut reader).unwrap(), CookieAttributeName::Domain("Domain".to_string()) ); - assert_eq!(reader.cursor.offset, 6); + assert_eq!(reader.cursor().offset, 6); let mut reader = Reader::new("domain"); assert_eq!( cookiepath_attribute_name(&mut reader).unwrap(), CookieAttributeName::Domain("domain".to_string()) ); - assert_eq!(reader.cursor.offset, 6); + assert_eq!(reader.cursor().offset, 6); let mut reader = Reader::new("unknown"); let error = cookiepath_attribute_name(&mut reader).err().unwrap(); diff --git a/packages/hurl_core/src/parser/expr.rs b/packages/hurl_core/src/parser/expr.rs index a81572876..570b5bedf 100644 --- a/packages/hurl_core/src/parser/expr.rs +++ b/packages/hurl_core/src/parser/expr.rs @@ -51,7 +51,7 @@ pub fn parse2(reader: &mut Reader) -> ParseResult { } fn variable_name(reader: &mut Reader) -> ParseResult { - let start = reader.cursor; + let start = reader.cursor(); let name = reader.read_while(|c| c.is_alphanumeric() || *c == '_' || *c == '-'); if name.is_empty() { return Err(ParseError::new( @@ -62,7 +62,7 @@ fn variable_name(reader: &mut Reader) -> ParseResult { } Ok(Variable { name, - source_info: SourceInfo::new(start.pos, reader.cursor.pos), + source_info: SourceInfo::new(start.pos, reader.cursor().pos), }) } diff --git a/packages/hurl_core/src/parser/filename.rs b/packages/hurl_core/src/parser/filename.rs index 0832bdc21..024057711 100644 --- a/packages/hurl_core/src/parser/filename.rs +++ b/packages/hurl_core/src/parser/filename.rs @@ -29,11 +29,11 @@ use crate::reader::Reader; /// This is very similar to the behaviour in a standard shell. /// pub fn parse(reader: &mut Reader) -> ParseResult