Reorganize import.

This commit is contained in:
jcamiel 2023-03-03 16:48:24 +01:00
parent 65f85f9e53
commit 3361aaaf24
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
97 changed files with 382 additions and 458 deletions

View File

@ -16,9 +16,9 @@
* *
*/ */
use cc::Build;
use std::path::Path; use std::path::Path;
use cc::Build;
#[cfg(windows)] #[cfg(windows)]
use winres::WindowsResource; use winres::WindowsResource;

View File

@ -15,11 +15,12 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use crate::cli::CliError;
use std::fs; use std::fs;
use std::fs::File; use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;
use crate::cli::CliError;
/// Remove BOM from the input bytes /// Remove BOM from the input bytes
fn strip_bom(bytes: &mut Vec<u8>) { fn strip_bom(bytes: &mut Vec<u8>) {
if bytes.starts_with(&[0xefu8, 0xbb, 0xbf]) { if bytes.starts_with(&[0xefu8, 0xbb, 0xbf]) {

View File

@ -15,11 +15,9 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use hurl_core::ast::Entry; use hurl_core::ast::Entry;
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
use hurl_core::ast::{MultipartParam, Request, SectionValue}; use hurl_core::ast::{MultipartParam, Request, SectionValue};
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
use { use {
std::io::{stderr, stdin, Write}, std::io::{stderr, stdin, Write},

View File

@ -20,18 +20,16 @@ mod interactive;
mod options; mod options;
mod variables; mod variables;
use hurl::{output, report};
use std::error::Error; use std::error::Error;
use std::fmt; use std::fmt;
use hurl::{output, report};
pub use self::fs::read_to_string; pub use self::fs::read_to_string;
pub use self::options::app; pub use self::options::{
pub use self::options::output_color; app, get_strings, has_flag, output_color, parse_options, CliOptions, OutputType,
pub use self::options::parse_options; };
pub use self::options::{get_strings, has_flag}; pub use self::variables::{parse as parse_variable, parse_value as parse_variable_value};
pub use self::options::{CliOptions, OutputType};
pub use self::variables::parse as parse_variable;
pub use self::variables::parse_value as parse_variable_value;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct CliError { pub struct CliError {

View File

@ -15,14 +15,6 @@
* limitations under the License. * 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::collections::HashMap;
use std::env; use std::env;
use std::fs::File; use std::fs::File;
@ -30,6 +22,15 @@ use std::io::{BufRead, BufReader};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::time::Duration; 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)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct CliOptions { pub struct CliOptions {
pub cacert_file: Option<String>, pub cacert_file: Option<String>,

View File

@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use crate::cli::CliError; use crate::cli::CliError;
use crate::runner::Value; use crate::runner::Value;

View File

@ -15,9 +15,10 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use lazy_static::lazy_static;
use std::collections::HashMap; use std::collections::HashMap;
use lazy_static::lazy_static;
// HTML5 named character references // HTML5 named character references
// //
// Generated from https://html.spec.whatwg.org/entities.json and // Generated from https://html.spec.whatwg.org/entities.json and

View File

@ -15,10 +15,12 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use crate::html::entities::HTML5_ENTITIES; use std::collections::HashMap;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use regex::{Captures, Regex}; 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 // Ref https://html.spec.whatwg.org/#decimal-character-reference-start-state
lazy_static! { lazy_static! {

View File

@ -15,10 +15,11 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use std::collections::HashMap;
use chrono::{DateTime, NaiveDateTime, Utc};
use crate::http::easy_ext::CertInfo; use crate::http::easy_ext::CertInfo;
use chrono::{DateTime, NaiveDateTime, Utc};
use std::collections::HashMap;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Certificate { pub struct Certificate {

View File

@ -17,28 +17,27 @@
*/ */
use std::io::Read; use std::io::Read;
use std::str; use std::str;
use std::str::FromStr;
use curl::easy;
use encoding::all::ISO_8859_1;
use encoding::{DecoderTrap, Encoding};
use std::time::Instant; 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::general_purpose;
use base64::Engine; use base64::Engine;
use curl::easy;
use curl::easy::{List, SslOpt}; use curl::easy::{List, SslOpt};
use std::str::FromStr; use encoding::all::ISO_8859_1;
use encoding::{DecoderTrap, Encoding};
use url::Url; 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. /// Defines an HTTP client to execute HTTP requests.
/// ///
/// Most of the methods are delegated to libcurl functions, while some /// Most of the methods are delegated to libcurl functions, while some

View File

@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use core::fmt; use core::fmt;
use std::str::FromStr; use std::str::FromStr;

View File

@ -15,11 +15,12 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use std::ffi::CStr;
use std::ptr;
use curl::easy::Easy; use curl::easy::Easy;
use curl::Error; use curl::Error;
use curl_sys::{curl_certinfo, curl_slist}; use curl_sys::{curl_certinfo, curl_slist};
use std::ffi::CStr;
use std::ptr;
/// Represents certificate information. /// Represents certificate information.
/// `data` has format "name:content"; /// `data` has format "name:content";
@ -125,10 +126,11 @@ fn to_list(slist: *mut curl_slist) -> Vec<String> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::to_list;
use std::ffi::CString; use std::ffi::CString;
use std::ptr; use std::ptr;
use super::to_list;
#[test] #[test]
fn convert_curl_slist_to_vec() { fn convert_curl_slist_to_vec() {
let mut slist = ptr::null_mut(); let mut slist = ptr::null_mut();

View File

@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use core::fmt; use core::fmt;
/// Represents an HTTP header /// Represents an HTTP header
@ -40,12 +39,7 @@ impl Header {
} }
} }
/// Returns all header values for given name /// Returns all `headers` values for given `name`.
///
/// # Arguments
///
/// * `headers` - A list of HTTP headers
/// * `name` - A name to filter header (case insensitively)
pub fn get_values(headers: &[Header], name: &str) -> Vec<String> { pub fn get_values(headers: &[Header], name: &str) -> Vec<String> {
headers headers
.iter() .iter()

View File

@ -15,12 +15,11 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::core::*;
use super::Header;
use crate::http::{header, HttpError};
use url::Url; use url::Url;
use crate::http::core::*;
use crate::http::{header, Header, HttpError};
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Request { pub struct Request {
pub url: String, pub url: String,

View File

@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use crate::http::{debug, mimetype, Request}; use crate::http::{debug, mimetype, Request};
use crate::util::logger::Logger; use crate::util::logger::Logger;

View File

@ -15,9 +15,9 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use encoding::{DecoderTrap, EncodingRef};
use crate::http::{mimetype, HttpError, Request}; use crate::http::{mimetype, HttpError, Request};
use encoding::{DecoderTrap, EncodingRef};
impl Request { impl Request {
/// Returns character encoding of the HTTP request. /// Returns character encoding of the HTTP request.

View File

@ -15,11 +15,10 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::{header, Header};
use core::fmt; use core::fmt;
use super::core::*; use crate::http::core::*;
use crate::http::{header, Header};
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct RequestSpec { pub struct RequestSpec {

View File

@ -15,12 +15,12 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::core::*;
use super::RequestSpec;
use crate::http::*;
use crate::util::path::ContextDir;
use std::collections::HashMap; use std::collections::HashMap;
use crate::http::core::*;
use crate::http::{RequestSpec, *};
use crate::util::path::ContextDir;
impl RequestSpec { impl RequestSpec {
/// Returns this request as curl arguments. /// Returns this request as curl arguments.
/// It does not contain the requests cookies (they will be accessed from the client) /// 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)] #[cfg(test)]
pub mod tests { pub mod tests {
use std::path::Path;
use super::*; use super::*;
use crate::http; use crate::http;
use std::path::Path;
fn form_http_request() -> RequestSpec { fn form_http_request() -> RequestSpec {
RequestSpec { RequestSpec {

View File

@ -15,12 +15,12 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::{header, Header};
use crate::http::certificate::Certificate;
use core::fmt; use core::fmt;
use std::time::Duration; use std::time::Duration;
use crate::http::certificate::Certificate;
use crate::http::{header, Header};
/// Represents an HTTP response. /// Represents an HTTP response.
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Response { pub struct Response {

View File

@ -15,8 +15,7 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::Response; use crate::http::{Response, ResponseCookie};
use super::ResponseCookie;
impl Response { impl Response {
pub fn cookies(&self) -> Vec<ResponseCookie> { pub fn cookies(&self) -> Vec<ResponseCookie> {

View File

@ -16,7 +16,6 @@
* *
*/ */
use encoding::{DecoderTrap, EncodingRef};
/// ///
/// Decompresses body response /// Decompresses body response
/// using the Content-Encoding response header /// 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 /// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
use std::io::prelude::*; use std::io::prelude::*;
use encoding::{DecoderTrap, EncodingRef};
use crate::http::{mimetype, HttpError, Response}; use crate::http::{mimetype, HttpError, Response};
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
@ -35,11 +36,7 @@ pub enum ContentEncoding {
} }
impl ContentEncoding { impl ContentEncoding {
/// Returns an encoding from an HTTP header value. /// Returns an encoding from an HTTP header value `s`.
///
/// # Arguments
///
/// * `s` - A Content-Encoding header value
pub fn parse(s: &str) -> Result<ContentEncoding, HttpError> { pub fn parse(s: &str) -> Result<ContentEncoding, HttpError> {
match s { match s {
"br" => Ok(ContentEncoding::Brotli), "br" => Ok(ContentEncoding::Brotli),
@ -52,11 +49,7 @@ impl ContentEncoding {
} }
} }
/// Decompresses bytes. /// Decompresses `data` bytes.
///
/// # Arguments
///
/// * `data` - A compressed bytes array
pub fn decode(&self, data: &[u8]) -> Result<Vec<u8>, HttpError> { pub fn decode(&self, data: &[u8]) -> Result<Vec<u8>, HttpError> {
match self { match self {
ContentEncoding::Identity => Ok(data.to_vec()), ContentEncoding::Identity => Ok(data.to_vec()),
@ -132,11 +125,7 @@ impl Response {
} }
} }
/// Decompresses Brotli compressed data. /// Decompresses Brotli compressed `data`.
///
/// # Arguments
///
/// * data - Compressed bytes.
fn uncompress_brotli(data: &[u8]) -> Result<Vec<u8>, HttpError> { fn uncompress_brotli(data: &[u8]) -> Result<Vec<u8>, HttpError> {
let buffer_size = 4096; let buffer_size = 4096;
let mut reader = brotli::Decompressor::new(data, buffer_size); let mut reader = brotli::Decompressor::new(data, buffer_size);
@ -149,11 +138,7 @@ fn uncompress_brotli(data: &[u8]) -> Result<Vec<u8>, HttpError> {
} }
} }
/// Decompresses GZip compressed data. /// Decompresses GZip compressed `data`.
///
/// # Arguments
///
/// * data - Compressed bytes.
fn uncompress_gzip(data: &[u8]) -> Result<Vec<u8>, HttpError> { fn uncompress_gzip(data: &[u8]) -> Result<Vec<u8>, HttpError> {
let mut decoder = match libflate::gzip::Decoder::new(data) { let mut decoder = match libflate::gzip::Decoder::new(data) {
Ok(v) => v, Ok(v) => v,
@ -172,11 +157,7 @@ fn uncompress_gzip(data: &[u8]) -> Result<Vec<u8>, HttpError> {
} }
} }
/// Decompresses Zlib compressed data. /// Decompresses Zlib compressed `data`.
///
/// # Arguments
///
/// * data - Compressed bytes.
fn uncompress_zlib(data: &[u8]) -> Result<Vec<u8>, HttpError> { fn uncompress_zlib(data: &[u8]) -> Result<Vec<u8>, HttpError> {
let mut decoder = match libflate::zlib::Decoder::new(data) { let mut decoder = match libflate::zlib::Decoder::new(data) {
Ok(v) => v, Ok(v) => v,

View File

@ -16,10 +16,11 @@
* *
*/ */
use regex::Regex;
use std::default::Default; use std::default::Default;
use std::time::Duration; use std::time::Duration;
use regex::Regex;
use crate::http::*; use crate::http::*;
use crate::util::logger::LoggerBuilder; use crate::util::logger::LoggerBuilder;
use crate::util::path::ContextDir; use crate::util::path::ContextDir;
@ -1112,9 +1113,10 @@ fn test_version() {
// This test function can be used to reproduce bug // This test function can be used to reproduce bug
#[test] #[test]
fn test_libcurl_directly() { fn test_libcurl_directly() {
use curl;
use std::io::{stdout, Write}; use std::io::{stdout, Write};
use curl;
let mut easy = curl::easy::Easy::new(); let mut easy = curl::easy::Easy::new();
easy.url("http://localhost:8000/hello").unwrap(); easy.url("http://localhost:8000/hello").unwrap();
easy.write_function(|data| { easy.write_function(|data| {

View File

@ -18,10 +18,11 @@
use std::collections::HashMap; use std::collections::HashMap;
use hurl_core::ast::*;
use crate::runner; use crate::runner;
use crate::runner::RunnerOptions; use crate::runner::RunnerOptions;
use crate::util::logger::LoggerBuilder; use crate::util::logger::LoggerBuilder;
use hurl_core::ast::*;
fn hello_request() -> Request { fn hello_request() -> Request {
// GET http://localhost;8000/hello // GET http://localhost;8000/hello

View File

@ -15,12 +15,13 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use chrono::{DateTime, Utc};
use crate::http::{ use crate::http::{
Certificate, Cookie, Header, Param, Request, RequestCookie, Response, ResponseCookie, Version, Certificate, Cookie, Header, Param, Request, RequestCookie, Response, ResponseCookie, Version,
}; };
use crate::runner::{AssertResult, Call, CaptureResult, EntryResult, HurlResult}; use crate::runner::{AssertResult, Call, CaptureResult, EntryResult, HurlResult};
use crate::util::logger; use crate::util::logger;
use chrono::{DateTime, Utc};
impl HurlResult { impl HurlResult {
/// Serializes an [`HurlResult`] to a JSON representation. /// Serializes an [`HurlResult`] to a JSON representation.

View File

@ -16,10 +16,11 @@
* *
*/ */
use crate::runner::Value;
use base64::engine::general_purpose; use base64::engine::general_purpose;
use base64::Engine; use base64::Engine;
use crate::runner::Value;
impl Value { impl Value {
pub fn to_json(&self) -> serde_json::Value { pub fn to_json(&self) -> serde_json::Value {
match self { match self {

View File

@ -16,9 +16,10 @@
* *
*/ */
use super::ast::*;
use float_cmp::approx_eq; use float_cmp::approx_eq;
use super::ast::*;
pub type JsonpathResult = Vec<serde_json::Value>; pub type JsonpathResult = Vec<serde_json::Value>;
impl Query { impl Query {

View File

@ -17,8 +17,7 @@
*/ */
use super::super::ast::*; use super::super::ast::*;
use super::error::{Error, ParseError}; use super::error::{Error, ParseError};
use super::ParseResult; use super::{ParseResult, Reader};
use super::Reader;
pub fn natural(reader: &mut Reader) -> ParseResult<'static, usize> { pub fn natural(reader: &mut Reader) -> ParseResult<'static, usize> {
let start = reader.state.clone(); let start = reader.state.clone();

View File

@ -20,10 +20,12 @@
//! These tests are not located at the root of the project, like Rust integration tests //! 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. //! 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 std::fs::read_to_string;
use serde_json::json;
use crate::jsonpath;
fn bookstore_value() -> serde_json::Value { fn bookstore_value() -> serde_json::Value {
let s = read_to_string("tests/bookstore.json").expect("could not read string from file"); 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") serde_json::from_str(s.as_str()).expect("could not parse json file")

View File

@ -25,13 +25,10 @@ use std::time::Instant;
use atty::Stream; use atty::Stream;
use clap::Command; use clap::Command;
use colored::*; use colored::*;
use hurl::report;
use hurl::report::html; use hurl::report::html;
use hurl::runner;
use hurl::runner::HurlResult; use hurl::runner::HurlResult;
use hurl::util::logger::{BaseLogger, Logger, LoggerBuilder}; 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::ast::HurlFile;
use hurl_core::parser; use hurl_core::parser;
use report::junit; use report::junit;

View File

@ -25,12 +25,13 @@ mod json;
mod raw; mod raw;
mod stdout; mod stdout;
pub use self::json::write_json;
pub use self::raw::write_body;
use std::fmt; use std::fmt;
use std::io::Write; use std::io::Write;
use std::path::Path; use std::path::Path;
pub use self::json::write_json;
pub use self::raw::write_body;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Error { pub struct Error {
pub message: String, pub message: String,

View File

@ -15,15 +15,15 @@
* limitations under the License. * 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 colored::Colorize;
use hurl_core::ast::SourceInfo; use hurl_core::ast::SourceInfo;
use hurl_core::error::Error; 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`. /// 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 /// If `filename` is `None`, stdout is used. If `include_headers` is true, the last HTTP

View File

@ -15,12 +15,14 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use crate::output::Error;
#[cfg(target_family = "windows")]
use atty::Stream;
use std::io; use std::io;
use std::io::Write; use std::io::Write;
#[cfg(target_family = "windows")]
use atty::Stream;
use crate::output::Error;
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
pub(crate) fn write_stdout(buf: &[u8]) -> Result<(), Error> { pub(crate) fn write_stdout(buf: &[u8]) -> Result<(), Error> {
let stdout = io::stdout(); let stdout = io::stdout();

View File

@ -20,12 +20,14 @@
mod testcase; mod testcase;
use crate::report::Error;
use chrono::{DateTime, Local};
use std::io::Write; use std::io::Write;
use std::path::Path; use std::path::Path;
use chrono::{DateTime, Local};
pub use testcase::Testcase; pub use testcase::Testcase;
use crate::report::Error;
/// The test result to be displayed in an HTML page /// The test result to be displayed in an HTML page
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
struct HTMLResult { struct HTMLResult {

View File

@ -15,13 +15,15 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::Error;
use crate::runner::HurlResult;
use hurl_core::ast::HurlFile;
use std::io::Write; use std::io::Write;
use std::path::Path; use std::path::Path;
use hurl_core::ast::HurlFile;
use uuid::Uuid; use uuid::Uuid;
use super::Error;
use crate::runner::HurlResult;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Testcase { pub struct Testcase {
pub id: String, pub id: String,

View File

@ -56,11 +56,13 @@
//! //!
mod testcase; mod testcase;
use crate::report::Error;
use std::fs::File; use std::fs::File;
pub use testcase::Testcase; pub use testcase::Testcase;
use xmltree::{Element, XMLNode}; use xmltree::{Element, XMLNode};
use crate::report::Error;
/// Creates a JUnit from a list of `testcases`. /// Creates a JUnit from a list of `testcases`.
pub fn write_report(filename: &str, testcases: &[Testcase]) -> Result<(), Error> { pub fn write_report(filename: &str, testcases: &[Testcase]) -> Result<(), Error> {
let mut testsuites = vec![]; let mut testsuites = vec![];

View File

@ -15,9 +15,10 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use xmltree::{Element, XMLNode};
use crate::runner::HurlResult; use crate::runner::HurlResult;
use crate::util::logger; use crate::util::logger;
use xmltree::{Element, XMLNode};
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Testcase { pub struct Testcase {
@ -99,9 +100,10 @@ impl Testcase {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use hurl_core::ast::SourceInfo;
use crate::report::junit::testcase::Testcase; use crate::report::junit::testcase::Testcase;
use crate::runner::{EntryResult, Error, HurlResult, RunnerError}; use crate::runner::{EntryResult, Error, HurlResult, RunnerError};
use hurl_core::ast::SourceInfo;
#[test] #[test]
fn test_create_testcase_success() { fn test_create_testcase_success() {

View File

@ -15,18 +15,16 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use std::collections::HashMap; use std::collections::HashMap;
use crate::http;
use crate::runner::filter::eval_filters;
use hurl_core::ast::*; use hurl_core::ast::*;
use super::core::*; use crate::http;
use super::core::{Error, RunnerError}; use crate::runner::core::{Error, RunnerError, *};
use super::predicate::eval_predicate; use crate::runner::filter::eval_filters;
use super::query::eval_query; use crate::runner::predicate::eval_predicate;
use super::value::Value; use crate::runner::query::eval_query;
use crate::runner::value::Value;
impl AssertResult { impl AssertResult {
/// Evaluates an assert and returns `None` if assert is succeeded or an `Error` if failed. /// 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)] #[cfg(test)]
pub mod tests { pub mod tests {
use hurl_core::ast::SourceInfo;
use super::super::query; use super::super::query;
use super::*; use super::*;
use crate::http::xml_three_users_http_response; use crate::http::xml_three_users_http_response;
use hurl_core::ast::SourceInfo;
// xpath //user countEquals 3 // xpath //user countEquals 3
pub fn assert_count_user() -> Assert { pub fn assert_count_user() -> Assert {

View File

@ -15,17 +15,19 @@
* limitations under the License. * 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::collections::HashMap;
use std::path::PathBuf; 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( pub fn eval_body(
body: &Body, body: &Body,
variables: &HashMap<String, Value>, variables: &HashMap<String, Value>,
@ -88,9 +90,10 @@ pub fn eval_file(filename: &Filename, context_dir: &ContextDir) -> Result<Vec<u8
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use hurl_core::ast::SourceInfo;
use std::path::Path; use std::path::Path;
use hurl_core::ast::SourceInfo;
use super::*; use super::*;
#[test] #[test]

View File

@ -15,17 +15,15 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use std::collections::HashMap; use std::collections::HashMap;
use crate::http;
use crate::runner::filter::eval_filters;
use hurl_core::ast::*; use hurl_core::ast::*;
use super::core::RunnerError; use crate::http;
use super::core::{CaptureResult, Error}; use crate::runner::core::{CaptureResult, Error, RunnerError};
use super::query::eval_query; use crate::runner::filter::eval_filters;
use super::value::Value; use crate::runner::query::eval_query;
use crate::runner::value::Value;
/// Evaluates a `capture` with `variables` map and `http_response`, returns a /// Evaluates a `capture` with `variables` map and `http_response`, returns a
/// [`CaptureResult`] on success or an [`Error`] . /// [`CaptureResult`] on success or an [`Error`] .
@ -57,9 +55,10 @@ pub fn eval_capture(
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
use hurl_core::ast::{Pos, SourceInfo};
use self::super::super::query; use self::super::super::query;
use super::*; use super::*;
use hurl_core::ast::{Pos, SourceInfo};
pub fn user_count_capture() -> Capture { pub fn user_count_capture() -> Capture {
// non scalar value // non scalar value

View File

@ -17,10 +17,10 @@
*/ */
use std::path::PathBuf; use std::path::PathBuf;
use crate::http;
use hurl_core::ast::SourceInfo; use hurl_core::ast::SourceInfo;
use super::value::Value; use super::value::Value;
use crate::http;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum Verbosity { pub enum Verbosity {

View File

@ -18,20 +18,17 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::time::Duration; use std::time::Duration;
use crate::http;
use crate::http::ClientOptions;
use crate::util::logger::Logger;
use hurl_core::ast::*; use hurl_core::ast::*;
use super::core::*; use crate::http;
use super::core::{Error, RunnerError}; use crate::http::ClientOptions;
use super::request::eval_request; use crate::runner::core::{Error, RunnerError, *};
use super::response::{eval_asserts, eval_captures}; use crate::runner::request::{cookie_storage_clear, cookie_storage_set, eval_request};
use super::value::Value; use crate::runner::response::{eval_asserts, eval_captures, eval_version_status_asserts};
use crate::runner::request::{cookie_storage_clear, cookie_storage_set};
use crate::runner::response::eval_version_status_asserts;
use crate::runner::runner_options::RunnerOptions; use crate::runner::runner_options::RunnerOptions;
use crate::runner::template::eval_template; 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`]. /// Runs an `entry` with `http_client` and returns one [`EntryResult`].
/// ///

View File

@ -15,11 +15,12 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use hurl_core::ast::SourceInfo;
use hurl_core::error::Error;
use crate::http::HttpError; use crate::http::HttpError;
use crate::runner; use crate::runner;
use crate::runner::RunnerError; use crate::runner::RunnerError;
use hurl_core::ast::SourceInfo;
use hurl_core::error::Error;
/// Textual Output for runner errors /// Textual Output for runner errors
impl Error for runner::Error { impl Error for runner::Error {

View File

@ -19,8 +19,8 @@ use std::collections::HashMap;
use hurl_core::ast::Expr; use hurl_core::ast::Expr;
use super::core::{Error, RunnerError}; use crate::runner::core::{Error, RunnerError};
use super::value::Value; use crate::runner::value::Value;
/// Evaluates the expression `expr` with `variables` map and `http_response`, returns a /// Evaluates the expression `expr` with `variables` map and `http_response`, returns a
/// [`Value`] on success or an [`Error`] . /// [`Value`] on success or an [`Error`] .

View File

@ -15,14 +15,13 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use chrono::NaiveDateTime;
use std::collections::HashMap; use std::collections::HashMap;
use chrono::NaiveDateTime;
use hurl_core::ast::{Filter, FilterValue, RegexValue, SourceInfo, Template};
use percent_encoding::AsciiSet; use percent_encoding::AsciiSet;
use crate::html; use crate::html;
use hurl_core::ast::{Filter, FilterValue, RegexValue, SourceInfo, Template};
use crate::runner::regex::eval_regex_value; use crate::runner::regex::eval_regex_value;
use crate::runner::template::eval_template; use crate::runner::template::eval_template;
use crate::runner::{Error, RunnerError, Value}; use crate::runner::{Error, RunnerError, Value};
@ -346,11 +345,12 @@ fn eval_to_int(value: &Value, source_info: &SourceInfo, assert: bool) -> Result<
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
use super::*;
use chrono::offset::Utc; use chrono::offset::Utc;
use chrono::prelude::*; use chrono::prelude::*;
use hurl_core::ast::{FilterValue, SourceInfo, Template, TemplateElement, Whitespace}; use hurl_core::ast::{FilterValue, SourceInfo, Template, TemplateElement, Whitespace};
use super::*;
pub fn filter_count() -> Filter { pub fn filter_count() -> Filter {
Filter { Filter {
source_info: SourceInfo::new(1, 1, 1, 6), source_info: SourceInfo::new(1, 1, 1, 6),

View File

@ -19,16 +19,15 @@ use std::collections::HashMap;
use std::thread; use std::thread;
use std::time::Instant; 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::VersionValue::VersionAnyLegacy;
use hurl_core::ast::*; 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 /// Runs a `hurl_file`, issue from the given `content`and `filename` and
/// returns a [`HurlResult`] upon completion. /// returns a [`HurlResult`] upon completion.
/// ///

View File

@ -20,9 +20,9 @@ use std::collections::HashMap;
use hurl_core::ast::{JsonListElement, JsonObjectElement, JsonValue, Template, TemplateElement}; use hurl_core::ast::{JsonListElement, JsonObjectElement, JsonValue, Template, TemplateElement};
use hurl_core::parser::{parse_json_boolean, parse_json_null, parse_json_number, Reader}; use hurl_core::parser::{parse_json_boolean, parse_json_null, parse_json_number, Reader};
use super::core::{Error, RunnerError}; use crate::runner::core::{Error, RunnerError};
use super::value::Value;
use crate::runner::template::eval_expression; use crate::runner::template::eval_expression;
use crate::runner::value::Value;
/// Evaluates a JSON value to a string given a set of `variables`. /// Evaluates a JSON value to a string given a set of `variables`.
/// If `keep_whitespace` is true, whitespace is preserved from the JSonValue, otherwise /// 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)] #[cfg(test)]
mod tests { mod tests {
use hurl_core::ast::*;
use super::super::core::RunnerError; use super::super::core::RunnerError;
use super::*; use super::*;
use hurl_core::ast::*;
pub fn json_hello_world_value() -> JsonValue { pub fn json_hello_world_value() -> JsonValue {
// "hello\u0020{{name}}!" // "hello\u0020{{name}}!"

View File

@ -15,12 +15,14 @@
* limitations under the License. * 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::json::eval_json_value;
use crate::runner::template::eval_template; use crate::runner::template::eval_template;
use crate::runner::{Error, Value}; 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. /// Renders to string a multiline body, given a set of variables.
pub fn eval_multiline( pub fn eval_multiline(
@ -55,14 +57,15 @@ pub fn eval_multiline(
#[cfg(test)] #[cfg(test)]
mod tests { 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 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 { fn whitespace() -> Whitespace {
Whitespace { Whitespace {
value: String::from(" "), value: String::from(" "),

View File

@ -15,17 +15,19 @@
* limitations under the License. * 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::collections::HashMap;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::path::Path; 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( pub fn eval_multipart_param(
multipart_param: &MultipartParam, multipart_param: &MultipartParam,
variables: &HashMap<String, Value>, variables: &HashMap<String, Value>,

View File

@ -18,15 +18,13 @@
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::HashMap; use std::collections::HashMap;
use hurl_core::ast::*;
use regex; use regex;
use hurl_core::ast::*; use crate::runner::core::{Error, PredicateResult};
use super::core::Error;
use super::template::eval_template;
use super::value::Value;
use crate::runner::core::PredicateResult;
use crate::runner::predicate_value::eval_predicate_value; use crate::runner::predicate_value::eval_predicate_value;
use crate::runner::template::eval_template;
use crate::runner::value::Value;
use crate::runner::RunnerError; use crate::runner::RunnerError;
pub fn eval_predicate( pub fn eval_predicate(
@ -829,8 +827,7 @@ fn contains(haystack: &[u8], needle: &[u8]) -> bool {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::AssertResult; use super::{AssertResult, *};
use super::*;
fn whitespace() -> Whitespace { fn whitespace() -> Whitespace {
Whitespace { Whitespace {

View File

@ -17,13 +17,13 @@
*/ */
use std::collections::HashMap; use std::collections::HashMap;
use crate::runner::multiline::eval_multiline;
use hurl_core::ast::*; use hurl_core::ast::*;
use super::core::Error; use crate::runner::core::Error;
use super::expr::eval_expr; use crate::runner::expr::eval_expr;
use super::template::eval_template; use crate::runner::multiline::eval_multiline;
use super::value::Value; use crate::runner::template::eval_template;
use crate::runner::value::Value;
pub fn eval_predicate_value( pub fn eval_predicate_value(
predicate_value: &PredicateValue, predicate_value: &PredicateValue,

View File

@ -15,19 +15,18 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use regex::Regex;
use std::collections::HashMap; 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 hurl_core::ast::*;
use regex::Regex;
use sha2::Digest; 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<Option<Value>, Error>; pub type QueryResult = Result<Option<Value>, Error>;
/// Evaluates this `query` and returns a [`QueryResult`], using the HTTP response `http_response` and `variables`. /// Evaluates this `query` and returns a [`QueryResult`], using the HTTP response `http_response` and `variables`.
@ -381,10 +380,11 @@ impl Value {
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
use super::*;
use hex_literal::hex; use hex_literal::hex;
use hurl_core::ast::{Pos, SourceInfo}; use hurl_core::ast::{Pos, SourceInfo};
use super::*;
pub fn xpath_invalid_query() -> Query { pub fn xpath_invalid_query() -> Query {
// xpath ??? // xpath ???
let whitespace = Whitespace { let whitespace = Whitespace {

View File

@ -15,12 +15,10 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use std::collections::HashMap; use std::collections::HashMap;
use regex::Regex;
use hurl_core::ast::RegexValue; use hurl_core::ast::RegexValue;
use regex::Regex;
use crate::runner::template::eval_template; use crate::runner::template::eval_template;
use crate::runner::{Error, RunnerError, Value}; use crate::runner::{Error, RunnerError, Value};

View File

@ -15,17 +15,19 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::body::eval_body; use std::collections::HashMap;
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 base64::engine::general_purpose; use base64::engine::general_purpose;
use base64::Engine; use base64::Engine;
use hurl_core::ast::*; 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`. /// Transforms an AST `request` to a spec request given a set of `variables`.
pub fn eval_request( pub fn eval_request(
@ -181,9 +183,10 @@ fn eval_method(method: &Method) -> http::Method {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use hurl_core::ast::SourceInfo;
use super::super::core::RunnerError; use super::super::core::RunnerError;
use super::*; use super::*;
use hurl_core::ast::SourceInfo;
fn whitespace() -> Whitespace { fn whitespace() -> Whitespace {
Whitespace { Whitespace {

View File

@ -15,19 +15,21 @@
* limitations under the License. * 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 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, /// 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`. /// given a set of `variables`, an actual `http_response` and a spec `response`.
pub fn eval_version_status_asserts( pub fn eval_version_status_asserts(
@ -326,11 +328,9 @@ pub fn eval_captures(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use self::super::super::{assert, capture};
use super::*; use super::*;
use self::super::super::assert;
use self::super::super::capture;
pub fn user_response() -> Response { pub fn user_response() -> Response {
let whitespace = Whitespace { let whitespace = Whitespace {
value: String::from(" "), value: String::from(" "),

View File

@ -15,10 +15,12 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use std::time::Duration;
use hurl_core::ast::Entry;
use crate::runner::Verbosity; use crate::runner::Verbosity;
use crate::util::path::ContextDir; use crate::util::path::ContextDir;
use hurl_core::ast::Entry;
use std::time::Duration;
pub struct RunnerOptionsBuilder { pub struct RunnerOptionsBuilder {
cacert_file: Option<String>, cacert_file: Option<String>,

View File

@ -19,8 +19,8 @@ use std::collections::HashMap;
use hurl_core::ast::*; use hurl_core::ast::*;
use super::core::{Error, RunnerError}; use crate::runner::core::{Error, RunnerError};
use super::value::Value; use crate::runner::value::Value;
/// Renders to string a `template` given a map of variables. /// Renders to string a `template` given a map of variables.
pub fn eval_template( pub fn eval_template(

View File

@ -16,11 +16,10 @@
* *
*/ */
// Unique entry point to libxml2 /// Unique entry point to libxml2
use std::ffi::CStr; use std::ffi::CStr;
use super::value::Value; use crate::runner::value::Value;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum XpathError { pub enum XpathError {

View File

@ -15,11 +15,12 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use std::cmp::max;
use crate::runner::{HurlResult, Value};
use colored::*; use colored::*;
use hurl_core::error::Error; 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...). /// 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`]). /// 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)] #[cfg(test)]
pub mod tests { pub mod tests {
use hurl_core::ast::SourceInfo;
use super::*; use super::*;
use crate::runner; use crate::runner;
use hurl_core::ast::SourceInfo;
#[test] #[test]
fn test_add_line_prefix_no_colored() { fn test_add_line_prefix_no_colored() {

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::json; use crate::ast::json;
/// ///
/// Hurl AST /// Hurl AST

View File

@ -15,9 +15,10 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::core::*;
use core::fmt; use core::fmt;
use crate::ast::core::*;
impl fmt::Display for Method { impl fmt::Display for Method {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self { let s = match self {

View File

@ -15,10 +15,11 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::core::Template;
use crate::ast::{Expr, TemplateElement};
use core::fmt; use core::fmt;
use crate::ast::core::Template;
use crate::ast::{Expr, TemplateElement};
/// ///
/// This the AST for the JSON used within Hurl /// This the AST for the JSON used within Hurl
/// ///

View File

@ -17,9 +17,9 @@
*/ */
pub use self::core::*; pub use self::core::*;
pub use self::json::ListElement as JsonListElement; pub use self::json::{
pub use self::json::ObjectElement as JsonObjectElement; ListElement as JsonListElement, ObjectElement as JsonObjectElement, Value as JsonValue,
pub use self::json::Value as JsonValue; };
mod core; mod core;
mod display; mod display;

View File

@ -15,11 +15,12 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::ast::SourceInfo;
use super::parser;
use super::parser::ParseError;
use core::cmp; use core::cmp;
use crate::ast::SourceInfo;
use crate::parser;
use crate::parser::ParseError;
pub trait Error { pub trait Error {
fn source_info(&self) -> SourceInfo; fn source_info(&self) -> SourceInfo;
fn description(&self) -> String; fn description(&self) -> String;

View File

@ -17,23 +17,11 @@
*/ */
use super::reader::Reader; use super::reader::Reader;
// part of hurl /// <https://en.wikipedia.org/wiki/Base64>
// just reuse Parser/Error Position /// Test padding/no-padding
// do not depend on external separator ///
// stop parsing when there is no more base64 character /// Encoded
// /// YW55IGNhcm5hbCBwbGVhcw== any carnal pleas # [97, 110, 121, 32, 99, 97, 114, 110, 97, 108, 32, 112, 108, 101, 97, 115]
// 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]
*/
pub fn parse(reader: &mut Reader) -> Vec<u8> { pub fn parse(reader: &mut Reader) -> Vec<u8> {
let mut bytes = vec![]; let mut bytes = vec![];

View File

@ -16,15 +16,13 @@
* *
*/ */
use crate::ast::*; use crate::ast::*;
use crate::parser::combinators::*;
use crate::parser::json::parse as parse_json;
use crate::parser::multiline::multiline_string; use crate::parser::multiline::multiline_string;
use crate::parser::primitives::*;
use crate::parser::reader::Reader;
use crate::parser::string::backtick_template; use crate::parser::string::backtick_template;
use crate::parser::{xml, ParseResult};
use super::combinators::*;
use super::json::parse as parse_json;
use super::primitives::*;
use super::reader::Reader;
use super::xml;
use super::ParseResult;
pub fn bytes(reader: &mut Reader) -> ParseResult<'static, Bytes> { pub fn bytes(reader: &mut Reader) -> ParseResult<'static, Bytes> {
choice( choice(

View File

@ -15,9 +15,9 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::error::*; use crate::parser::error::*;
use super::reader::Reader; use crate::parser::reader::Reader;
use super::{ParseFunc, ParseResult}; use crate::parser::{ParseFunc, ParseResult};
pub fn optional<'a, T>(f: ParseFunc<'a, T>, reader: &mut Reader) -> ParseResult<'a, Option<T>> { pub fn optional<'a, T>(f: ParseFunc<'a, T>, reader: &mut Reader) -> ParseResult<'a, Option<T>> {
let start = reader.state.clone(); 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> { pub fn nonrecover<'a, T>(f: ParseFunc<'a, T>, reader: &mut Reader) -> ParseResult<'a, T> {
//let start = p.state.clone();
match f(reader) { match f(reader) {
Ok(r) => Ok(r), Ok(r) => Ok(r),
Err(e) => Err(Error { Err(e) => Err(Error {

View File

@ -15,27 +15,13 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use crate::ast::*; use crate::ast::*;
use crate::parser::combinators::*;
use super::combinators::*; use crate::parser::error::*;
use super::error::*; use crate::parser::primitives::*;
use super::primitives::*; use crate::parser::reader::Reader;
use super::reader::Reader; use crate::parser::string::*;
use super::string::*; use crate::parser::ParseResult;
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
*/
pub fn cookiepath(reader: &mut Reader) -> ParseResult<'static, CookiePath> { pub fn cookiepath(reader: &mut Reader) -> ParseResult<'static, CookiePath> {
let start = reader.state.pos.clone(); let start = reader.state.pos.clone();
@ -82,9 +68,8 @@ fn cookiepath_attribute_name(reader: &mut Reader) -> ParseResult<'static, Cookie
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::ast::{Pos, SourceInfo};
use super::*; use super::*;
use crate::ast::{Pos, SourceInfo};
#[test] #[test]
fn test_cookiepath_simple() { fn test_cookiepath_simple() {

View File

@ -16,11 +16,10 @@
* *
*/ */
use crate::ast::*; use crate::ast::*;
use crate::parser::error::*;
use super::error::*; use crate::parser::primitives::*;
use super::primitives::*; use crate::parser::reader::Reader;
use super::reader::Reader; use crate::parser::ParseResult;
use super::ParseResult;
pub fn parse(reader: &mut Reader) -> ParseResult<'static, Expr> { pub fn parse(reader: &mut Reader) -> ParseResult<'static, Expr> {
// let start = p.state.clone(); // let start = p.state.clone();
@ -79,9 +78,8 @@ fn variable_name(reader: &mut Reader) -> ParseResult<'static, Variable> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::ast::Pos;
use super::*; use super::*;
use crate::ast::Pos;
#[test] #[test]
fn test_expr() { fn test_expr() {

View File

@ -15,12 +15,10 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::error::*;
use super::reader::Reader;
use super::ParseResult;
use crate::ast::*; 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> { pub fn parse(reader: &mut Reader) -> ParseResult<'static, Filename> {
// This is an absolute file // This is an absolute file
@ -49,9 +47,8 @@ pub fn parse(reader: &mut Reader) -> ParseResult<'static, Filename> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::ast::Pos;
use super::*; use super::*;
use crate::ast::Pos;
#[test] #[test]
fn test_filename() { fn test_filename() {

View File

@ -165,11 +165,10 @@ fn url_decode_filter(reader: &mut Reader) -> ParseResult<'static, FilterValue> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*;
use crate::ast::Pos; use crate::ast::Pos;
use crate::parser::ParseError; use crate::parser::ParseError;
use super::*;
#[test] #[test]
fn test_count() { fn test_count() {
let mut reader = Reader::init("count"); let mut reader = Reader::init("count");

View File

@ -16,14 +16,11 @@
* *
*/ */
use crate::ast::{JsonListElement, JsonObjectElement, JsonValue, Pos, SourceInfo, Template}; use crate::ast::{JsonListElement, JsonObjectElement, JsonValue, Pos, SourceInfo, Template};
use crate::parser::combinators::*;
use super::combinators::*; use crate::parser::primitives::*;
use super::error; use crate::parser::reader::*;
use super::primitives::*; use crate::parser::template::*;
use super::reader::*; use crate::parser::{error, expr, ParseResult};
use super::template::*;
use super::ParseResult;
use crate::parser::expr;
pub fn parse(reader: &mut Reader) -> ParseResult<'static, JsonValue> { pub fn parse(reader: &mut Reader) -> ParseResult<'static, JsonValue> {
choice( choice(

View File

@ -24,10 +24,10 @@ pub fn parse_hurl_file(s: &str) -> ParseResult<'static, HurlFile> {
} }
pub use self::error::{Error, ParseError}; pub use self::error::{Error, ParseError};
pub use self::json::boolean_value as parse_json_boolean; pub use self::json::{
pub use self::json::null_value as parse_json_null; boolean_value as parse_json_boolean, null_value as parse_json_null,
pub use self::json::number_value as parse_json_number; number_value as parse_json_number, parse as parse_json,
pub use self::json::parse as parse_json; };
pub use self::reader::Reader; pub use self::reader::Reader;
pub use self::template::templatize; pub use self::template::templatize;
use crate::ast::HurlFile; use crate::ast::HurlFile;

View File

@ -15,13 +15,12 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use super::combinators::*;
use super::reader::Reader;
use super::ParseResult;
use crate::ast::*; use crate::ast::*;
use crate::parser::combinators::*;
use crate::parser::json::object_value; use crate::parser::json::object_value;
use crate::parser::primitives::*; 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> { pub fn multiline_string(reader: &mut Reader) -> ParseResult<'static, MultilineString> {
try_literal("```", reader)?; try_literal("```", reader)?;

View File

@ -17,15 +17,14 @@
*/ */
use crate::ast::VersionValue::VersionAny; use crate::ast::VersionValue::VersionAny;
use crate::ast::*; use crate::ast::*;
use crate::parser::bytes::*;
use super::bytes::*; use crate::parser::combinators::*;
use super::combinators::*; use crate::parser::error::*;
use super::error::*; use crate::parser::primitives::*;
use super::primitives::*; use crate::parser::reader::Reader;
use super::reader::Reader; use crate::parser::sections::*;
use super::sections::*; use crate::parser::url::url;
use super::url::url; use crate::parser::ParseResult;
use super::ParseResult;
pub fn hurl_file(reader: &mut Reader) -> ParseResult<'static, HurlFile> { pub fn hurl_file(reader: &mut Reader) -> ParseResult<'static, HurlFile> {
let entries = zero_or_more(entry, reader)?; let entries = zero_or_more(entry, reader)?;

View File

@ -15,15 +15,13 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use crate::ast::*; use crate::ast::*;
use crate::parser::combinators::*;
use super::combinators::*; use crate::parser::error::*;
use super::error::*; use crate::parser::predicate_value::predicate_value;
use super::predicate_value::predicate_value; use crate::parser::primitives::*;
use super::primitives::*; use crate::parser::reader::Reader;
use super::reader::Reader; use crate::parser::ParseResult;
use super::ParseResult;
pub fn predicate(reader: &mut Reader) -> ParseResult<'static, Predicate> { pub fn predicate(reader: &mut Reader) -> ParseResult<'static, Predicate> {
let (not, space0) = predicate_not(reader); let (not, space0) = predicate_not(reader);
@ -361,9 +359,8 @@ fn exist_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncVal
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::ast::Pos;
use super::*; use super::*;
use crate::ast::Pos;
#[test] #[test]
fn test_predicate_not() { fn test_predicate_not() {

View File

@ -15,17 +15,13 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use crate::ast::*; use crate::ast::*;
use crate::parser::combinators::*;
use super::combinators::*;
use super::expr;
use super::primitives::*;
use super::reader::Reader;
use super::string::*;
use super::ParseResult;
use crate::parser::multiline::multiline_string; 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> { pub fn predicate_value(reader: &mut Reader) -> ParseResult<'static, PredicateValue> {
choice( choice(

View File

@ -16,14 +16,11 @@
* *
*/ */
use crate::ast::*; use crate::ast::*;
use crate::parser::combinators::*;
use super::base64; use crate::parser::error::*;
use super::combinators::*; use crate::parser::reader::Reader;
use super::error::*; use crate::parser::string::*;
use super::filename; use crate::parser::{base64, filename, ParseResult};
use super::reader::Reader;
use super::string::*;
use super::ParseResult;
pub fn space(reader: &mut Reader) -> ParseResult<'static, Whitespace> { pub fn space(reader: &mut Reader) -> ParseResult<'static, Whitespace> {
let start = reader.state.clone(); let start = reader.state.clone();
@ -595,9 +592,8 @@ pub fn hex_digit(reader: &mut Reader) -> ParseResult<'static, u32> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::ast::Pos;
use super::*; use super::*;
use crate::ast::Pos;
#[test] #[test]
fn test_space() { fn test_space() {

View File

@ -16,14 +16,12 @@
* *
*/ */
use crate::ast::*; use crate::ast::*;
use crate::parser::{Error, ParseError}; use crate::parser::combinators::*;
use crate::parser::cookiepath::cookiepath;
use super::combinators::*; use crate::parser::primitives::*;
use super::cookiepath::cookiepath; use crate::parser::reader::Reader;
use super::primitives::*; use crate::parser::string::*;
use super::reader::Reader; use crate::parser::{Error, ParseError, ParseResult};
use super::string::*;
use super::ParseResult;
pub fn query(reader: &mut Reader) -> ParseResult<'static, Query> { pub fn query(reader: &mut Reader) -> ParseResult<'static, Query> {
let start = reader.state.pos.clone(); let start = reader.state.pos.clone();

View File

@ -16,17 +16,15 @@
* *
*/ */
use crate::ast::*; use crate::ast::*;
use crate::parser::combinators::*;
use crate::parser::error::*;
use crate::parser::filter::filters; use crate::parser::filter::filters;
use crate::parser::predicate::predicate;
use super::combinators::*; use crate::parser::primitives::*;
use super::error::*; use crate::parser::query::query;
use super::filename; use crate::parser::reader::Reader;
use super::predicate::predicate; use crate::parser::string::*;
use super::primitives::*; use crate::parser::{filename, ParseResult};
use super::query::query;
use super::reader::Reader;
use super::string::*;
use super::ParseResult;
pub fn request_sections(reader: &mut Reader) -> ParseResult<'static, Vec<Section>> { pub fn request_sections(reader: &mut Reader) -> ParseResult<'static, Vec<Section>> {
let sections = zero_or_more(request_section, reader)?; let sections = zero_or_more(request_section, reader)?;

View File

@ -16,18 +16,16 @@
* *
*/ */
use crate::ast::*; 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::*; /// Steps:
use super::error::*; /// 1- parse String until end of stream or end of line or #
use super::primitives::*; /// the string does not contain trailing space
use super::reader::Reader; /// 2- templatize
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
pub fn unquoted_template(reader: &mut Reader) -> ParseResult<'static, Template> { pub fn unquoted_template(reader: &mut Reader) -> ParseResult<'static, Template> {
let start = reader.state.clone(); let start = reader.state.clone();
let mut chars = vec![]; let mut chars = vec![];
@ -328,9 +326,10 @@ fn hex_value(reader: &mut Reader) -> ParseResult<'static, u32> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*;
use std::time::SystemTime; use std::time::SystemTime;
use super::*;
#[test] #[test]
fn test_unquoted_template_empty() { fn test_unquoted_template_empty() {
let mut reader = Reader::init(""); let mut reader = Reader::init("");

View File

@ -15,13 +15,9 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use crate::ast::{Pos, SourceInfo, TemplateElement}; use crate::ast::{Pos, SourceInfo, TemplateElement};
use crate::parser::reader::*;
use super::error; use crate::parser::{error, expr, ParseResult};
use super::expr;
use super::reader::*;
use super::ParseResult;
pub struct EncodedString { pub struct EncodedString {
pub source_info: SourceInfo, pub source_info: SourceInfo,
@ -132,9 +128,8 @@ pub fn templatize(encoded_string: EncodedString) -> ParseResult<'static, Vec<Tem
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::ast::{Expr, Variable, Whitespace};
use super::*; use super::*;
use crate::ast::{Expr, Variable, Whitespace};
#[test] #[test]
fn test_templatize_empty_string() { fn test_templatize_empty_string() {

View File

@ -16,12 +16,10 @@
* *
*/ */
use crate::ast::*; use crate::ast::*;
use crate::parser::error::*;
use super::error::*; use crate::parser::primitives::*;
use super::expr; use crate::parser::reader::Reader;
use super::primitives::*; use crate::parser::{expr, ParseResult};
use super::reader::Reader;
use super::ParseResult;
pub fn url(reader: &mut Reader) -> ParseResult<'static, Template> { pub fn url(reader: &mut Reader) -> ParseResult<'static, Template> {
// Can not be json-encoded, nor empty. // Can not be json-encoded, nor empty.

View File

@ -18,10 +18,9 @@
use sxd_document::parser; use sxd_document::parser;
use crate::ast::Pos; use crate::ast::Pos;
use crate::parser::error::*;
use super::error::*; use crate::parser::reader::Reader;
use super::reader::Reader; use crate::parser::ParseResult;
use super::ParseResult;
pub fn parse(reader: &mut Reader) -> ParseResult<'static, String> { pub fn parse(reader: &mut Reader) -> ParseResult<'static, String> {
let mut buf = String::from(""); let mut buf = String::from("");

View File

@ -15,11 +15,12 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use hurl_core::ast::JsonValue;
use std::fs; use std::fs;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use hurl_core::ast::JsonValue;
#[test] #[test]
fn debug() { fn debug() {
let content = r#""{{name}}""#; let content = r#""{{name}}""#;

View File

@ -15,12 +15,12 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use crate::cli::CliError;
use std::fs; use std::fs;
use std::fs::File; use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;
use crate::cli::CliError;
/// Remove BOM from the input bytes /// Remove BOM from the input bytes
fn strip_bom(bytes: &mut Vec<u8>) { fn strip_bom(bytes: &mut Vec<u8>) {
if bytes.starts_with(&[0xefu8, 0xbb, 0xbf]) { if bytes.starts_with(&[0xefu8, 0xbb, 0xbf]) {

View File

@ -16,7 +16,6 @@
* *
*/ */
use colored::*; use colored::*;
use hurl_core::error::Error; use hurl_core::error::Error;
use hurl_core::parser; use hurl_core::parser;

View File

@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use clap::ArgMatches; use clap::ArgMatches;
pub fn get_string(matches: &ArgMatches, name: &str) -> Option<String> { pub fn get_string(matches: &ArgMatches, name: &str) -> Option<String> {

View File

@ -15,10 +15,8 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use base64::engine::general_purpose; use base64::engine::general_purpose;
use base64::Engine; use base64::Engine;
use hurl_core::ast::*; use hurl_core::ast::*;
use super::serialize_json::*; use super::serialize_json::*;

View File

@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */
pub use self::json::format as format_json; pub use self::json::format as format_json;
pub use self::text::format as format_text; pub use self::text::format as format_text;
pub use self::token::{Token, Tokenizable}; pub use self::token::{Token, Tokenizable};

View File

@ -16,10 +16,9 @@
* *
*/ */
use colored::*; use colored::*;
use hurl_core::ast::*; use hurl_core::ast::*;
use super::token::*; use crate::format::token::*;
pub fn format(hurl_file: HurlFile, color: bool) -> String { pub fn format(hurl_file: HurlFile, color: bool) -> String {
let mut buffer = String::from(""); let mut buffer = String::from("");

View File

@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use hurl_core::ast::*; use hurl_core::ast::*;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]

View File

@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use hurl_core::ast::SourceInfo; use hurl_core::ast::SourceInfo;
use hurl_core::error::Error; use hurl_core::error::Error;

View File

@ -15,9 +15,9 @@
* limitations under the License. * limitations under the License.
* *
*/ */
pub use rules::{check_hurl_file, lint_hurl_file};
pub use self::core::{Error, LinterError}; pub use self::core::{Error, LinterError};
pub use rules::{check_hurl_file, lint_hurl_file};
mod core; mod core;
mod error; mod error;
mod rules; mod rules;

View File

@ -17,7 +17,7 @@
*/ */
use hurl_core::ast::*; use hurl_core::ast::*;
use super::core::{Error, LinterError}; use crate::linter::core::{Error, LinterError};
/// Returns lint errors for the `hurl_file`. /// Returns lint errors for the `hurl_file`.
pub fn check_hurl_file(hurl_file: &HurlFile) -> Vec<Error> { pub fn check_hurl_file(hurl_file: &HurlFile) -> Vec<Error> {

View File

@ -15,17 +15,14 @@
* limitations under the License. * limitations under the License.
* *
*/ */
use std::io::Write; use std::io::{self, Read, Write};
use std::io::{self, Read};
use std::path::Path; use std::path::Path;
use std::process; use std::process;
use atty::Stream; use atty::Stream;
use clap::ArgAction; use clap::ArgAction;
use hurl_core::parser; use hurl_core::parser;
use hurlfmt::format; use hurlfmt::{cli, format, linter};
use hurlfmt::{cli, linter};
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
pub fn init_colored() { pub fn init_colored() {

View File

@ -18,12 +18,11 @@
use std::fs; use std::fs;
use proptest::prelude::prop::test_runner::TestRunner;
use proptest::prelude::*;
use hurl_core::ast::*; use hurl_core::ast::*;
use hurl_core::parser::{parse_json, Reader}; use hurl_core::parser::{parse_json, Reader};
use hurlfmt::format::{Token, Tokenizable}; use hurlfmt::format::{Token, Tokenizable};
use proptest::prelude::prop::test_runner::TestRunner;
use proptest::prelude::*;
fn whitespace() -> BoxedStrategy<String> { fn whitespace() -> BoxedStrategy<String> {
prop_oneof![ prop_oneof![

4
rustfmt.toml Normal file
View File

@ -0,0 +1,4 @@
# Reorganize import. Must be used with nightly.
# See <https://rust-lang.github.io/rustfmt> for option description
#group_imports = "StdExternalCrate"
#imports_granularity = "Module"