diff --git a/packages/hurl/build.rs b/packages/hurl/build.rs index 249bc9c32..1979a828a 100644 --- a/packages/hurl/build.rs +++ b/packages/hurl/build.rs @@ -16,9 +16,9 @@ * */ -use cc::Build; use std::path::Path; +use cc::Build; #[cfg(windows)] use winres::WindowsResource; diff --git a/packages/hurl/src/cli/fs.rs b/packages/hurl/src/cli/fs.rs index 10a3af2ad..b4bd8e3b4 100644 --- a/packages/hurl/src/cli/fs.rs +++ b/packages/hurl/src/cli/fs.rs @@ -15,11 +15,12 @@ * limitations under the License. * */ -use crate::cli::CliError; use std::fs; use std::fs::File; use std::io::prelude::*; +use crate::cli::CliError; + /// Remove BOM from the input bytes fn strip_bom(bytes: &mut Vec) { if bytes.starts_with(&[0xefu8, 0xbb, 0xbf]) { diff --git a/packages/hurl/src/cli/interactive.rs b/packages/hurl/src/cli/interactive.rs index 40a46ad92..7786277a6 100644 --- a/packages/hurl/src/cli/interactive.rs +++ b/packages/hurl/src/cli/interactive.rs @@ -15,11 +15,9 @@ * limitations under the License. * */ - use hurl_core::ast::Entry; #[cfg(target_family = "unix")] use hurl_core::ast::{MultipartParam, Request, SectionValue}; - #[cfg(target_family = "unix")] use { std::io::{stderr, stdin, Write}, diff --git a/packages/hurl/src/cli/mod.rs b/packages/hurl/src/cli/mod.rs index 0c005849c..a54ebb14c 100644 --- a/packages/hurl/src/cli/mod.rs +++ b/packages/hurl/src/cli/mod.rs @@ -20,18 +20,16 @@ mod interactive; mod options; mod variables; -use hurl::{output, report}; use std::error::Error; use std::fmt; +use hurl::{output, report}; + pub use self::fs::read_to_string; -pub use self::options::app; -pub use self::options::output_color; -pub use self::options::parse_options; -pub use self::options::{get_strings, has_flag}; -pub use self::options::{CliOptions, OutputType}; -pub use self::variables::parse as parse_variable; -pub use self::variables::parse_value as parse_variable_value; +pub use self::options::{ + app, get_strings, has_flag, output_color, parse_options, CliOptions, OutputType, +}; +pub use self::variables::{parse as parse_variable, parse_value as parse_variable_value}; #[derive(Clone, Debug, PartialEq, Eq)] pub struct CliError { diff --git a/packages/hurl/src/cli/options.rs b/packages/hurl/src/cli/options.rs index 8c1a9a3b5..9e9181b0d 100644 --- a/packages/hurl/src/cli/options.rs +++ b/packages/hurl/src/cli/options.rs @@ -15,14 +15,6 @@ * limitations under the License. * */ -use crate::cli; -use crate::cli::CliError; -use crate::runner::RunnerOptionsBuilder; -use crate::runner::{RunnerOptions, Value, Verbosity}; -use atty::Stream; -use clap::{value_parser, ArgAction, ArgMatches, Command}; -use hurl::util::path::ContextDir; -use hurl_core::ast::Entry; use std::collections::HashMap; use std::env; use std::fs::File; @@ -30,6 +22,15 @@ use std::io::{BufRead, BufReader}; use std::path::{Path, PathBuf}; use std::time::Duration; +use atty::Stream; +use clap::{value_parser, ArgAction, ArgMatches, Command}; +use hurl::util::path::ContextDir; +use hurl_core::ast::Entry; + +use crate::cli; +use crate::cli::CliError; +use crate::runner::{RunnerOptions, RunnerOptionsBuilder, Value, Verbosity}; + #[derive(Clone, Debug, PartialEq, Eq)] pub struct CliOptions { pub cacert_file: Option, diff --git a/packages/hurl/src/cli/variables.rs b/packages/hurl/src/cli/variables.rs index 30ea20654..eca10b399 100644 --- a/packages/hurl/src/cli/variables.rs +++ b/packages/hurl/src/cli/variables.rs @@ -15,7 +15,6 @@ * limitations under the License. * */ - use crate::cli::CliError; use crate::runner::Value; diff --git a/packages/hurl/src/html/entities.rs b/packages/hurl/src/html/entities.rs index 85c2850b1..3433a6fb5 100644 --- a/packages/hurl/src/html/entities.rs +++ b/packages/hurl/src/html/entities.rs @@ -15,9 +15,10 @@ * limitations under the License. * */ -use lazy_static::lazy_static; use std::collections::HashMap; +use lazy_static::lazy_static; + // HTML5 named character references // // Generated from https://html.spec.whatwg.org/entities.json and diff --git a/packages/hurl/src/html/unescape.rs b/packages/hurl/src/html/unescape.rs index 734c41f28..7792ed6be 100644 --- a/packages/hurl/src/html/unescape.rs +++ b/packages/hurl/src/html/unescape.rs @@ -15,10 +15,12 @@ * limitations under the License. * */ -use crate::html::entities::HTML5_ENTITIES; +use std::collections::HashMap; + use lazy_static::lazy_static; use regex::{Captures, Regex}; -use std::collections::HashMap; + +use crate::html::entities::HTML5_ENTITIES; // Ref https://html.spec.whatwg.org/#decimal-character-reference-start-state lazy_static! { diff --git a/packages/hurl/src/http/certificate.rs b/packages/hurl/src/http/certificate.rs index 1825edd1a..1fb267045 100644 --- a/packages/hurl/src/http/certificate.rs +++ b/packages/hurl/src/http/certificate.rs @@ -15,10 +15,11 @@ * limitations under the License. * */ +use std::collections::HashMap; + +use chrono::{DateTime, NaiveDateTime, Utc}; use crate::http::easy_ext::CertInfo; -use chrono::{DateTime, NaiveDateTime, Utc}; -use std::collections::HashMap; #[derive(Clone, Debug, PartialEq, Eq)] pub struct Certificate { diff --git a/packages/hurl/src/http/client.rs b/packages/hurl/src/http/client.rs index 2d95de233..057dd5396 100644 --- a/packages/hurl/src/http/client.rs +++ b/packages/hurl/src/http/client.rs @@ -17,28 +17,27 @@ */ use std::io::Read; use std::str; - -use curl::easy; -use encoding::all::ISO_8859_1; -use encoding::{DecoderTrap, Encoding}; +use std::str::FromStr; use std::time::Instant; -use super::core::*; -use super::options::ClientOptions; -use super::request::*; -use super::request_spec::*; -use super::response::*; -use super::{Header, HttpError, Verbosity}; -use crate::http::certificate::Certificate; -use crate::http::easy_ext; -use crate::util::logger::Logger; -use crate::util::path::ContextDir; use base64::engine::general_purpose; use base64::Engine; +use curl::easy; use curl::easy::{List, SslOpt}; -use std::str::FromStr; +use encoding::all::ISO_8859_1; +use encoding::{DecoderTrap, Encoding}; use url::Url; +use crate::http::certificate::Certificate; +use crate::http::core::*; +use crate::http::options::ClientOptions; +use crate::http::request::*; +use crate::http::request_spec::*; +use crate::http::response::*; +use crate::http::{easy_ext, Header, HttpError, Verbosity}; +use crate::util::logger::Logger; +use crate::util::path::ContextDir; + /// Defines an HTTP client to execute HTTP requests. /// /// Most of the methods are delegated to libcurl functions, while some diff --git a/packages/hurl/src/http/core.rs b/packages/hurl/src/http/core.rs index 13b7c2d90..cead8e318 100644 --- a/packages/hurl/src/http/core.rs +++ b/packages/hurl/src/http/core.rs @@ -15,7 +15,6 @@ * limitations under the License. * */ - use core::fmt; use std::str::FromStr; diff --git a/packages/hurl/src/http/easy_ext.rs b/packages/hurl/src/http/easy_ext.rs index ba0cc09fb..ca9878c7e 100644 --- a/packages/hurl/src/http/easy_ext.rs +++ b/packages/hurl/src/http/easy_ext.rs @@ -15,11 +15,12 @@ * limitations under the License. * */ +use std::ffi::CStr; +use std::ptr; + use curl::easy::Easy; use curl::Error; use curl_sys::{curl_certinfo, curl_slist}; -use std::ffi::CStr; -use std::ptr; /// Represents certificate information. /// `data` has format "name:content"; @@ -125,10 +126,11 @@ fn to_list(slist: *mut curl_slist) -> Vec { #[cfg(test)] mod tests { - use super::to_list; use std::ffi::CString; use std::ptr; + use super::to_list; + #[test] fn convert_curl_slist_to_vec() { let mut slist = ptr::null_mut(); diff --git a/packages/hurl/src/http/header.rs b/packages/hurl/src/http/header.rs index fb1a8fd9b..ef4bb8549 100644 --- a/packages/hurl/src/http/header.rs +++ b/packages/hurl/src/http/header.rs @@ -15,7 +15,6 @@ * limitations under the License. * */ - use core::fmt; /// Represents an HTTP header @@ -40,12 +39,7 @@ impl Header { } } -/// Returns all header values for given name -/// -/// # Arguments -/// -/// * `headers` - A list of HTTP headers -/// * `name` - A name to filter header (case insensitively) +/// Returns all `headers` values for given `name`. pub fn get_values(headers: &[Header], name: &str) -> Vec { headers .iter() diff --git a/packages/hurl/src/http/request.rs b/packages/hurl/src/http/request.rs index 7d17e1929..7737fe8dc 100644 --- a/packages/hurl/src/http/request.rs +++ b/packages/hurl/src/http/request.rs @@ -15,12 +15,11 @@ * limitations under the License. * */ - -use super::core::*; -use super::Header; -use crate::http::{header, HttpError}; use url::Url; +use crate::http::core::*; +use crate::http::{header, Header, HttpError}; + #[derive(Clone, Debug, PartialEq, Eq)] pub struct Request { pub url: String, diff --git a/packages/hurl/src/http/request_debug.rs b/packages/hurl/src/http/request_debug.rs index e40c1cc85..6c99dcb33 100644 --- a/packages/hurl/src/http/request_debug.rs +++ b/packages/hurl/src/http/request_debug.rs @@ -15,7 +15,6 @@ * limitations under the License. * */ - use crate::http::{debug, mimetype, Request}; use crate::util::logger::Logger; diff --git a/packages/hurl/src/http/request_decoding.rs b/packages/hurl/src/http/request_decoding.rs index 82a69e568..ccece10c2 100644 --- a/packages/hurl/src/http/request_decoding.rs +++ b/packages/hurl/src/http/request_decoding.rs @@ -15,9 +15,9 @@ * limitations under the License. * */ +use encoding::{DecoderTrap, EncodingRef}; use crate::http::{mimetype, HttpError, Request}; -use encoding::{DecoderTrap, EncodingRef}; impl Request { /// Returns character encoding of the HTTP request. diff --git a/packages/hurl/src/http/request_spec.rs b/packages/hurl/src/http/request_spec.rs index e7331a8dd..72ae1020b 100644 --- a/packages/hurl/src/http/request_spec.rs +++ b/packages/hurl/src/http/request_spec.rs @@ -15,11 +15,10 @@ * limitations under the License. * */ - -use super::{header, Header}; use core::fmt; -use super::core::*; +use crate::http::core::*; +use crate::http::{header, Header}; #[derive(Clone, Debug, PartialEq, Eq)] pub struct RequestSpec { diff --git a/packages/hurl/src/http/request_spec_curl_args.rs b/packages/hurl/src/http/request_spec_curl_args.rs index b5dae0375..2ea5bf95f 100644 --- a/packages/hurl/src/http/request_spec_curl_args.rs +++ b/packages/hurl/src/http/request_spec_curl_args.rs @@ -15,12 +15,12 @@ * limitations under the License. * */ -use super::core::*; -use super::RequestSpec; -use crate::http::*; -use crate::util::path::ContextDir; use std::collections::HashMap; +use crate::http::core::*; +use crate::http::{RequestSpec, *}; +use crate::util::path::ContextDir; + impl RequestSpec { /// Returns this request as curl arguments. /// It does not contain the requests cookies (they will be accessed from the client) @@ -234,9 +234,10 @@ fn escape_string(s: &str) -> String { #[cfg(test)] pub mod tests { + use std::path::Path; + use super::*; use crate::http; - use std::path::Path; fn form_http_request() -> RequestSpec { RequestSpec { diff --git a/packages/hurl/src/http/response.rs b/packages/hurl/src/http/response.rs index 6fe68f465..64267b430 100644 --- a/packages/hurl/src/http/response.rs +++ b/packages/hurl/src/http/response.rs @@ -15,12 +15,12 @@ * limitations under the License. * */ - -use super::{header, Header}; -use crate::http::certificate::Certificate; use core::fmt; use std::time::Duration; +use crate::http::certificate::Certificate; +use crate::http::{header, Header}; + /// Represents an HTTP response. #[derive(Clone, Debug, PartialEq, Eq)] pub struct Response { diff --git a/packages/hurl/src/http/response_cookie.rs b/packages/hurl/src/http/response_cookie.rs index 8eb49c238..a8a5293a7 100644 --- a/packages/hurl/src/http/response_cookie.rs +++ b/packages/hurl/src/http/response_cookie.rs @@ -15,8 +15,7 @@ * limitations under the License. * */ -use super::Response; -use super::ResponseCookie; +use crate::http::{Response, ResponseCookie}; impl Response { pub fn cookies(&self) -> Vec { diff --git a/packages/hurl/src/http/response_decoding.rs b/packages/hurl/src/http/response_decoding.rs index dbe1e9faa..55bf34548 100644 --- a/packages/hurl/src/http/response_decoding.rs +++ b/packages/hurl/src/http/response_decoding.rs @@ -16,7 +16,6 @@ * */ -use encoding::{DecoderTrap, EncodingRef}; /// /// Decompresses body response /// using the Content-Encoding response header @@ -24,6 +23,8 @@ use encoding::{DecoderTrap, EncodingRef}; /// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding use std::io::prelude::*; +use encoding::{DecoderTrap, EncodingRef}; + use crate::http::{mimetype, HttpError, Response}; #[derive(Clone, Debug, PartialEq, Eq)] @@ -35,11 +36,7 @@ pub enum ContentEncoding { } impl ContentEncoding { - /// Returns an encoding from an HTTP header value. - /// - /// # Arguments - /// - /// * `s` - A Content-Encoding header value + /// Returns an encoding from an HTTP header value `s`. pub fn parse(s: &str) -> Result { match s { "br" => Ok(ContentEncoding::Brotli), @@ -52,11 +49,7 @@ impl ContentEncoding { } } - /// Decompresses bytes. - /// - /// # Arguments - /// - /// * `data` - A compressed bytes array + /// Decompresses `data` bytes. pub fn decode(&self, data: &[u8]) -> Result, HttpError> { match self { ContentEncoding::Identity => Ok(data.to_vec()), @@ -132,11 +125,7 @@ impl Response { } } -/// Decompresses Brotli compressed data. -/// -/// # Arguments -/// -/// * data - Compressed bytes. +/// Decompresses Brotli compressed `data`. fn uncompress_brotli(data: &[u8]) -> Result, HttpError> { let buffer_size = 4096; let mut reader = brotli::Decompressor::new(data, buffer_size); @@ -149,11 +138,7 @@ fn uncompress_brotli(data: &[u8]) -> Result, HttpError> { } } -/// Decompresses GZip compressed data. -/// -/// # Arguments -/// -/// * data - Compressed bytes. +/// Decompresses GZip compressed `data`. fn uncompress_gzip(data: &[u8]) -> Result, HttpError> { let mut decoder = match libflate::gzip::Decoder::new(data) { Ok(v) => v, @@ -172,11 +157,7 @@ fn uncompress_gzip(data: &[u8]) -> Result, HttpError> { } } -/// Decompresses Zlib compressed data. -/// -/// # Arguments -/// -/// * data - Compressed bytes. +/// Decompresses Zlib compressed `data`. fn uncompress_zlib(data: &[u8]) -> Result, HttpError> { let mut decoder = match libflate::zlib::Decoder::new(data) { Ok(v) => v, diff --git a/packages/hurl/src/http/tests/libcurl.rs b/packages/hurl/src/http/tests/libcurl.rs index d03f37102..bd8ed7246 100644 --- a/packages/hurl/src/http/tests/libcurl.rs +++ b/packages/hurl/src/http/tests/libcurl.rs @@ -16,10 +16,11 @@ * */ -use regex::Regex; use std::default::Default; use std::time::Duration; +use regex::Regex; + use crate::http::*; use crate::util::logger::LoggerBuilder; use crate::util::path::ContextDir; @@ -1112,9 +1113,10 @@ fn test_version() { // This test function can be used to reproduce bug #[test] fn test_libcurl_directly() { - use curl; use std::io::{stdout, Write}; + use curl; + let mut easy = curl::easy::Easy::new(); easy.url("http://localhost:8000/hello").unwrap(); easy.write_function(|data| { diff --git a/packages/hurl/src/http/tests/runner.rs b/packages/hurl/src/http/tests/runner.rs index 5411a0a4c..42db01a51 100644 --- a/packages/hurl/src/http/tests/runner.rs +++ b/packages/hurl/src/http/tests/runner.rs @@ -18,10 +18,11 @@ use std::collections::HashMap; +use hurl_core::ast::*; + use crate::runner; use crate::runner::RunnerOptions; use crate::util::logger::LoggerBuilder; -use hurl_core::ast::*; fn hello_request() -> Request { // GET http://localhost;8000/hello diff --git a/packages/hurl/src/json/result.rs b/packages/hurl/src/json/result.rs index 9e196408b..974fc18e4 100644 --- a/packages/hurl/src/json/result.rs +++ b/packages/hurl/src/json/result.rs @@ -15,12 +15,13 @@ * limitations under the License. * */ +use chrono::{DateTime, Utc}; + use crate::http::{ Certificate, Cookie, Header, Param, Request, RequestCookie, Response, ResponseCookie, Version, }; use crate::runner::{AssertResult, Call, CaptureResult, EntryResult, HurlResult}; use crate::util::logger; -use chrono::{DateTime, Utc}; impl HurlResult { /// Serializes an [`HurlResult`] to a JSON representation. diff --git a/packages/hurl/src/json/value.rs b/packages/hurl/src/json/value.rs index 24a898df2..0e028993f 100644 --- a/packages/hurl/src/json/value.rs +++ b/packages/hurl/src/json/value.rs @@ -16,10 +16,11 @@ * */ -use crate::runner::Value; use base64::engine::general_purpose; use base64::Engine; +use crate::runner::Value; + impl Value { pub fn to_json(&self) -> serde_json::Value { match self { diff --git a/packages/hurl/src/jsonpath/eval.rs b/packages/hurl/src/jsonpath/eval.rs index 9e84dfc63..2a50a0973 100644 --- a/packages/hurl/src/jsonpath/eval.rs +++ b/packages/hurl/src/jsonpath/eval.rs @@ -16,9 +16,10 @@ * */ -use super::ast::*; use float_cmp::approx_eq; +use super::ast::*; + pub type JsonpathResult = Vec; impl Query { diff --git a/packages/hurl/src/jsonpath/parser/primitives.rs b/packages/hurl/src/jsonpath/parser/primitives.rs index d9c78eaa0..95589f5e7 100644 --- a/packages/hurl/src/jsonpath/parser/primitives.rs +++ b/packages/hurl/src/jsonpath/parser/primitives.rs @@ -17,8 +17,7 @@ */ use super::super::ast::*; use super::error::{Error, ParseError}; -use super::ParseResult; -use super::Reader; +use super::{ParseResult, Reader}; pub fn natural(reader: &mut Reader) -> ParseResult<'static, usize> { let start = reader.state.clone(); diff --git a/packages/hurl/src/jsonpath/tests/mod.rs b/packages/hurl/src/jsonpath/tests/mod.rs index 4f881a06f..b92628829 100644 --- a/packages/hurl/src/jsonpath/tests/mod.rs +++ b/packages/hurl/src/jsonpath/tests/mod.rs @@ -20,10 +20,12 @@ //! These tests are not located at the root of the project, like Rust integration tests //! are usually located since we do not want to expose the jsonpath module to our public API. -use crate::jsonpath; -use serde_json::json; use std::fs::read_to_string; +use serde_json::json; + +use crate::jsonpath; + fn bookstore_value() -> serde_json::Value { let s = read_to_string("tests/bookstore.json").expect("could not read string from file"); serde_json::from_str(s.as_str()).expect("could not parse json file") diff --git a/packages/hurl/src/main.rs b/packages/hurl/src/main.rs index f91062a73..70eab6cca 100644 --- a/packages/hurl/src/main.rs +++ b/packages/hurl/src/main.rs @@ -25,13 +25,10 @@ use std::time::Instant; use atty::Stream; use clap::Command; use colored::*; - -use hurl::report; use hurl::report::html; -use hurl::runner; use hurl::runner::HurlResult; use hurl::util::logger::{BaseLogger, Logger, LoggerBuilder}; -use hurl::{libcurl_version_info, output}; +use hurl::{libcurl_version_info, output, report, runner}; use hurl_core::ast::HurlFile; use hurl_core::parser; use report::junit; diff --git a/packages/hurl/src/output/mod.rs b/packages/hurl/src/output/mod.rs index 99fbe6bca..f8265806f 100644 --- a/packages/hurl/src/output/mod.rs +++ b/packages/hurl/src/output/mod.rs @@ -25,12 +25,13 @@ mod json; mod raw; mod stdout; -pub use self::json::write_json; -pub use self::raw::write_body; use std::fmt; use std::io::Write; use std::path::Path; +pub use self::json::write_json; +pub use self::raw::write_body; + #[derive(Clone, Debug, PartialEq, Eq)] pub struct Error { pub message: String, diff --git a/packages/hurl/src/output/raw.rs b/packages/hurl/src/output/raw.rs index cbe24461b..4bab0fa86 100644 --- a/packages/hurl/src/output/raw.rs +++ b/packages/hurl/src/output/raw.rs @@ -15,15 +15,15 @@ * limitations under the License. * */ -use crate::http::Response; -use crate::output; -use crate::runner; -use crate::runner::{HurlResult, RunnerError}; -use crate::util::logger::Logger; use colored::Colorize; use hurl_core::ast::SourceInfo; use hurl_core::error::Error; +use crate::http::Response; +use crate::runner::{HurlResult, RunnerError}; +use crate::util::logger::Logger; +use crate::{output, runner}; + /// Writes the `hurl_result` last body response to the file `filename_out`. /// /// If `filename` is `None`, stdout is used. If `include_headers` is true, the last HTTP diff --git a/packages/hurl/src/output/stdout.rs b/packages/hurl/src/output/stdout.rs index afed0205a..9024c732c 100644 --- a/packages/hurl/src/output/stdout.rs +++ b/packages/hurl/src/output/stdout.rs @@ -15,12 +15,14 @@ * limitations under the License. * */ -use crate::output::Error; -#[cfg(target_family = "windows")] -use atty::Stream; use std::io; use std::io::Write; +#[cfg(target_family = "windows")] +use atty::Stream; + +use crate::output::Error; + #[cfg(target_family = "unix")] pub(crate) fn write_stdout(buf: &[u8]) -> Result<(), Error> { let stdout = io::stdout(); diff --git a/packages/hurl/src/report/html/mod.rs b/packages/hurl/src/report/html/mod.rs index 8cd978c96..cc2de58be 100644 --- a/packages/hurl/src/report/html/mod.rs +++ b/packages/hurl/src/report/html/mod.rs @@ -20,12 +20,14 @@ mod testcase; -use crate::report::Error; -use chrono::{DateTime, Local}; use std::io::Write; use std::path::Path; + +use chrono::{DateTime, Local}; pub use testcase::Testcase; +use crate::report::Error; + /// The test result to be displayed in an HTML page #[derive(Clone, Debug, PartialEq, Eq)] struct HTMLResult { diff --git a/packages/hurl/src/report/html/testcase.rs b/packages/hurl/src/report/html/testcase.rs index da3107c4b..582ef7fe7 100644 --- a/packages/hurl/src/report/html/testcase.rs +++ b/packages/hurl/src/report/html/testcase.rs @@ -15,13 +15,15 @@ * limitations under the License. * */ -use super::Error; -use crate::runner::HurlResult; -use hurl_core::ast::HurlFile; use std::io::Write; use std::path::Path; + +use hurl_core::ast::HurlFile; use uuid::Uuid; +use super::Error; +use crate::runner::HurlResult; + #[derive(Clone, Debug, PartialEq, Eq)] pub struct Testcase { pub id: String, diff --git a/packages/hurl/src/report/junit/mod.rs b/packages/hurl/src/report/junit/mod.rs index 06b6d2e5f..ee5a854bd 100644 --- a/packages/hurl/src/report/junit/mod.rs +++ b/packages/hurl/src/report/junit/mod.rs @@ -56,11 +56,13 @@ //! mod testcase; -use crate::report::Error; use std::fs::File; + pub use testcase::Testcase; use xmltree::{Element, XMLNode}; +use crate::report::Error; + /// Creates a JUnit from a list of `testcases`. pub fn write_report(filename: &str, testcases: &[Testcase]) -> Result<(), Error> { let mut testsuites = vec![]; diff --git a/packages/hurl/src/report/junit/testcase.rs b/packages/hurl/src/report/junit/testcase.rs index 2cfafec2e..9e7d29b14 100644 --- a/packages/hurl/src/report/junit/testcase.rs +++ b/packages/hurl/src/report/junit/testcase.rs @@ -15,9 +15,10 @@ * limitations under the License. * */ +use xmltree::{Element, XMLNode}; + use crate::runner::HurlResult; use crate::util::logger; -use xmltree::{Element, XMLNode}; #[derive(Clone, Debug, PartialEq, Eq)] pub struct Testcase { @@ -99,9 +100,10 @@ impl Testcase { #[cfg(test)] mod test { + use hurl_core::ast::SourceInfo; + use crate::report::junit::testcase::Testcase; use crate::runner::{EntryResult, Error, HurlResult, RunnerError}; - use hurl_core::ast::SourceInfo; #[test] fn test_create_testcase_success() { diff --git a/packages/hurl/src/runner/assert.rs b/packages/hurl/src/runner/assert.rs index f800c9031..9660b2ee3 100644 --- a/packages/hurl/src/runner/assert.rs +++ b/packages/hurl/src/runner/assert.rs @@ -15,18 +15,16 @@ * limitations under the License. * */ - use std::collections::HashMap; -use crate::http; -use crate::runner::filter::eval_filters; use hurl_core::ast::*; -use super::core::*; -use super::core::{Error, RunnerError}; -use super::predicate::eval_predicate; -use super::query::eval_query; -use super::value::Value; +use crate::http; +use crate::runner::core::{Error, RunnerError, *}; +use crate::runner::filter::eval_filters; +use crate::runner::predicate::eval_predicate; +use crate::runner::query::eval_query; +use crate::runner::value::Value; impl AssertResult { /// Evaluates an assert and returns `None` if assert is succeeded or an `Error` if failed. @@ -179,10 +177,11 @@ pub fn eval_assert( #[cfg(test)] pub mod tests { + use hurl_core::ast::SourceInfo; + use super::super::query; use super::*; use crate::http::xml_three_users_http_response; - use hurl_core::ast::SourceInfo; // xpath //user countEquals 3 pub fn assert_count_user() -> Assert { diff --git a/packages/hurl/src/runner/body.rs b/packages/hurl/src/runner/body.rs index 1a426fa55..d8ab7c3f4 100644 --- a/packages/hurl/src/runner/body.rs +++ b/packages/hurl/src/runner/body.rs @@ -15,17 +15,19 @@ * limitations under the License. * */ -use super::core::{Error, RunnerError}; -use super::json::eval_json_value; -use super::value::Value; -use crate::http; -use crate::runner::multiline::eval_multiline; -use crate::runner::template::eval_template; -use crate::util::path::ContextDir; -use hurl_core::ast::*; use std::collections::HashMap; use std::path::PathBuf; +use hurl_core::ast::*; + +use crate::http; +use crate::runner::core::{Error, RunnerError}; +use crate::runner::json::eval_json_value; +use crate::runner::multiline::eval_multiline; +use crate::runner::template::eval_template; +use crate::runner::value::Value; +use crate::util::path::ContextDir; + pub fn eval_body( body: &Body, variables: &HashMap, @@ -88,9 +90,10 @@ pub fn eval_file(filename: &Filename, context_dir: &ContextDir) -> Result Capture { // non scalar value diff --git a/packages/hurl/src/runner/core.rs b/packages/hurl/src/runner/core.rs index ce4c8ba8d..be01f3ad9 100644 --- a/packages/hurl/src/runner/core.rs +++ b/packages/hurl/src/runner/core.rs @@ -17,10 +17,10 @@ */ use std::path::PathBuf; -use crate::http; use hurl_core::ast::SourceInfo; use super::value::Value; +use crate::http; #[derive(Clone, Debug, PartialEq, Eq)] pub enum Verbosity { diff --git a/packages/hurl/src/runner/entry.rs b/packages/hurl/src/runner/entry.rs index 2c27dc6a6..c6f4429e4 100644 --- a/packages/hurl/src/runner/entry.rs +++ b/packages/hurl/src/runner/entry.rs @@ -18,20 +18,17 @@ use std::collections::HashMap; use std::time::Duration; -use crate::http; -use crate::http::ClientOptions; -use crate::util::logger::Logger; use hurl_core::ast::*; -use super::core::*; -use super::core::{Error, RunnerError}; -use super::request::eval_request; -use super::response::{eval_asserts, eval_captures}; -use super::value::Value; -use crate::runner::request::{cookie_storage_clear, cookie_storage_set}; -use crate::runner::response::eval_version_status_asserts; +use crate::http; +use crate::http::ClientOptions; +use crate::runner::core::{Error, RunnerError, *}; +use crate::runner::request::{cookie_storage_clear, cookie_storage_set, eval_request}; +use crate::runner::response::{eval_asserts, eval_captures, eval_version_status_asserts}; use crate::runner::runner_options::RunnerOptions; use crate::runner::template::eval_template; +use crate::runner::value::Value; +use crate::util::logger::Logger; /// Runs an `entry` with `http_client` and returns one [`EntryResult`]. /// diff --git a/packages/hurl/src/runner/error.rs b/packages/hurl/src/runner/error.rs index 2d0c976df..95c0afc91 100644 --- a/packages/hurl/src/runner/error.rs +++ b/packages/hurl/src/runner/error.rs @@ -15,11 +15,12 @@ * limitations under the License. * */ +use hurl_core::ast::SourceInfo; +use hurl_core::error::Error; + use crate::http::HttpError; use crate::runner; use crate::runner::RunnerError; -use hurl_core::ast::SourceInfo; -use hurl_core::error::Error; /// Textual Output for runner errors impl Error for runner::Error { diff --git a/packages/hurl/src/runner/expr.rs b/packages/hurl/src/runner/expr.rs index e6b70d132..99623b50d 100644 --- a/packages/hurl/src/runner/expr.rs +++ b/packages/hurl/src/runner/expr.rs @@ -19,8 +19,8 @@ use std::collections::HashMap; use hurl_core::ast::Expr; -use super::core::{Error, RunnerError}; -use super::value::Value; +use crate::runner::core::{Error, RunnerError}; +use crate::runner::value::Value; /// Evaluates the expression `expr` with `variables` map and `http_response`, returns a /// [`Value`] on success or an [`Error`] . diff --git a/packages/hurl/src/runner/filter.rs b/packages/hurl/src/runner/filter.rs index 21245386f..d6d302865 100644 --- a/packages/hurl/src/runner/filter.rs +++ b/packages/hurl/src/runner/filter.rs @@ -15,14 +15,13 @@ * limitations under the License. * */ -use chrono::NaiveDateTime; use std::collections::HashMap; +use chrono::NaiveDateTime; +use hurl_core::ast::{Filter, FilterValue, RegexValue, SourceInfo, Template}; use percent_encoding::AsciiSet; use crate::html; -use hurl_core::ast::{Filter, FilterValue, RegexValue, SourceInfo, Template}; - use crate::runner::regex::eval_regex_value; use crate::runner::template::eval_template; use crate::runner::{Error, RunnerError, Value}; @@ -346,11 +345,12 @@ fn eval_to_int(value: &Value, source_info: &SourceInfo, assert: bool) -> Result< #[cfg(test)] pub mod tests { - use super::*; use chrono::offset::Utc; use chrono::prelude::*; use hurl_core::ast::{FilterValue, SourceInfo, Template, TemplateElement, Whitespace}; + use super::*; + pub fn filter_count() -> Filter { Filter { source_info: SourceInfo::new(1, 1, 1, 6), diff --git a/packages/hurl/src/runner/hurl_file.rs b/packages/hurl/src/runner/hurl_file.rs index f08112329..04e48890f 100644 --- a/packages/hurl/src/runner/hurl_file.rs +++ b/packages/hurl/src/runner/hurl_file.rs @@ -19,16 +19,15 @@ use std::collections::HashMap; use std::thread; use std::time::Instant; -use crate::http; -use crate::runner::core::*; -use crate::runner::entry; -use crate::runner::runner_options::RunnerOptions; -use crate::runner::Value; -use crate::util::logger::Logger; -use crate::util::logger::LoggerBuilder; use hurl_core::ast::VersionValue::VersionAnyLegacy; use hurl_core::ast::*; +use crate::http; +use crate::runner::core::*; +use crate::runner::runner_options::RunnerOptions; +use crate::runner::{entry, Value}; +use crate::util::logger::{Logger, LoggerBuilder}; + /// Runs a `hurl_file`, issue from the given `content`and `filename` and /// returns a [`HurlResult`] upon completion. /// diff --git a/packages/hurl/src/runner/json.rs b/packages/hurl/src/runner/json.rs index 0f33e9ea7..a9a500d1b 100644 --- a/packages/hurl/src/runner/json.rs +++ b/packages/hurl/src/runner/json.rs @@ -20,9 +20,9 @@ use std::collections::HashMap; use hurl_core::ast::{JsonListElement, JsonObjectElement, JsonValue, Template, TemplateElement}; use hurl_core::parser::{parse_json_boolean, parse_json_null, parse_json_number, Reader}; -use super::core::{Error, RunnerError}; -use super::value::Value; +use crate::runner::core::{Error, RunnerError}; use crate::runner::template::eval_expression; +use crate::runner::value::Value; /// Evaluates a JSON value to a string given a set of `variables`. /// If `keep_whitespace` is true, whitespace is preserved from the JSonValue, otherwise @@ -179,9 +179,10 @@ fn encode_json_char(c: char) -> String { #[cfg(test)] mod tests { + use hurl_core::ast::*; + use super::super::core::RunnerError; use super::*; - use hurl_core::ast::*; pub fn json_hello_world_value() -> JsonValue { // "hello\u0020{{name}}!" diff --git a/packages/hurl/src/runner/multiline.rs b/packages/hurl/src/runner/multiline.rs index 2b43ef750..0750970b6 100644 --- a/packages/hurl/src/runner/multiline.rs +++ b/packages/hurl/src/runner/multiline.rs @@ -15,12 +15,14 @@ * limitations under the License. * */ +use std::collections::HashMap; + +use hurl_core::ast::{MultilineString, Text}; +use serde_json::json; + use crate::runner::json::eval_json_value; use crate::runner::template::eval_template; use crate::runner::{Error, Value}; -use hurl_core::ast::{MultilineString, Text}; -use serde_json::json; -use std::collections::HashMap; /// Renders to string a multiline body, given a set of variables. pub fn eval_multiline( @@ -55,14 +57,15 @@ pub fn eval_multiline( #[cfg(test)] mod tests { - use crate::runner::multiline::eval_multiline; - use hurl_core::ast::JsonValue; - use hurl_core::ast::{ - GraphQl, GraphQlVariables, JsonObjectElement, MultilineString, SourceInfo, Template, - TemplateElement, Whitespace, - }; use std::collections::HashMap; + use hurl_core::ast::{ + GraphQl, GraphQlVariables, JsonObjectElement, JsonValue, MultilineString, SourceInfo, + Template, TemplateElement, Whitespace, + }; + + use crate::runner::multiline::eval_multiline; + fn whitespace() -> Whitespace { Whitespace { value: String::from(" "), diff --git a/packages/hurl/src/runner/multipart.rs b/packages/hurl/src/runner/multipart.rs index 8402f1144..4908a90a1 100644 --- a/packages/hurl/src/runner/multipart.rs +++ b/packages/hurl/src/runner/multipart.rs @@ -15,17 +15,19 @@ * limitations under the License. * */ -use super::core::Error; -use super::template::eval_template; -use super::value::Value; -use crate::http; -use crate::runner::body::eval_file; -use crate::util::path::ContextDir; -use hurl_core::ast::*; use std::collections::HashMap; use std::ffi::OsStr; use std::path::Path; +use hurl_core::ast::*; + +use crate::http; +use crate::runner::body::eval_file; +use crate::runner::core::Error; +use crate::runner::template::eval_template; +use crate::runner::value::Value; +use crate::util::path::ContextDir; + pub fn eval_multipart_param( multipart_param: &MultipartParam, variables: &HashMap, diff --git a/packages/hurl/src/runner/predicate.rs b/packages/hurl/src/runner/predicate.rs index 3e21d4a7b..30040df27 100644 --- a/packages/hurl/src/runner/predicate.rs +++ b/packages/hurl/src/runner/predicate.rs @@ -18,15 +18,13 @@ use std::cmp::Ordering; use std::collections::HashMap; +use hurl_core::ast::*; use regex; -use hurl_core::ast::*; - -use super::core::Error; -use super::template::eval_template; -use super::value::Value; -use crate::runner::core::PredicateResult; +use crate::runner::core::{Error, PredicateResult}; use crate::runner::predicate_value::eval_predicate_value; +use crate::runner::template::eval_template; +use crate::runner::value::Value; use crate::runner::RunnerError; pub fn eval_predicate( @@ -829,8 +827,7 @@ fn contains(haystack: &[u8], needle: &[u8]) -> bool { #[cfg(test)] mod tests { - use super::AssertResult; - use super::*; + use super::{AssertResult, *}; fn whitespace() -> Whitespace { Whitespace { diff --git a/packages/hurl/src/runner/predicate_value.rs b/packages/hurl/src/runner/predicate_value.rs index 5e38e0256..f1c876552 100644 --- a/packages/hurl/src/runner/predicate_value.rs +++ b/packages/hurl/src/runner/predicate_value.rs @@ -17,13 +17,13 @@ */ use std::collections::HashMap; -use crate::runner::multiline::eval_multiline; use hurl_core::ast::*; -use super::core::Error; -use super::expr::eval_expr; -use super::template::eval_template; -use super::value::Value; +use crate::runner::core::Error; +use crate::runner::expr::eval_expr; +use crate::runner::multiline::eval_multiline; +use crate::runner::template::eval_template; +use crate::runner::value::Value; pub fn eval_predicate_value( predicate_value: &PredicateValue, diff --git a/packages/hurl/src/runner/query.rs b/packages/hurl/src/runner/query.rs index fe5813532..362e52cb3 100644 --- a/packages/hurl/src/runner/query.rs +++ b/packages/hurl/src/runner/query.rs @@ -15,19 +15,18 @@ * limitations under the License. * */ - -use regex::Regex; use std::collections::HashMap; -use super::core::{Error, RunnerError}; -use super::template::eval_template; -use super::value::Value; -use super::xpath; -use crate::http; -use crate::jsonpath; use hurl_core::ast::*; +use regex::Regex; use sha2::Digest; +use crate::runner::core::{Error, RunnerError}; +use crate::runner::template::eval_template; +use crate::runner::value::Value; +use crate::runner::xpath; +use crate::{http, jsonpath}; + pub type QueryResult = Result, Error>; /// Evaluates this `query` and returns a [`QueryResult`], using the HTTP response `http_response` and `variables`. @@ -381,10 +380,11 @@ impl Value { #[cfg(test)] pub mod tests { - use super::*; use hex_literal::hex; use hurl_core::ast::{Pos, SourceInfo}; + use super::*; + pub fn xpath_invalid_query() -> Query { // xpath ??? let whitespace = Whitespace { diff --git a/packages/hurl/src/runner/regex.rs b/packages/hurl/src/runner/regex.rs index babcd8507..fc542b012 100644 --- a/packages/hurl/src/runner/regex.rs +++ b/packages/hurl/src/runner/regex.rs @@ -15,12 +15,10 @@ * limitations under the License. * */ - use std::collections::HashMap; -use regex::Regex; - use hurl_core::ast::RegexValue; +use regex::Regex; use crate::runner::template::eval_template; use crate::runner::{Error, RunnerError, Value}; diff --git a/packages/hurl/src/runner/request.rs b/packages/hurl/src/runner/request.rs index 9f3a6a060..fe84cf92a 100644 --- a/packages/hurl/src/runner/request.rs +++ b/packages/hurl/src/runner/request.rs @@ -15,17 +15,19 @@ * limitations under the License. * */ -use super::body::eval_body; -use super::core::Error; -use super::template::eval_template; -use super::value::Value; -use crate::http; -use crate::runner::multipart::eval_multipart_param; -use crate::util::path::ContextDir; +use std::collections::HashMap; + use base64::engine::general_purpose; use base64::Engine; use hurl_core::ast::*; -use std::collections::HashMap; + +use crate::http; +use crate::runner::body::eval_body; +use crate::runner::core::Error; +use crate::runner::multipart::eval_multipart_param; +use crate::runner::template::eval_template; +use crate::runner::value::Value; +use crate::util::path::ContextDir; /// Transforms an AST `request` to a spec request given a set of `variables`. pub fn eval_request( @@ -181,9 +183,10 @@ fn eval_method(method: &Method) -> http::Method { #[cfg(test)] mod tests { + use hurl_core::ast::SourceInfo; + use super::super::core::RunnerError; use super::*; - use hurl_core::ast::SourceInfo; fn whitespace() -> Whitespace { Whitespace { diff --git a/packages/hurl/src/runner/response.rs b/packages/hurl/src/runner/response.rs index 8c2734c9d..2962490b2 100644 --- a/packages/hurl/src/runner/response.rs +++ b/packages/hurl/src/runner/response.rs @@ -15,19 +15,21 @@ * limitations under the License. * */ -use super::assert::eval_assert; -use super::body::eval_body; -use super::capture::eval_capture; -use super::core::*; -use super::json::eval_json_value; -use super::template::eval_template; -use super::value::Value; -use crate::http; -use crate::runner::multiline::eval_multiline; -use crate::util::path::ContextDir; -use hurl_core::ast::*; use std::collections::HashMap; +use hurl_core::ast::*; + +use crate::http; +use crate::runner::assert::eval_assert; +use crate::runner::body::eval_body; +use crate::runner::capture::eval_capture; +use crate::runner::core::*; +use crate::runner::json::eval_json_value; +use crate::runner::multiline::eval_multiline; +use crate::runner::template::eval_template; +use crate::runner::value::Value; +use crate::util::path::ContextDir; + /// Returns a list of assert results on the response status code and HTTP version, /// given a set of `variables`, an actual `http_response` and a spec `response`. pub fn eval_version_status_asserts( @@ -326,11 +328,9 @@ pub fn eval_captures( #[cfg(test)] mod tests { + use self::super::super::{assert, capture}; use super::*; - use self::super::super::assert; - use self::super::super::capture; - pub fn user_response() -> Response { let whitespace = Whitespace { value: String::from(" "), diff --git a/packages/hurl/src/runner/runner_options.rs b/packages/hurl/src/runner/runner_options.rs index 466af9dad..bda8fe0f3 100644 --- a/packages/hurl/src/runner/runner_options.rs +++ b/packages/hurl/src/runner/runner_options.rs @@ -15,10 +15,12 @@ * limitations under the License. * */ +use std::time::Duration; + +use hurl_core::ast::Entry; + use crate::runner::Verbosity; use crate::util::path::ContextDir; -use hurl_core::ast::Entry; -use std::time::Duration; pub struct RunnerOptionsBuilder { cacert_file: Option, diff --git a/packages/hurl/src/runner/template.rs b/packages/hurl/src/runner/template.rs index d773a0ee0..e19d4a73c 100644 --- a/packages/hurl/src/runner/template.rs +++ b/packages/hurl/src/runner/template.rs @@ -19,8 +19,8 @@ use std::collections::HashMap; use hurl_core::ast::*; -use super::core::{Error, RunnerError}; -use super::value::Value; +use crate::runner::core::{Error, RunnerError}; +use crate::runner::value::Value; /// Renders to string a `template` given a map of variables. pub fn eval_template( diff --git a/packages/hurl/src/runner/xpath.rs b/packages/hurl/src/runner/xpath.rs index fa4d4b3ae..a6af4f539 100644 --- a/packages/hurl/src/runner/xpath.rs +++ b/packages/hurl/src/runner/xpath.rs @@ -16,11 +16,10 @@ * */ -// Unique entry point to libxml2 - +/// Unique entry point to libxml2 use std::ffi::CStr; -use super::value::Value; +use crate::runner::value::Value; #[derive(Clone, Debug, PartialEq, Eq)] pub enum XpathError { diff --git a/packages/hurl/src/util/logger.rs b/packages/hurl/src/util/logger.rs index 56c078db0..09d1acccb 100644 --- a/packages/hurl/src/util/logger.rs +++ b/packages/hurl/src/util/logger.rs @@ -15,11 +15,12 @@ * limitations under the License. * */ +use std::cmp::max; -use crate::runner::{HurlResult, Value}; use colored::*; use hurl_core::error::Error; -use std::cmp::max; + +use crate::runner::{HurlResult, Value}; /// A simple logger to log app related event (start, high levels error, etc...). /// When we run an [`hurl_core::ast::HurlFile`], user has to provide a dedicated Hurl logger (see [`Logger`]). @@ -601,9 +602,10 @@ fn get_lines(text: &str) -> Vec<&str> { #[cfg(test)] pub mod tests { + use hurl_core::ast::SourceInfo; + use super::*; use crate::runner; - use hurl_core::ast::SourceInfo; #[test] fn test_add_line_prefix_no_colored() { diff --git a/packages/hurl_core/src/ast/core.rs b/packages/hurl_core/src/ast/core.rs index 9c97636a6..22edb30f8 100644 --- a/packages/hurl_core/src/ast/core.rs +++ b/packages/hurl_core/src/ast/core.rs @@ -15,7 +15,7 @@ * limitations under the License. * */ -use super::json; +use crate::ast::json; /// /// Hurl AST diff --git a/packages/hurl_core/src/ast/display.rs b/packages/hurl_core/src/ast/display.rs index cc6f5f3b8..4766c27c5 100644 --- a/packages/hurl_core/src/ast/display.rs +++ b/packages/hurl_core/src/ast/display.rs @@ -15,9 +15,10 @@ * limitations under the License. * */ -use super::core::*; use core::fmt; +use crate::ast::core::*; + impl fmt::Display for Method { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let s = match self { diff --git a/packages/hurl_core/src/ast/json.rs b/packages/hurl_core/src/ast/json.rs index 099ee5b54..ba481d5e8 100644 --- a/packages/hurl_core/src/ast/json.rs +++ b/packages/hurl_core/src/ast/json.rs @@ -15,10 +15,11 @@ * limitations under the License. * */ -use super::core::Template; -use crate::ast::{Expr, TemplateElement}; use core::fmt; +use crate::ast::core::Template; +use crate::ast::{Expr, TemplateElement}; + /// /// This the AST for the JSON used within Hurl /// diff --git a/packages/hurl_core/src/ast/mod.rs b/packages/hurl_core/src/ast/mod.rs index fb12d367c..691c2a977 100644 --- a/packages/hurl_core/src/ast/mod.rs +++ b/packages/hurl_core/src/ast/mod.rs @@ -17,9 +17,9 @@ */ pub use self::core::*; -pub use self::json::ListElement as JsonListElement; -pub use self::json::ObjectElement as JsonObjectElement; -pub use self::json::Value as JsonValue; +pub use self::json::{ + ListElement as JsonListElement, ObjectElement as JsonObjectElement, Value as JsonValue, +}; mod core; mod display; diff --git a/packages/hurl_core/src/error/mod.rs b/packages/hurl_core/src/error/mod.rs index 4514ecc05..7b91b7d2e 100644 --- a/packages/hurl_core/src/error/mod.rs +++ b/packages/hurl_core/src/error/mod.rs @@ -15,11 +15,12 @@ * limitations under the License. * */ -use super::ast::SourceInfo; -use super::parser; -use super::parser::ParseError; use core::cmp; +use crate::ast::SourceInfo; +use crate::parser; +use crate::parser::ParseError; + pub trait Error { fn source_info(&self) -> SourceInfo; fn description(&self) -> String; diff --git a/packages/hurl_core/src/parser/base64.rs b/packages/hurl_core/src/parser/base64.rs index be2e7ff36..a6c74f76b 100644 --- a/packages/hurl_core/src/parser/base64.rs +++ b/packages/hurl_core/src/parser/base64.rs @@ -17,23 +17,11 @@ */ use super::reader::Reader; -// part of hurl -// just reuse Parser/Error Position -// do not depend on external separator -// stop parsing when there is no more base64 character -// -// what kind of errors can you have? -// can only fail if using bad padding? -// if padding is used it must be used properly -// you can only have an Expecting padding error (missing one for example) - -/* -https://en.wikipedia.org/wiki/Base64 -Test padding/no-padding - -Encoded -YW55IGNhcm5hbCBwbGVhcw== any carnal pleas # [97, 110, 121, 32, 99, 97, 114, 110, 97, 108, 32, 112, 108, 101, 97, 115] -*/ +/// +/// Test padding/no-padding +/// +/// Encoded +/// YW55IGNhcm5hbCBwbGVhcw== any carnal pleas # [97, 110, 121, 32, 99, 97, 114, 110, 97, 108, 32, 112, 108, 101, 97, 115] pub fn parse(reader: &mut Reader) -> Vec { let mut bytes = vec![]; diff --git a/packages/hurl_core/src/parser/bytes.rs b/packages/hurl_core/src/parser/bytes.rs index a8fd155b1..7b90f4de2 100644 --- a/packages/hurl_core/src/parser/bytes.rs +++ b/packages/hurl_core/src/parser/bytes.rs @@ -16,15 +16,13 @@ * */ use crate::ast::*; +use crate::parser::combinators::*; +use crate::parser::json::parse as parse_json; use crate::parser::multiline::multiline_string; +use crate::parser::primitives::*; +use crate::parser::reader::Reader; use crate::parser::string::backtick_template; - -use super::combinators::*; -use super::json::parse as parse_json; -use super::primitives::*; -use super::reader::Reader; -use super::xml; -use super::ParseResult; +use crate::parser::{xml, ParseResult}; pub fn bytes(reader: &mut Reader) -> ParseResult<'static, Bytes> { choice( diff --git a/packages/hurl_core/src/parser/combinators.rs b/packages/hurl_core/src/parser/combinators.rs index 59528e63b..85ded62b8 100644 --- a/packages/hurl_core/src/parser/combinators.rs +++ b/packages/hurl_core/src/parser/combinators.rs @@ -15,9 +15,9 @@ * limitations under the License. * */ -use super::error::*; -use super::reader::Reader; -use super::{ParseFunc, ParseResult}; +use crate::parser::error::*; +use crate::parser::reader::Reader; +use crate::parser::{ParseFunc, ParseResult}; pub fn optional<'a, T>(f: ParseFunc<'a, T>, reader: &mut Reader) -> ParseResult<'a, Option> { let start = reader.state.clone(); @@ -48,7 +48,6 @@ pub fn recover<'a, T>(f: ParseFunc<'a, T>, reader: &mut Reader) -> ParseResult<' } pub fn nonrecover<'a, T>(f: ParseFunc<'a, T>, reader: &mut Reader) -> ParseResult<'a, T> { - //let start = p.state.clone(); match f(reader) { Ok(r) => Ok(r), Err(e) => Err(Error { diff --git a/packages/hurl_core/src/parser/cookiepath.rs b/packages/hurl_core/src/parser/cookiepath.rs index 788ef4148..8ded32f7e 100644 --- a/packages/hurl_core/src/parser/cookiepath.rs +++ b/packages/hurl_core/src/parser/cookiepath.rs @@ -15,27 +15,13 @@ * limitations under the License. * */ - use crate::ast::*; - -use super::combinators::*; -use super::error::*; -use super::primitives::*; -use super::reader::Reader; -use super::string::*; -use super::ParseResult; - -/* - -"cookiepath" expression -not described in the official grammar - -cookie-query = "cookie" sp sp* """ cookiepath-expr """ -cookiepath-expr = cookie-query-name ( "[" sp* cookie-query-attribute sp* "]" ) -cookiepath-name = <[a-zA-Z0-9{}]+> -cookiepath-attribute = Value | Expires | Max-Age | Domain | Path | Secure | HttpOnly | SameSite - -*/ +use crate::parser::combinators::*; +use crate::parser::error::*; +use crate::parser::primitives::*; +use crate::parser::reader::Reader; +use crate::parser::string::*; +use crate::parser::ParseResult; pub fn cookiepath(reader: &mut Reader) -> ParseResult<'static, CookiePath> { let start = reader.state.pos.clone(); @@ -82,9 +68,8 @@ fn cookiepath_attribute_name(reader: &mut Reader) -> ParseResult<'static, Cookie #[cfg(test)] mod tests { - use crate::ast::{Pos, SourceInfo}; - use super::*; + use crate::ast::{Pos, SourceInfo}; #[test] fn test_cookiepath_simple() { diff --git a/packages/hurl_core/src/parser/expr.rs b/packages/hurl_core/src/parser/expr.rs index c24ad71fa..18156fce6 100644 --- a/packages/hurl_core/src/parser/expr.rs +++ b/packages/hurl_core/src/parser/expr.rs @@ -16,11 +16,10 @@ * */ use crate::ast::*; - -use super::error::*; -use super::primitives::*; -use super::reader::Reader; -use super::ParseResult; +use crate::parser::error::*; +use crate::parser::primitives::*; +use crate::parser::reader::Reader; +use crate::parser::ParseResult; pub fn parse(reader: &mut Reader) -> ParseResult<'static, Expr> { // let start = p.state.clone(); @@ -79,9 +78,8 @@ fn variable_name(reader: &mut Reader) -> ParseResult<'static, Variable> { #[cfg(test)] mod tests { - use crate::ast::Pos; - use super::*; + use crate::ast::Pos; #[test] fn test_expr() { diff --git a/packages/hurl_core/src/parser/filename.rs b/packages/hurl_core/src/parser/filename.rs index 8b8a46fd5..a9e8439ab 100644 --- a/packages/hurl_core/src/parser/filename.rs +++ b/packages/hurl_core/src/parser/filename.rs @@ -15,12 +15,10 @@ * limitations under the License. * */ - -use super::error::*; -use super::reader::Reader; - -use super::ParseResult; use crate::ast::*; +use crate::parser::error::*; +use crate::parser::reader::Reader; +use crate::parser::ParseResult; pub fn parse(reader: &mut Reader) -> ParseResult<'static, Filename> { // This is an absolute file @@ -49,9 +47,8 @@ pub fn parse(reader: &mut Reader) -> ParseResult<'static, Filename> { #[cfg(test)] mod tests { - use crate::ast::Pos; - use super::*; + use crate::ast::Pos; #[test] fn test_filename() { diff --git a/packages/hurl_core/src/parser/filter.rs b/packages/hurl_core/src/parser/filter.rs index f663e3051..b15ef3012 100644 --- a/packages/hurl_core/src/parser/filter.rs +++ b/packages/hurl_core/src/parser/filter.rs @@ -165,11 +165,10 @@ fn url_decode_filter(reader: &mut Reader) -> ParseResult<'static, FilterValue> { #[cfg(test)] mod tests { + use super::*; use crate::ast::Pos; use crate::parser::ParseError; - use super::*; - #[test] fn test_count() { let mut reader = Reader::init("count"); diff --git a/packages/hurl_core/src/parser/json.rs b/packages/hurl_core/src/parser/json.rs index c159ab7c0..ea09de33a 100644 --- a/packages/hurl_core/src/parser/json.rs +++ b/packages/hurl_core/src/parser/json.rs @@ -16,14 +16,11 @@ * */ use crate::ast::{JsonListElement, JsonObjectElement, JsonValue, Pos, SourceInfo, Template}; - -use super::combinators::*; -use super::error; -use super::primitives::*; -use super::reader::*; -use super::template::*; -use super::ParseResult; -use crate::parser::expr; +use crate::parser::combinators::*; +use crate::parser::primitives::*; +use crate::parser::reader::*; +use crate::parser::template::*; +use crate::parser::{error, expr, ParseResult}; pub fn parse(reader: &mut Reader) -> ParseResult<'static, JsonValue> { choice( diff --git a/packages/hurl_core/src/parser/mod.rs b/packages/hurl_core/src/parser/mod.rs index 74b4fce87..34108848b 100644 --- a/packages/hurl_core/src/parser/mod.rs +++ b/packages/hurl_core/src/parser/mod.rs @@ -24,10 +24,10 @@ pub fn parse_hurl_file(s: &str) -> ParseResult<'static, HurlFile> { } pub use self::error::{Error, ParseError}; -pub use self::json::boolean_value as parse_json_boolean; -pub use self::json::null_value as parse_json_null; -pub use self::json::number_value as parse_json_number; -pub use self::json::parse as parse_json; +pub use self::json::{ + boolean_value as parse_json_boolean, null_value as parse_json_null, + number_value as parse_json_number, parse as parse_json, +}; pub use self::reader::Reader; pub use self::template::templatize; use crate::ast::HurlFile; diff --git a/packages/hurl_core/src/parser/multiline.rs b/packages/hurl_core/src/parser/multiline.rs index b486c17e5..32c7166b6 100644 --- a/packages/hurl_core/src/parser/multiline.rs +++ b/packages/hurl_core/src/parser/multiline.rs @@ -15,13 +15,12 @@ * limitations under the License. * */ -use super::combinators::*; -use super::reader::Reader; -use super::ParseResult; use crate::ast::*; +use crate::parser::combinators::*; use crate::parser::json::object_value; use crate::parser::primitives::*; -use crate::parser::{template, Error, ParseError}; +use crate::parser::reader::Reader; +use crate::parser::{template, Error, ParseError, ParseResult}; pub fn multiline_string(reader: &mut Reader) -> ParseResult<'static, MultilineString> { try_literal("```", reader)?; diff --git a/packages/hurl_core/src/parser/parsers.rs b/packages/hurl_core/src/parser/parsers.rs index e766a3e20..34e89cb85 100644 --- a/packages/hurl_core/src/parser/parsers.rs +++ b/packages/hurl_core/src/parser/parsers.rs @@ -17,15 +17,14 @@ */ use crate::ast::VersionValue::VersionAny; use crate::ast::*; - -use super::bytes::*; -use super::combinators::*; -use super::error::*; -use super::primitives::*; -use super::reader::Reader; -use super::sections::*; -use super::url::url; -use super::ParseResult; +use crate::parser::bytes::*; +use crate::parser::combinators::*; +use crate::parser::error::*; +use crate::parser::primitives::*; +use crate::parser::reader::Reader; +use crate::parser::sections::*; +use crate::parser::url::url; +use crate::parser::ParseResult; pub fn hurl_file(reader: &mut Reader) -> ParseResult<'static, HurlFile> { let entries = zero_or_more(entry, reader)?; diff --git a/packages/hurl_core/src/parser/predicate.rs b/packages/hurl_core/src/parser/predicate.rs index f1ebe1b32..a51501bb3 100644 --- a/packages/hurl_core/src/parser/predicate.rs +++ b/packages/hurl_core/src/parser/predicate.rs @@ -15,15 +15,13 @@ * limitations under the License. * */ - use crate::ast::*; - -use super::combinators::*; -use super::error::*; -use super::predicate_value::predicate_value; -use super::primitives::*; -use super::reader::Reader; -use super::ParseResult; +use crate::parser::combinators::*; +use crate::parser::error::*; +use crate::parser::predicate_value::predicate_value; +use crate::parser::primitives::*; +use crate::parser::reader::Reader; +use crate::parser::ParseResult; pub fn predicate(reader: &mut Reader) -> ParseResult<'static, Predicate> { let (not, space0) = predicate_not(reader); @@ -361,9 +359,8 @@ fn exist_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncVal #[cfg(test)] mod tests { - use crate::ast::Pos; - use super::*; + use crate::ast::Pos; #[test] fn test_predicate_not() { diff --git a/packages/hurl_core/src/parser/predicate_value.rs b/packages/hurl_core/src/parser/predicate_value.rs index cea58a215..5bbc7a4ad 100644 --- a/packages/hurl_core/src/parser/predicate_value.rs +++ b/packages/hurl_core/src/parser/predicate_value.rs @@ -15,17 +15,13 @@ * limitations under the License. * */ - use crate::ast::*; - -use super::combinators::*; -use super::expr; -use super::primitives::*; -use super::reader::Reader; -use super::string::*; -use super::ParseResult; +use crate::parser::combinators::*; use crate::parser::multiline::multiline_string; -use crate::parser::{Error, ParseError}; +use crate::parser::primitives::*; +use crate::parser::reader::Reader; +use crate::parser::string::*; +use crate::parser::{expr, Error, ParseError, ParseResult}; pub fn predicate_value(reader: &mut Reader) -> ParseResult<'static, PredicateValue> { choice( diff --git a/packages/hurl_core/src/parser/primitives.rs b/packages/hurl_core/src/parser/primitives.rs index c107ba3f6..70209f1a2 100644 --- a/packages/hurl_core/src/parser/primitives.rs +++ b/packages/hurl_core/src/parser/primitives.rs @@ -16,14 +16,11 @@ * */ use crate::ast::*; - -use super::base64; -use super::combinators::*; -use super::error::*; -use super::filename; -use super::reader::Reader; -use super::string::*; -use super::ParseResult; +use crate::parser::combinators::*; +use crate::parser::error::*; +use crate::parser::reader::Reader; +use crate::parser::string::*; +use crate::parser::{base64, filename, ParseResult}; pub fn space(reader: &mut Reader) -> ParseResult<'static, Whitespace> { let start = reader.state.clone(); @@ -595,9 +592,8 @@ pub fn hex_digit(reader: &mut Reader) -> ParseResult<'static, u32> { #[cfg(test)] mod tests { - use crate::ast::Pos; - use super::*; + use crate::ast::Pos; #[test] fn test_space() { diff --git a/packages/hurl_core/src/parser/query.rs b/packages/hurl_core/src/parser/query.rs index 392489f83..0cc5ead15 100644 --- a/packages/hurl_core/src/parser/query.rs +++ b/packages/hurl_core/src/parser/query.rs @@ -16,14 +16,12 @@ * */ use crate::ast::*; -use crate::parser::{Error, ParseError}; - -use super::combinators::*; -use super::cookiepath::cookiepath; -use super::primitives::*; -use super::reader::Reader; -use super::string::*; -use super::ParseResult; +use crate::parser::combinators::*; +use crate::parser::cookiepath::cookiepath; +use crate::parser::primitives::*; +use crate::parser::reader::Reader; +use crate::parser::string::*; +use crate::parser::{Error, ParseError, ParseResult}; pub fn query(reader: &mut Reader) -> ParseResult<'static, Query> { let start = reader.state.pos.clone(); diff --git a/packages/hurl_core/src/parser/sections.rs b/packages/hurl_core/src/parser/sections.rs index 098e503f1..eaa5759a9 100644 --- a/packages/hurl_core/src/parser/sections.rs +++ b/packages/hurl_core/src/parser/sections.rs @@ -16,17 +16,15 @@ * */ use crate::ast::*; +use crate::parser::combinators::*; +use crate::parser::error::*; use crate::parser::filter::filters; - -use super::combinators::*; -use super::error::*; -use super::filename; -use super::predicate::predicate; -use super::primitives::*; -use super::query::query; -use super::reader::Reader; -use super::string::*; -use super::ParseResult; +use crate::parser::predicate::predicate; +use crate::parser::primitives::*; +use crate::parser::query::query; +use crate::parser::reader::Reader; +use crate::parser::string::*; +use crate::parser::{filename, ParseResult}; pub fn request_sections(reader: &mut Reader) -> ParseResult<'static, Vec
> { let sections = zero_or_more(request_section, reader)?; diff --git a/packages/hurl_core/src/parser/string.rs b/packages/hurl_core/src/parser/string.rs index ed5435ed9..816ccb76c 100644 --- a/packages/hurl_core/src/parser/string.rs +++ b/packages/hurl_core/src/parser/string.rs @@ -16,18 +16,16 @@ * */ use crate::ast::*; +use crate::parser::combinators::*; +use crate::parser::error::*; +use crate::parser::primitives::*; +use crate::parser::reader::Reader; +use crate::parser::{template, ParseResult}; -use super::combinators::*; -use super::error::*; -use super::primitives::*; -use super::reader::Reader; -use super::template; -use super::ParseResult; - -// Steps: -// 1- parse String until end of stream or end of line or # -// the string does not contain trailing space -// 2- templatize +/// Steps: +/// 1- parse String until end of stream or end of line or # +/// the string does not contain trailing space +/// 2- templatize pub fn unquoted_template(reader: &mut Reader) -> ParseResult<'static, Template> { let start = reader.state.clone(); let mut chars = vec![]; @@ -328,9 +326,10 @@ fn hex_value(reader: &mut Reader) -> ParseResult<'static, u32> { #[cfg(test)] mod tests { - use super::*; use std::time::SystemTime; + use super::*; + #[test] fn test_unquoted_template_empty() { let mut reader = Reader::init(""); diff --git a/packages/hurl_core/src/parser/template.rs b/packages/hurl_core/src/parser/template.rs index 25c74dc53..3bae2e56b 100644 --- a/packages/hurl_core/src/parser/template.rs +++ b/packages/hurl_core/src/parser/template.rs @@ -15,13 +15,9 @@ * limitations under the License. * */ - use crate::ast::{Pos, SourceInfo, TemplateElement}; - -use super::error; -use super::expr; -use super::reader::*; -use super::ParseResult; +use crate::parser::reader::*; +use crate::parser::{error, expr, ParseResult}; pub struct EncodedString { pub source_info: SourceInfo, @@ -132,9 +128,8 @@ pub fn templatize(encoded_string: EncodedString) -> ParseResult<'static, Vec ParseResult<'static, Template> { // Can not be json-encoded, nor empty. diff --git a/packages/hurl_core/src/parser/xml.rs b/packages/hurl_core/src/parser/xml.rs index 34e4d2a49..274674327 100644 --- a/packages/hurl_core/src/parser/xml.rs +++ b/packages/hurl_core/src/parser/xml.rs @@ -18,10 +18,9 @@ use sxd_document::parser; use crate::ast::Pos; - -use super::error::*; -use super::reader::Reader; -use super::ParseResult; +use crate::parser::error::*; +use crate::parser::reader::Reader; +use crate::parser::ParseResult; pub fn parse(reader: &mut Reader) -> ParseResult<'static, String> { let mut buf = String::from(""); diff --git a/packages/hurl_core/tests/json.rs b/packages/hurl_core/tests/json.rs index fee74ff3e..9c095aa1c 100644 --- a/packages/hurl_core/tests/json.rs +++ b/packages/hurl_core/tests/json.rs @@ -15,11 +15,12 @@ * limitations under the License. * */ -use hurl_core::ast::JsonValue; use std::fs; use std::fs::File; use std::io::Read; +use hurl_core::ast::JsonValue; + #[test] fn debug() { let content = r#""{{name}}""#; diff --git a/packages/hurlfmt/src/cli/fs.rs b/packages/hurlfmt/src/cli/fs.rs index 6c0656ddf..abdcf2b08 100644 --- a/packages/hurlfmt/src/cli/fs.rs +++ b/packages/hurlfmt/src/cli/fs.rs @@ -15,12 +15,12 @@ * limitations under the License. * */ - -use crate::cli::CliError; use std::fs; use std::fs::File; use std::io::prelude::*; +use crate::cli::CliError; + /// Remove BOM from the input bytes fn strip_bom(bytes: &mut Vec) { if bytes.starts_with(&[0xefu8, 0xbb, 0xbf]) { diff --git a/packages/hurlfmt/src/cli/logger.rs b/packages/hurlfmt/src/cli/logger.rs index c127d72a1..98367e7c1 100644 --- a/packages/hurlfmt/src/cli/logger.rs +++ b/packages/hurlfmt/src/cli/logger.rs @@ -16,7 +16,6 @@ * */ use colored::*; - use hurl_core::error::Error; use hurl_core::parser; diff --git a/packages/hurlfmt/src/cli/options.rs b/packages/hurlfmt/src/cli/options.rs index 7198d1284..07cb5f9d8 100644 --- a/packages/hurlfmt/src/cli/options.rs +++ b/packages/hurlfmt/src/cli/options.rs @@ -15,7 +15,6 @@ * limitations under the License. * */ - use clap::ArgMatches; pub fn get_string(matches: &ArgMatches, name: &str) -> Option { diff --git a/packages/hurlfmt/src/format/json.rs b/packages/hurlfmt/src/format/json.rs index f8cdd8a33..f758cb08e 100644 --- a/packages/hurlfmt/src/format/json.rs +++ b/packages/hurlfmt/src/format/json.rs @@ -15,10 +15,8 @@ * limitations under the License. * */ - use base64::engine::general_purpose; use base64::Engine; - use hurl_core::ast::*; use super::serialize_json::*; diff --git a/packages/hurlfmt/src/format/mod.rs b/packages/hurlfmt/src/format/mod.rs index 95d52c702..9949047c5 100644 --- a/packages/hurlfmt/src/format/mod.rs +++ b/packages/hurlfmt/src/format/mod.rs @@ -15,7 +15,6 @@ * limitations under the License. * */ - pub use self::json::format as format_json; pub use self::text::format as format_text; pub use self::token::{Token, Tokenizable}; diff --git a/packages/hurlfmt/src/format/text.rs b/packages/hurlfmt/src/format/text.rs index 58a0f32b7..788f244e1 100644 --- a/packages/hurlfmt/src/format/text.rs +++ b/packages/hurlfmt/src/format/text.rs @@ -16,10 +16,9 @@ * */ use colored::*; - use hurl_core::ast::*; -use super::token::*; +use crate::format::token::*; pub fn format(hurl_file: HurlFile, color: bool) -> String { let mut buffer = String::from(""); diff --git a/packages/hurlfmt/src/format/token.rs b/packages/hurlfmt/src/format/token.rs index 151c83fed..5f761f7bf 100644 --- a/packages/hurlfmt/src/format/token.rs +++ b/packages/hurlfmt/src/format/token.rs @@ -15,7 +15,6 @@ * limitations under the License. * */ - use hurl_core::ast::*; #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/packages/hurlfmt/src/linter/error.rs b/packages/hurlfmt/src/linter/error.rs index e216b9e50..c51724ef0 100644 --- a/packages/hurlfmt/src/linter/error.rs +++ b/packages/hurlfmt/src/linter/error.rs @@ -15,7 +15,6 @@ * limitations under the License. * */ - use hurl_core::ast::SourceInfo; use hurl_core::error::Error; diff --git a/packages/hurlfmt/src/linter/mod.rs b/packages/hurlfmt/src/linter/mod.rs index ddcf5f99b..36d80d061 100644 --- a/packages/hurlfmt/src/linter/mod.rs +++ b/packages/hurlfmt/src/linter/mod.rs @@ -15,9 +15,9 @@ * limitations under the License. * */ +pub use rules::{check_hurl_file, lint_hurl_file}; pub use self::core::{Error, LinterError}; -pub use rules::{check_hurl_file, lint_hurl_file}; mod core; mod error; mod rules; diff --git a/packages/hurlfmt/src/linter/rules.rs b/packages/hurlfmt/src/linter/rules.rs index 855c7f772..ff9b069ab 100644 --- a/packages/hurlfmt/src/linter/rules.rs +++ b/packages/hurlfmt/src/linter/rules.rs @@ -17,7 +17,7 @@ */ use hurl_core::ast::*; -use super::core::{Error, LinterError}; +use crate::linter::core::{Error, LinterError}; /// Returns lint errors for the `hurl_file`. pub fn check_hurl_file(hurl_file: &HurlFile) -> Vec { diff --git a/packages/hurlfmt/src/main.rs b/packages/hurlfmt/src/main.rs index c01ed26bf..9dec1c305 100644 --- a/packages/hurlfmt/src/main.rs +++ b/packages/hurlfmt/src/main.rs @@ -15,17 +15,14 @@ * limitations under the License. * */ -use std::io::Write; -use std::io::{self, Read}; +use std::io::{self, Read, Write}; use std::path::Path; use std::process; use atty::Stream; use clap::ArgAction; - use hurl_core::parser; -use hurlfmt::format; -use hurlfmt::{cli, linter}; +use hurlfmt::{cli, format, linter}; #[cfg(target_family = "unix")] pub fn init_colored() { diff --git a/packages/hurlfmt/tests/json.rs b/packages/hurlfmt/tests/json.rs index 6131e4428..56273885a 100644 --- a/packages/hurlfmt/tests/json.rs +++ b/packages/hurlfmt/tests/json.rs @@ -18,12 +18,11 @@ use std::fs; -use proptest::prelude::prop::test_runner::TestRunner; -use proptest::prelude::*; - use hurl_core::ast::*; use hurl_core::parser::{parse_json, Reader}; use hurlfmt::format::{Token, Tokenizable}; +use proptest::prelude::prop::test_runner::TestRunner; +use proptest::prelude::*; fn whitespace() -> BoxedStrategy { prop_oneof![ diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 000000000..84037ff31 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,4 @@ +# Reorganize import. Must be used with nightly. +# See for option description +#group_imports = "StdExternalCrate" +#imports_granularity = "Module" \ No newline at end of file