mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-23 09:44:22 +03:00
Remove unnecessary empty structs.
This commit is contained in:
parent
3a0795b4bc
commit
4072ea2c8a
@ -38,7 +38,7 @@ pub fn parse_value(s: &str) -> Result<Value, OptionsError> {
|
||||
} else if s == "false" {
|
||||
Ok(Value::Bool(false))
|
||||
} else if s == "null" {
|
||||
Ok(Value::Null {})
|
||||
Ok(Value::Null)
|
||||
} else if let Ok(v) = s.parse::<i64>() {
|
||||
Ok(Value::Integer(v))
|
||||
} else if let Ok(v) = s.parse::<f64>() {
|
||||
@ -85,7 +85,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
parse("a_null=null").unwrap(),
|
||||
("a_null".to_string(), Value::Null {})
|
||||
("a_null".to_string(), Value::Null)
|
||||
);
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ mod tests {
|
||||
parse_value("\"123\"").unwrap(),
|
||||
Value::String("123".to_string())
|
||||
);
|
||||
assert_eq!(parse_value("null").unwrap(), Value::Null {});
|
||||
assert_eq!(parse_value("null").unwrap(), Value::Null);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -95,7 +95,7 @@ impl fmt::Display for Param {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct ParseCookieError {}
|
||||
pub struct ParseCookieError;
|
||||
|
||||
impl FromStr for Cookie {
|
||||
type Err = ParseCookieError;
|
||||
@ -109,32 +109,32 @@ impl FromStr for Cookie {
|
||||
(false, v.to_string())
|
||||
}
|
||||
} else {
|
||||
return Err(ParseCookieError {});
|
||||
return Err(ParseCookieError);
|
||||
};
|
||||
let include_subdomain = if let Some(&v) = tokens.get(1) {
|
||||
v.to_string()
|
||||
} else {
|
||||
return Err(ParseCookieError {});
|
||||
return Err(ParseCookieError);
|
||||
};
|
||||
let path = if let Some(&v) = tokens.get(2) {
|
||||
v.to_string()
|
||||
} else {
|
||||
return Err(ParseCookieError {});
|
||||
return Err(ParseCookieError);
|
||||
};
|
||||
let https = if let Some(&v) = tokens.get(3) {
|
||||
v.to_string()
|
||||
} else {
|
||||
return Err(ParseCookieError {});
|
||||
return Err(ParseCookieError);
|
||||
};
|
||||
let expires = if let Some(&v) = tokens.get(4) {
|
||||
v.to_string()
|
||||
} else {
|
||||
return Err(ParseCookieError {});
|
||||
return Err(ParseCookieError);
|
||||
};
|
||||
let name = if let Some(&v) = tokens.get(5) {
|
||||
v.to_string()
|
||||
} else {
|
||||
return Err(ParseCookieError {});
|
||||
return Err(ParseCookieError);
|
||||
};
|
||||
let value = if let Some(&v) = tokens.get(6) {
|
||||
v.to_string()
|
||||
@ -187,6 +187,6 @@ mod tests {
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(Cookie::from_str("xxx").err().unwrap(), ParseCookieError {});
|
||||
assert_eq!(Cookie::from_str("xxx").err().unwrap(), ParseCookieError);
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ pub struct Predicate {
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum PredicateFunc {
|
||||
KeyExist {},
|
||||
KeyExist,
|
||||
EqualString(String),
|
||||
Equal(Number),
|
||||
GreaterThan(Number),
|
||||
|
@ -182,7 +182,7 @@ mod tests {
|
||||
selectors: vec![
|
||||
Selector::NameChild("store".to_string()),
|
||||
Selector::NameChild("book".to_string()),
|
||||
Selector::ArrayWildcard {},
|
||||
Selector::ArrayWildcard,
|
||||
Selector::NameChild("author".to_string()),
|
||||
],
|
||||
};
|
||||
|
@ -151,7 +151,7 @@ impl Predicate {
|
||||
serde_json::Value::Object(_) => {
|
||||
if let Some(value) = extract_value(elem, self.key.clone()) {
|
||||
match (value, self.func.clone()) {
|
||||
(_, PredicateFunc::KeyExist {}) => true,
|
||||
(_, PredicateFunc::KeyExist) => true,
|
||||
(serde_json::Value::Number(v), PredicateFunc::Equal(ref num)) => {
|
||||
approx_eq!(f64, v.as_f64().unwrap(), num.to_f64(), ulps = 2)
|
||||
} //v.as_f64().unwrap() == num.to_f64(),
|
||||
@ -294,7 +294,7 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_selector_array_wildcard() {
|
||||
assert_eq!(
|
||||
Selector::ArrayWildcard {}.eval(&json_books()).unwrap(),
|
||||
Selector::ArrayWildcard.eval(&json_books()).unwrap(),
|
||||
JsonpathResult::Collection(vec![
|
||||
json_first_book(),
|
||||
json_second_book(),
|
||||
@ -350,7 +350,7 @@ mod tests {
|
||||
pub fn test_predicate() {
|
||||
assert!(Predicate {
|
||||
key: vec!["key".to_string()],
|
||||
func: PredicateFunc::KeyExist {},
|
||||
func: PredicateFunc::KeyExist,
|
||||
}
|
||||
.eval(json!({"key": "value"})));
|
||||
assert!(Predicate {
|
||||
|
@ -106,7 +106,7 @@ fn selector_array_wildcard(reader: &mut Reader) -> Result<Selector, Error> {
|
||||
try_left_bracket(reader)?;
|
||||
try_literal("*", reader)?;
|
||||
literal("]", reader)?;
|
||||
Ok(Selector::ArrayWildcard {})
|
||||
Ok(Selector::ArrayWildcard)
|
||||
}
|
||||
|
||||
fn selector_array_slice(reader: &mut Reader) -> Result<Selector, Error> {
|
||||
@ -191,12 +191,12 @@ fn selector_object_key(reader: &mut Reader) -> Result<Selector, Error> {
|
||||
|
||||
fn selector_wildcard(reader: &mut Reader) -> Result<Selector, Error> {
|
||||
try_literal(".*", reader)?;
|
||||
Ok(Selector::Wildcard {})
|
||||
Ok(Selector::Wildcard)
|
||||
}
|
||||
|
||||
fn selector_recursive_wildcard(reader: &mut Reader) -> Result<Selector, Error> {
|
||||
try_literal("..*", reader)?;
|
||||
Ok(Selector::RecursiveWildcard {})
|
||||
Ok(Selector::RecursiveWildcard)
|
||||
}
|
||||
|
||||
fn selector_recursive_key(reader: &mut Reader) -> Result<Selector, Error> {
|
||||
@ -231,7 +231,7 @@ fn predicate(reader: &mut Reader) -> ParseResult<Predicate> {
|
||||
Ok(f) => f,
|
||||
Err(_) => {
|
||||
reader.state = state;
|
||||
PredicateFunc::KeyExist {}
|
||||
PredicateFunc::KeyExist
|
||||
}
|
||||
};
|
||||
Ok(Predicate { key, func })
|
||||
@ -386,7 +386,7 @@ mod tests {
|
||||
selector(&mut reader).unwrap(),
|
||||
Selector::Filter(Predicate {
|
||||
key: vec!["isbn".to_string()],
|
||||
func: PredicateFunc::KeyExist {},
|
||||
func: PredicateFunc::KeyExist,
|
||||
})
|
||||
);
|
||||
assert_eq!(reader.state.cursor, 11);
|
||||
@ -458,13 +458,13 @@ mod tests {
|
||||
#[test]
|
||||
pub fn test_selector_wildcard() {
|
||||
let mut reader = Reader::new("[*]");
|
||||
assert_eq!(selector(&mut reader).unwrap(), Selector::ArrayWildcard {});
|
||||
assert_eq!(selector(&mut reader).unwrap(), Selector::ArrayWildcard);
|
||||
assert_eq!(reader.state.cursor, 3);
|
||||
|
||||
// you don't need to keep the exact string
|
||||
// this is not part of the AST
|
||||
let mut reader = Reader::new(".[*]");
|
||||
assert_eq!(selector(&mut reader).unwrap(), Selector::ArrayWildcard {});
|
||||
assert_eq!(selector(&mut reader).unwrap(), Selector::ArrayWildcard);
|
||||
assert_eq!(reader.state.cursor, 4);
|
||||
}
|
||||
|
||||
@ -539,7 +539,7 @@ mod tests {
|
||||
predicate(&mut Reader::new("@.isbn")).unwrap(),
|
||||
Predicate {
|
||||
key: vec!["isbn".to_string()],
|
||||
func: PredicateFunc::KeyExist {},
|
||||
func: PredicateFunc::KeyExist,
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -147,7 +147,7 @@ pub fn eval_assert(
|
||||
.1
|
||||
.source_info
|
||||
.clone(),
|
||||
inner: RunnerError::FilterMissingInput {},
|
||||
inner: RunnerError::FilterMissingInput,
|
||||
assert: true,
|
||||
}),
|
||||
Some(value) => {
|
||||
|
@ -38,7 +38,7 @@ pub fn eval_capture(
|
||||
None => {
|
||||
return Err(Error {
|
||||
source_info: capture.query.source_info.clone(),
|
||||
inner: RunnerError::NoQueryResult {},
|
||||
inner: RunnerError::NoQueryResult,
|
||||
assert: false,
|
||||
});
|
||||
}
|
||||
@ -48,7 +48,7 @@ pub fn eval_capture(
|
||||
None => {
|
||||
return Err(Error {
|
||||
source_info: capture.query.source_info.clone(),
|
||||
inner: RunnerError::NoQueryResult {},
|
||||
inner: RunnerError::NoQueryResult,
|
||||
assert: false,
|
||||
})
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ pub enum RunnerError {
|
||||
expected: String,
|
||||
type_mismatch: bool,
|
||||
},
|
||||
InvalidRegex(),
|
||||
InvalidRegex,
|
||||
|
||||
AssertHeaderValueError {
|
||||
actual: String,
|
||||
@ -191,9 +191,9 @@ pub enum RunnerError {
|
||||
},
|
||||
|
||||
// Filter
|
||||
FilterMissingInput {},
|
||||
FilterMissingInput,
|
||||
FilterInvalidInput(String),
|
||||
FilterRegexNoCapture {},
|
||||
FilterRegexNoCapture,
|
||||
FilterInvalidEncoding(String),
|
||||
FilterDecode(String),
|
||||
}
|
||||
|
@ -43,31 +43,31 @@ impl Error for runner::Error {
|
||||
RunnerError::CouldNotParseResponse => "HTTP connection".to_string(),
|
||||
RunnerError::SslCertificate { .. } => "SSL certificate".to_string(),
|
||||
RunnerError::PredicateValue { .. } => "Assert - predicate value failed".to_string(),
|
||||
RunnerError::InvalidRegex {} => "Invalid regex".to_string(),
|
||||
RunnerError::InvalidRegex => "Invalid regex".to_string(),
|
||||
RunnerError::FileReadAccess { .. } => "File read access".to_string(),
|
||||
RunnerError::QueryInvalidXml { .. } => "Invalid XML".to_string(),
|
||||
RunnerError::QueryInvalidXpathEval {} => "Invalid XPath expression".to_string(),
|
||||
RunnerError::QueryHeaderNotFound {} => "Header not found".to_string(),
|
||||
RunnerError::QueryCookieNotFound {} => "Cookie not found".to_string(),
|
||||
RunnerError::QueryInvalidXml => "Invalid XML".to_string(),
|
||||
RunnerError::QueryInvalidXpathEval => "Invalid XPath expression".to_string(),
|
||||
RunnerError::QueryHeaderNotFound => "Header not found".to_string(),
|
||||
RunnerError::QueryCookieNotFound => "Cookie not found".to_string(),
|
||||
RunnerError::AssertHeaderValueError { .. } => "Assert header value".to_string(),
|
||||
RunnerError::AssertBodyValueError { .. } => "Assert body value".to_string(),
|
||||
RunnerError::AssertVersion { .. } => "Assert HTTP version".to_string(),
|
||||
RunnerError::AssertStatus { .. } => "Assert status code".to_string(),
|
||||
RunnerError::QueryInvalidJson { .. } => "Invalid JSON".to_string(),
|
||||
RunnerError::QueryInvalidJson => "Invalid JSON".to_string(),
|
||||
RunnerError::QueryInvalidJsonpathExpression { .. } => "Invalid JSONPath".to_string(),
|
||||
RunnerError::PredicateType { .. } => "Assert - inconsistent predicate type".to_string(),
|
||||
RunnerError::PredicateType => "Assert - inconsistent predicate type".to_string(),
|
||||
RunnerError::InvalidDecoding { .. } => "Invalid decoding".to_string(),
|
||||
RunnerError::InvalidCharset { .. } => "Invalid charset".to_string(),
|
||||
RunnerError::AssertFailure { .. } => "Assert failure".to_string(),
|
||||
RunnerError::UnrenderableVariable { .. } => "Unrenderable variable".to_string(),
|
||||
RunnerError::NoQueryResult { .. } => "No query result".to_string(),
|
||||
RunnerError::NoQueryResult => "No query result".to_string(),
|
||||
RunnerError::UnsupportedContentEncoding(..) => "Decompression error".to_string(),
|
||||
RunnerError::CouldNotUncompressResponse(..) => "Decompression error".to_string(),
|
||||
RunnerError::InvalidJson { .. } => "Invalid JSON".to_string(),
|
||||
RunnerError::UnauthorizedFileAccess { .. } => "Unauthorized file access".to_string(),
|
||||
RunnerError::FilterMissingInput { .. } => "Filter Error".to_string(),
|
||||
RunnerError::FilterMissingInput => "Filter Error".to_string(),
|
||||
RunnerError::FilterInvalidInput { .. } => "Filter Error".to_string(),
|
||||
RunnerError::FilterRegexNoCapture { .. } => "Filter Error".to_string(),
|
||||
RunnerError::FilterRegexNoCapture => "Filter Error".to_string(),
|
||||
RunnerError::FilterInvalidEncoding { .. } => "Filter Error".to_string(),
|
||||
RunnerError::FilterDecode { .. } => "Filter Error".to_string(),
|
||||
}
|
||||
@ -95,33 +95,27 @@ impl Error for runner::Error {
|
||||
RunnerError::PredicateValue(value) => {
|
||||
format!("actual value is <{value}>")
|
||||
}
|
||||
RunnerError::InvalidRegex {} => "regex expression is not valid".to_string(),
|
||||
RunnerError::InvalidRegex => "regex expression is not valid".to_string(),
|
||||
RunnerError::FileReadAccess { value } => format!("file {value} can not be read"),
|
||||
RunnerError::QueryInvalidXml { .. } => {
|
||||
"the HTTP response is not a valid XML".to_string()
|
||||
}
|
||||
RunnerError::QueryHeaderNotFound {} => {
|
||||
RunnerError::QueryInvalidXml => "the HTTP response is not a valid XML".to_string(),
|
||||
RunnerError::QueryHeaderNotFound => {
|
||||
"this header has not been found in the response".to_string()
|
||||
}
|
||||
RunnerError::QueryCookieNotFound {} => {
|
||||
RunnerError::QueryCookieNotFound => {
|
||||
"this cookie has not been found in the response".to_string()
|
||||
}
|
||||
RunnerError::QueryInvalidXpathEval {} => {
|
||||
"the XPath expression is not valid".to_string()
|
||||
}
|
||||
RunnerError::QueryInvalidXpathEval => "the XPath expression is not valid".to_string(),
|
||||
RunnerError::AssertHeaderValueError { actual } => {
|
||||
format!("actual value is <{actual}>")
|
||||
}
|
||||
RunnerError::AssertBodyValueError { actual, .. } => {
|
||||
format!("actual value is <{actual}>")
|
||||
}
|
||||
RunnerError::QueryInvalidJson { .. } => {
|
||||
"the HTTP response is not a valid JSON".to_string()
|
||||
}
|
||||
RunnerError::QueryInvalidJson => "the HTTP response is not a valid JSON".to_string(),
|
||||
RunnerError::QueryInvalidJsonpathExpression { value } => {
|
||||
format!("the JSONPath expression '{value}' is not valid")
|
||||
}
|
||||
RunnerError::PredicateType { .. } => {
|
||||
RunnerError::PredicateType => {
|
||||
"predicate type inconsistent with value return by query".to_string()
|
||||
}
|
||||
RunnerError::InvalidDecoding { charset } => {
|
||||
@ -149,7 +143,7 @@ impl Error for runner::Error {
|
||||
RunnerError::UnrenderableVariable { name, value } => {
|
||||
format!("variable <{name}> with value {value} can not be rendered")
|
||||
}
|
||||
RunnerError::NoQueryResult { .. } => "The query didn't return any result".to_string(),
|
||||
RunnerError::NoQueryResult => "The query didn't return any result".to_string(),
|
||||
RunnerError::UnsupportedContentEncoding(algorithm) => {
|
||||
format!("compression {algorithm} is not supported")
|
||||
}
|
||||
@ -165,11 +159,11 @@ impl Error for runner::Error {
|
||||
path.to_str().unwrap()
|
||||
)
|
||||
}
|
||||
RunnerError::FilterMissingInput { .. } => "missing value to apply filter".to_string(),
|
||||
RunnerError::FilterMissingInput => "missing value to apply filter".to_string(),
|
||||
RunnerError::FilterInvalidInput(message) => {
|
||||
format!("invalid filter input: {message}")
|
||||
}
|
||||
RunnerError::FilterRegexNoCapture { .. } => "capture not found".to_string(),
|
||||
RunnerError::FilterRegexNoCapture => "capture not found".to_string(),
|
||||
RunnerError::FilterInvalidEncoding(encoding) => {
|
||||
format!("<{encoding}> encoding is not supported")
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ pub fn eval_filters(
|
||||
} else {
|
||||
return Err(Error {
|
||||
source_info: filter.source_info.clone(),
|
||||
inner: RunnerError::FilterMissingInput {},
|
||||
inner: RunnerError::FilterMissingInput,
|
||||
assert: in_assert,
|
||||
});
|
||||
}
|
||||
@ -487,22 +487,22 @@ pub fn eval_xpath_string(
|
||||
};
|
||||
match result {
|
||||
Ok(value) => Ok(Some(value)),
|
||||
Err(xpath::XpathError::InvalidXml {}) => Err(Error {
|
||||
Err(xpath::XpathError::InvalidXml) => Err(Error {
|
||||
source_info: source_info.clone(),
|
||||
inner: RunnerError::QueryInvalidXml,
|
||||
assert: false,
|
||||
}),
|
||||
Err(xpath::XpathError::InvalidHtml {}) => Err(Error {
|
||||
Err(xpath::XpathError::InvalidHtml) => Err(Error {
|
||||
source_info: source_info.clone(),
|
||||
inner: RunnerError::QueryInvalidXml,
|
||||
assert: false,
|
||||
}),
|
||||
Err(xpath::XpathError::Eval {}) => Err(Error {
|
||||
Err(xpath::XpathError::Eval) => Err(Error {
|
||||
source_info: expr_template.source_info.clone(),
|
||||
inner: RunnerError::QueryInvalidXpathEval,
|
||||
assert: false,
|
||||
}),
|
||||
Err(xpath::XpathError::Unsupported {}) => {
|
||||
Err(xpath::XpathError::Unsupported) => {
|
||||
panic!("Unsupported xpath {expr}"); // good usecase for panic - I could not reproqduce this usecase myself
|
||||
}
|
||||
}
|
||||
@ -737,7 +737,7 @@ pub mod tests {
|
||||
.err()
|
||||
.unwrap();
|
||||
assert_eq!(error.source_info, SourceInfo::new(1, 7, 1, 20));
|
||||
assert_eq!(error.inner, RunnerError::InvalidRegex {});
|
||||
assert_eq!(error.inner, RunnerError::InvalidRegex);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -33,7 +33,7 @@ pub fn eval_json_value(
|
||||
keep_whitespace: bool,
|
||||
) -> Result<String, Error> {
|
||||
match json_value {
|
||||
JsonValue::Null {} => Ok("null".to_string()),
|
||||
JsonValue::Null => Ok("null".to_string()),
|
||||
JsonValue::Number(s) => Ok(s.clone()),
|
||||
JsonValue::String(template) => {
|
||||
let s = eval_json_template(template, variables)?;
|
||||
@ -249,7 +249,7 @@ mod tests {
|
||||
let mut variables = HashMap::new();
|
||||
variables.insert("name".to_string(), Value::String("Bob".to_string()));
|
||||
assert_eq!(
|
||||
eval_json_value(&JsonValue::Null {}, &variables, true).unwrap(),
|
||||
eval_json_value(&JsonValue::Null, &variables, true).unwrap(),
|
||||
"null".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
|
@ -134,7 +134,7 @@ fn eval_variable_value(
|
||||
variables: &mut HashMap<String, Value>,
|
||||
) -> Result<Value, Error> {
|
||||
match variable_value {
|
||||
VariableValue::Null {} => Ok(Value::Null),
|
||||
VariableValue::Null => Ok(Value::Null),
|
||||
VariableValue::Bool(v) => Ok(Value::Bool(*v)),
|
||||
VariableValue::Integer(v) => Ok(Value::Integer(*v)),
|
||||
VariableValue::Float(Float { value, .. }) => Ok(Value::Float(*value)),
|
||||
|
@ -212,14 +212,14 @@ fn expected_no_value(
|
||||
let expected = eval_predicate_value_template(expected, variables)?;
|
||||
Ok(format!("matches regex <{expected}>"))
|
||||
}
|
||||
PredicateFuncValue::IsInteger {} => Ok("integer".to_string()),
|
||||
PredicateFuncValue::IsFloat {} => Ok("float".to_string()),
|
||||
PredicateFuncValue::IsBoolean {} => Ok("boolean".to_string()),
|
||||
PredicateFuncValue::IsString {} => Ok("string".to_string()),
|
||||
PredicateFuncValue::IsCollection {} => Ok("collection".to_string()),
|
||||
PredicateFuncValue::IsDate {} => Ok("date".to_string()),
|
||||
PredicateFuncValue::Exist {} => Ok("something".to_string()),
|
||||
PredicateFuncValue::IsEmpty {} => Ok("empty".to_string()),
|
||||
PredicateFuncValue::IsInteger => Ok("integer".to_string()),
|
||||
PredicateFuncValue::IsFloat => Ok("float".to_string()),
|
||||
PredicateFuncValue::IsBoolean => Ok("boolean".to_string()),
|
||||
PredicateFuncValue::IsString => Ok("string".to_string()),
|
||||
PredicateFuncValue::IsCollection => Ok("collection".to_string()),
|
||||
PredicateFuncValue::IsDate => Ok("date".to_string()),
|
||||
PredicateFuncValue::Exist => Ok("something".to_string()),
|
||||
PredicateFuncValue::IsEmpty => Ok("empty".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,14 +278,14 @@ fn eval_predicate_func(
|
||||
PredicateFuncValue::Match {
|
||||
value: expected, ..
|
||||
} => eval_match(expected, &predicate_func.source_info, variables, value),
|
||||
PredicateFuncValue::IsInteger {} => eval_is_integer(value),
|
||||
PredicateFuncValue::IsFloat {} => eval_is_float(value),
|
||||
PredicateFuncValue::IsBoolean {} => eval_is_boolean(value),
|
||||
PredicateFuncValue::IsString {} => eval_is_string(value),
|
||||
PredicateFuncValue::IsCollection {} => eval_is_collection(value),
|
||||
PredicateFuncValue::IsDate {} => eval_is_date(value),
|
||||
PredicateFuncValue::Exist {} => eval_exist(value),
|
||||
PredicateFuncValue::IsEmpty {} => eval_is_empty(value),
|
||||
PredicateFuncValue::IsInteger => eval_is_integer(value),
|
||||
PredicateFuncValue::IsFloat => eval_is_float(value),
|
||||
PredicateFuncValue::IsBoolean => eval_is_boolean(value),
|
||||
PredicateFuncValue::IsString => eval_is_string(value),
|
||||
PredicateFuncValue::IsCollection => eval_is_collection(value),
|
||||
PredicateFuncValue::IsDate => eval_is_date(value),
|
||||
PredicateFuncValue::Exist => eval_exist(value),
|
||||
PredicateFuncValue::IsEmpty => eval_is_empty(value),
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,7 +471,7 @@ fn eval_match(
|
||||
Err(_) => {
|
||||
return Err(Error {
|
||||
source_info: source_info.clone(),
|
||||
inner: RunnerError::InvalidRegex(),
|
||||
inner: RunnerError::InvalidRegex,
|
||||
assert: false,
|
||||
});
|
||||
}
|
||||
@ -628,7 +628,7 @@ fn assert_values_equal(actual: &Value, expected: &Value) -> AssertResult {
|
||||
let actual_display = actual.display();
|
||||
let expected_display = expected.display();
|
||||
match (actual, expected) {
|
||||
(Value::Null {}, Value::Null {}) => AssertResult {
|
||||
(Value::Null, Value::Null) => AssertResult {
|
||||
success: true,
|
||||
actual: actual_display,
|
||||
expected: expected_display,
|
||||
@ -703,7 +703,7 @@ fn assert_values_not_equal(actual: &Value, expected: &Value) -> AssertResult {
|
||||
let actual_display = actual.display();
|
||||
let expected_display = expected.display();
|
||||
match (actual, expected) {
|
||||
(Value::Null {}, Value::Null {}) => AssertResult {
|
||||
(Value::Null, Value::Null) => AssertResult {
|
||||
success: false,
|
||||
actual: actual_display,
|
||||
expected: expected_display,
|
||||
@ -1092,7 +1092,7 @@ mod tests {
|
||||
// predicate: `exist`
|
||||
// value: Some(Unit) | None
|
||||
let pred_func = PredicateFunc {
|
||||
value: PredicateFuncValue::Exist {},
|
||||
value: PredicateFuncValue::Exist,
|
||||
source_info: SourceInfo::new(0, 0, 0, 0),
|
||||
};
|
||||
|
||||
@ -1507,7 +1507,7 @@ mod tests {
|
||||
value: PredicateFuncValue::Equal {
|
||||
space0: whitespace(),
|
||||
operator: false,
|
||||
value: PredicateValue::Null {},
|
||||
value: PredicateValue::Null,
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -1585,7 +1585,7 @@ mod tests {
|
||||
source_info: SourceInfo::new(0, 0, 0, 0),
|
||||
value: PredicateFuncValue::Equal {
|
||||
space0: whitespace(),
|
||||
value: PredicateValue::Null {},
|
||||
value: PredicateValue::Null,
|
||||
operator: false,
|
||||
},
|
||||
},
|
||||
@ -1610,7 +1610,7 @@ mod tests {
|
||||
value: PredicateFuncValue::Equal {
|
||||
space0: whitespace(),
|
||||
operator: false,
|
||||
value: PredicateValue::Null {},
|
||||
value: PredicateValue::Null,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -41,7 +41,7 @@ pub fn eval_predicate_value(
|
||||
PredicateValue::Integer(value) => Ok(Value::Integer(*value)),
|
||||
PredicateValue::Float(value) => Ok(Value::Float(value.value)),
|
||||
PredicateValue::Bool(value) => Ok(Value::Bool(*value)),
|
||||
PredicateValue::Null {} => Ok(Value::Null {}),
|
||||
PredicateValue::Null => Ok(Value::Null),
|
||||
PredicateValue::Hex(value) => Ok(Value::Bytes(value.value.clone())),
|
||||
PredicateValue::Base64(value) => Ok(Value::Bytes(value.value.clone())),
|
||||
PredicateValue::Expression(expr) => {
|
||||
|
@ -37,14 +37,14 @@ pub fn eval_query(
|
||||
http_response: &http::Response,
|
||||
) -> QueryResult {
|
||||
match query.value.clone() {
|
||||
QueryValue::Status {} => eval_query_status(http_response),
|
||||
QueryValue::Url {} => eval_query_url(http_response),
|
||||
QueryValue::Status => eval_query_status(http_response),
|
||||
QueryValue::Url => eval_query_url(http_response),
|
||||
QueryValue::Header { name, .. } => eval_query_header(http_response, &name, variables),
|
||||
QueryValue::Cookie {
|
||||
expr: CookiePath { name, attribute },
|
||||
..
|
||||
} => eval_query_cookie(http_response, &name, &attribute, variables),
|
||||
QueryValue::Body {} => eval_query_body(http_response, &query.source_info),
|
||||
QueryValue::Body => eval_query_body(http_response, &query.source_info),
|
||||
QueryValue::Xpath { expr, .. } => {
|
||||
eval_query_xpath(http_response, &expr, variables, &query.source_info)
|
||||
}
|
||||
@ -55,10 +55,10 @@ pub fn eval_query(
|
||||
eval_query_regex(http_response, &value, variables, &query.source_info)
|
||||
}
|
||||
QueryValue::Variable { name, .. } => eval_query_variable(&name, variables),
|
||||
QueryValue::Duration {} => eval_query_duration(http_response),
|
||||
QueryValue::Bytes {} => eval_query_bytes(http_response, &query.source_info),
|
||||
QueryValue::Sha256 {} => eval_query_sha256(http_response, &query.source_info),
|
||||
QueryValue::Md5 {} => eval_query_md5(http_response, &query.source_info),
|
||||
QueryValue::Duration => eval_query_duration(http_response),
|
||||
QueryValue::Bytes => eval_query_bytes(http_response, &query.source_info),
|
||||
QueryValue::Sha256 => eval_query_sha256(http_response, &query.source_info),
|
||||
QueryValue::Md5 => eval_query_md5(http_response, &query.source_info),
|
||||
QueryValue::Certificate {
|
||||
attribute_name: field,
|
||||
..
|
||||
@ -219,7 +219,7 @@ fn eval_query_regex(
|
||||
let source_info = t.source_info.clone();
|
||||
return Err(Error {
|
||||
source_info,
|
||||
inner: RunnerError::InvalidRegex(),
|
||||
inner: RunnerError::InvalidRegex,
|
||||
assert: false,
|
||||
});
|
||||
}
|
||||
@ -559,7 +559,7 @@ pub mod tests {
|
||||
eval_query(
|
||||
&Query {
|
||||
source_info: SourceInfo::new(0, 0, 0, 0),
|
||||
value: QueryValue::Status {},
|
||||
value: QueryValue::Status,
|
||||
},
|
||||
&variables,
|
||||
&http::hello_http_response(),
|
||||
@ -834,7 +834,7 @@ pub mod tests {
|
||||
eval_query(
|
||||
&Query {
|
||||
source_info: SourceInfo::new(0, 0, 0, 0),
|
||||
value: QueryValue::Body {},
|
||||
value: QueryValue::Body,
|
||||
},
|
||||
&variables,
|
||||
&http::hello_http_response(),
|
||||
@ -846,7 +846,7 @@ pub mod tests {
|
||||
let error = eval_query(
|
||||
&Query {
|
||||
source_info: SourceInfo::new(1, 1, 1, 2),
|
||||
value: QueryValue::Body {},
|
||||
value: QueryValue::Body,
|
||||
},
|
||||
&variables,
|
||||
&http::bytes_http_response(),
|
||||
@ -1082,7 +1082,7 @@ pub mod tests {
|
||||
.err()
|
||||
.unwrap();
|
||||
assert_eq!(error.source_info, SourceInfo::new(1, 7, 1, 10));
|
||||
assert_eq!(error.inner, RunnerError::InvalidRegex());
|
||||
assert_eq!(error.inner, RunnerError::InvalidRegex);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1092,7 +1092,7 @@ pub mod tests {
|
||||
eval_query(
|
||||
&Query {
|
||||
source_info: SourceInfo::new(0, 0, 0, 0),
|
||||
value: QueryValue::Bytes {},
|
||||
value: QueryValue::Bytes,
|
||||
},
|
||||
&variables,
|
||||
&http::hello_http_response(),
|
||||
|
@ -34,7 +34,7 @@ pub fn eval_regex_value(
|
||||
Ok(re) => Ok(re),
|
||||
Err(_) => Err(Error {
|
||||
source_info: t.source_info.clone(),
|
||||
inner: RunnerError::InvalidRegex(),
|
||||
inner: RunnerError::InvalidRegex,
|
||||
assert: false,
|
||||
}),
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ pub fn eval_asserts(
|
||||
asserts.push(AssertResult::Header {
|
||||
actual: Err(Error {
|
||||
source_info: header.key.source_info.clone(),
|
||||
inner: RunnerError::QueryHeaderNotFound {},
|
||||
inner: RunnerError::QueryHeaderNotFound,
|
||||
assert: false,
|
||||
}),
|
||||
expected,
|
||||
|
@ -40,12 +40,12 @@ pub fn eval_xml(xml: &str, expr: &str) -> Result<Value, XpathError> {
|
||||
match parse_html_string_patched(xml, &parser) {
|
||||
Ok(doc) => {
|
||||
if doc.get_root_element().is_none() {
|
||||
Err(XpathError::InvalidXml {})
|
||||
Err(XpathError::InvalidXml)
|
||||
} else {
|
||||
eval(&doc, expr, true)
|
||||
}
|
||||
}
|
||||
Err(_) => Err(XpathError::InvalidXml {}),
|
||||
Err(_) => Err(XpathError::InvalidXml),
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,12 +57,12 @@ pub fn eval_html(html: &str, expr: &str) -> Result<Value, XpathError> {
|
||||
// You can have a doc structure even if the input xml is not valid
|
||||
// check that the root element exists
|
||||
if doc.get_root_element().is_none() {
|
||||
Err(XpathError::InvalidHtml {})
|
||||
Err(XpathError::InvalidHtml)
|
||||
} else {
|
||||
eval(&doc, expr, false)
|
||||
}
|
||||
}
|
||||
Err(_) => Err(XpathError::InvalidHtml {}),
|
||||
Err(_) => Err(XpathError::InvalidHtml),
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ fn eval(doc: &Document, expr: &str, support_ns: bool) -> Result<Value, XpathErro
|
||||
|
||||
let result = match context.evaluate(expr) {
|
||||
Ok(object) => object,
|
||||
Err(_) => return Err(XpathError::Eval {}),
|
||||
Err(_) => return Err(XpathError::Eval),
|
||||
};
|
||||
|
||||
match unsafe { *result.ptr }.type_ {
|
||||
@ -180,7 +180,7 @@ fn eval(doc: &Document, expr: &str, support_ns: bool) -> Result<Value, XpathErro
|
||||
libxml::bindings::xmlXPathObjectType_XPATH_NODESET => {
|
||||
Ok(Value::Nodeset(result.get_number_of_nodes()))
|
||||
}
|
||||
_ => Err(XpathError::Unsupported {}),
|
||||
_ => Err(XpathError::Unsupported),
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,8 +267,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_error_eval() {
|
||||
assert_eq!(eval_xml("<a/>", "^^^").err().unwrap(), XpathError::Eval {});
|
||||
assert_eq!(eval_xml("<a/>", "//").err().unwrap(), XpathError::Eval {});
|
||||
assert_eq!(eval_xml("<a/>", "^^^").err().unwrap(), XpathError::Eval);
|
||||
assert_eq!(eval_xml("<a/>", "//").err().unwrap(), XpathError::Eval);
|
||||
// assert_eq!(1,2);
|
||||
}
|
||||
|
||||
|
@ -726,7 +726,7 @@ xpath "strong(//head/title)" equals "Hello"
|
||||
let filename = "test.hurl";
|
||||
let error = runner::Error {
|
||||
source_info: SourceInfo::new(4, 7, 4, 29),
|
||||
inner: runner::RunnerError::QueryInvalidXpathEval {},
|
||||
inner: runner::RunnerError::QueryInvalidXpathEval,
|
||||
assert: true,
|
||||
};
|
||||
assert_eq!(
|
||||
|
@ -297,8 +297,8 @@ pub struct Query {
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum QueryValue {
|
||||
Status {},
|
||||
Url {},
|
||||
Status,
|
||||
Url,
|
||||
Header {
|
||||
space0: Whitespace,
|
||||
name: Template,
|
||||
@ -307,7 +307,7 @@ pub enum QueryValue {
|
||||
space0: Whitespace,
|
||||
expr: CookiePath,
|
||||
},
|
||||
Body {},
|
||||
Body,
|
||||
Xpath {
|
||||
space0: Whitespace,
|
||||
expr: Template,
|
||||
@ -324,10 +324,10 @@ pub enum QueryValue {
|
||||
space0: Whitespace,
|
||||
name: Template,
|
||||
},
|
||||
Duration {},
|
||||
Bytes {},
|
||||
Sha256 {},
|
||||
Md5 {},
|
||||
Duration,
|
||||
Bytes,
|
||||
Sha256,
|
||||
Md5,
|
||||
Certificate {
|
||||
space0: Whitespace,
|
||||
attribute_name: CertificateAttributeName,
|
||||
@ -416,7 +416,7 @@ pub enum PredicateValue {
|
||||
Integer(i64),
|
||||
Float(Float),
|
||||
Bool(bool),
|
||||
Null {},
|
||||
Null,
|
||||
Hex(Hex),
|
||||
Base64(Base64),
|
||||
Expression(Expr),
|
||||
@ -476,15 +476,14 @@ pub enum PredicateFuncValue {
|
||||
space0: Whitespace,
|
||||
value: PredicateValue,
|
||||
},
|
||||
// FIXME: why use an empty struct here ?
|
||||
IsInteger {},
|
||||
IsFloat {},
|
||||
IsBoolean {},
|
||||
IsString {},
|
||||
IsCollection {},
|
||||
IsDate {},
|
||||
Exist {},
|
||||
IsEmpty {},
|
||||
IsInteger,
|
||||
IsFloat,
|
||||
IsBoolean,
|
||||
IsString,
|
||||
IsCollection,
|
||||
IsDate,
|
||||
Exist,
|
||||
IsEmpty,
|
||||
}
|
||||
|
||||
//
|
||||
@ -790,7 +789,7 @@ pub struct VariableDefinition {
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum VariableValue {
|
||||
Null {},
|
||||
Null,
|
||||
Bool(bool),
|
||||
Integer(i64),
|
||||
Float(Float),
|
||||
|
@ -167,7 +167,7 @@ impl fmt::Display for VariableDefinition {
|
||||
impl fmt::Display for VariableValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let s = match self {
|
||||
VariableValue::Null { .. } => "null".to_string(),
|
||||
VariableValue::Null => "null".to_string(),
|
||||
VariableValue::Bool(value) => value.to_string(),
|
||||
VariableValue::Integer(n) => n.to_string(),
|
||||
VariableValue::Float(x) => x.to_string(),
|
||||
@ -227,14 +227,14 @@ impl PredicateFuncValue {
|
||||
PredicateFuncValue::Contain { .. } => "contains".to_string(),
|
||||
PredicateFuncValue::Include { .. } => "includes".to_string(),
|
||||
PredicateFuncValue::Match { .. } => "matches".to_string(),
|
||||
PredicateFuncValue::IsInteger { .. } => "isInteger".to_string(),
|
||||
PredicateFuncValue::IsFloat { .. } => "isFloat".to_string(),
|
||||
PredicateFuncValue::IsBoolean { .. } => "isBoolean".to_string(),
|
||||
PredicateFuncValue::IsString { .. } => "isString".to_string(),
|
||||
PredicateFuncValue::IsCollection { .. } => "isCollection".to_string(),
|
||||
PredicateFuncValue::IsDate { .. } => "isDate".to_string(),
|
||||
PredicateFuncValue::Exist { .. } => "exists".to_string(),
|
||||
PredicateFuncValue::IsEmpty { .. } => "isEmpty".to_string(),
|
||||
PredicateFuncValue::IsInteger => "isInteger".to_string(),
|
||||
PredicateFuncValue::IsFloat => "isFloat".to_string(),
|
||||
PredicateFuncValue::IsBoolean => "isBoolean".to_string(),
|
||||
PredicateFuncValue::IsString => "isString".to_string(),
|
||||
PredicateFuncValue::IsCollection => "isCollection".to_string(),
|
||||
PredicateFuncValue::IsDate => "isDate".to_string(),
|
||||
PredicateFuncValue::Exist => "exists".to_string(),
|
||||
PredicateFuncValue::IsEmpty => "isEmpty".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,14 +40,14 @@ pub enum Value {
|
||||
space0: String,
|
||||
elements: Vec<ObjectElement>,
|
||||
},
|
||||
Null {},
|
||||
Null,
|
||||
}
|
||||
|
||||
impl Value {
|
||||
pub fn _type(&self) -> String {
|
||||
match self {
|
||||
Value::Number(_) => "number".to_string(),
|
||||
Value::Null {} => "null".to_string(),
|
||||
Value::Null => "null".to_string(),
|
||||
Value::Boolean(_) => "boolean".to_string(),
|
||||
Value::List { .. } => "list".to_string(),
|
||||
Value::Object { .. } => "object".to_string(),
|
||||
@ -101,7 +101,7 @@ impl fmt::Display for Value {
|
||||
.collect::<Vec<String>>();
|
||||
format!("{{{}{}}}", space0, elements.join(","))
|
||||
}
|
||||
Value::Null { .. } => "null".to_string(),
|
||||
Value::Null => "null".to_string(),
|
||||
};
|
||||
write!(f, "{s}")
|
||||
}
|
||||
@ -160,7 +160,7 @@ impl Value {
|
||||
.collect::<Vec<String>>();
|
||||
format!("{{{}{}}}", space0, elements.join(","))
|
||||
}
|
||||
Value::Null { .. } => "null".to_string(),
|
||||
Value::Null => "null".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -314,7 +314,7 @@ mod tests {
|
||||
}
|
||||
.to_string()
|
||||
);
|
||||
assert_eq!("null".to_string(), Value::Null {}.to_string());
|
||||
assert_eq!("null".to_string(), Value::Null.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -38,26 +38,26 @@ impl Error for parser::Error {
|
||||
fn description(&self) -> String {
|
||||
match self.clone().inner {
|
||||
ParseError::Method { .. } => "Parsing method".to_string(),
|
||||
ParseError::Version { .. } => "Parsing version".to_string(),
|
||||
ParseError::Status { .. } => "Parsing status code".to_string(),
|
||||
ParseError::Filename { .. } => "Parsing filename".to_string(),
|
||||
ParseError::Version => "Parsing version".to_string(),
|
||||
ParseError::Status => "Parsing status code".to_string(),
|
||||
ParseError::Filename => "Parsing filename".to_string(),
|
||||
ParseError::Expecting { .. } => "Parsing literal".to_string(),
|
||||
ParseError::Space { .. } => "Parsing space".to_string(),
|
||||
ParseError::Space => "Parsing space".to_string(),
|
||||
ParseError::RequestSectionName { .. } => "Parsing request section name".to_string(),
|
||||
ParseError::ResponseSectionName { .. } => "Parsing response section name".to_string(),
|
||||
ParseError::JsonpathExpr { .. } => "Parsing JSONPath expression".to_string(),
|
||||
ParseError::XPathExpr { .. } => "Parsing XPath expression".to_string(),
|
||||
ParseError::TemplateVariable { .. } => "Parsing template variable".to_string(),
|
||||
ParseError::Json { .. } => "Parsing JSON".to_string(),
|
||||
ParseError::Predicate { .. } => "Parsing predicate".to_string(),
|
||||
ParseError::PredicateValue { .. } => "Parsing predicate value".to_string(),
|
||||
ParseError::JsonPathExpr => "Parsing JSONPath expression".to_string(),
|
||||
ParseError::XPathExpr => "Parsing XPath expression".to_string(),
|
||||
ParseError::TemplateVariable => "Parsing template variable".to_string(),
|
||||
ParseError::Json => "Parsing JSON".to_string(),
|
||||
ParseError::Predicate => "Parsing predicate".to_string(),
|
||||
ParseError::PredicateValue => "Parsing predicate value".to_string(),
|
||||
ParseError::RegexExpr { .. } => "Parsing regex".to_string(),
|
||||
ParseError::DuplicateSection { .. } => "Parsing section".to_string(),
|
||||
ParseError::RequestSection { .. } => "Parsing section".to_string(),
|
||||
ParseError::ResponseSection { .. } => "Parsing section".to_string(),
|
||||
ParseError::EscapeChar { .. } => "Parsing escape character".to_string(),
|
||||
ParseError::InvalidCookieAttribute { .. } => "Parsing cookie attribute".to_string(),
|
||||
ParseError::OddNumberOfHexDigits { .. } => "Parsing hex bytearray".to_string(),
|
||||
ParseError::DuplicateSection => "Parsing section".to_string(),
|
||||
ParseError::RequestSection => "Parsing section".to_string(),
|
||||
ParseError::ResponseSection => "Parsing section".to_string(),
|
||||
ParseError::EscapeChar => "Parsing escape character".to_string(),
|
||||
ParseError::InvalidCookieAttribute => "Parsing cookie attribute".to_string(),
|
||||
ParseError::OddNumberOfHexDigits => "Parsing hex bytearray".to_string(),
|
||||
ParseError::UrlIllegalCharacter(_) => "Parsing URL".to_string(),
|
||||
ParseError::UrlInvalidStart => "Parsing URL".to_string(),
|
||||
ParseError::Multiline => "Parsing multiline".to_string(),
|
||||
@ -74,11 +74,11 @@ impl Error for parser::Error {
|
||||
name.as_str(),
|
||||
"Valid values are GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH",
|
||||
)),
|
||||
ParseError::Version { .. } => "HTTP version must be HTTP, HTTP/1.0, HTTP/1.1 or HTTP/2".to_string(),
|
||||
ParseError::Status { .. } => "HTTP status code is not valid".to_string(),
|
||||
ParseError::Filename { .. } => "expecting a filename".to_string(),
|
||||
ParseError::Version => "HTTP version must be HTTP, HTTP/1.0, HTTP/1.1 or HTTP/2".to_string(),
|
||||
ParseError::Status => "HTTP status code is not valid".to_string(),
|
||||
ParseError::Filename => "expecting a filename".to_string(),
|
||||
ParseError::Expecting { value } => format!("expecting '{value}'"),
|
||||
ParseError::Space { .. } => "expecting a space".to_string(),
|
||||
ParseError::Space => "expecting a space".to_string(),
|
||||
ParseError::RequestSectionName { name }
|
||||
=> format!("the section is not valid. {}", did_you_mean(
|
||||
&["QueryStringParams", "FormParams", "MultipartFormData", "Cookies", "Options"],
|
||||
@ -91,25 +91,25 @@ impl Error for parser::Error {
|
||||
name.as_str(),
|
||||
"Valid values are Captures or Asserts",
|
||||
)),
|
||||
ParseError::JsonpathExpr { .. } => "expecting a JSONPath expression".to_string(),
|
||||
ParseError::XPathExpr { .. } => "expecting a XPath expression".to_string(),
|
||||
ParseError::TemplateVariable { .. } => "expecting a variable".to_string(),
|
||||
ParseError::Json { .. } => "JSON error".to_string(),
|
||||
ParseError::Predicate { .. } => "expecting a predicate".to_string(),
|
||||
ParseError::PredicateValue { .. } => "invalid predicate value".to_string(),
|
||||
ParseError::JsonPathExpr => "expecting a JSONPath expression".to_string(),
|
||||
ParseError::XPathExpr => "expecting a XPath expression".to_string(),
|
||||
ParseError::TemplateVariable => "expecting a variable".to_string(),
|
||||
ParseError::Json => "JSON error".to_string(),
|
||||
ParseError::Predicate => "expecting a predicate".to_string(),
|
||||
ParseError::PredicateValue => "invalid predicate value".to_string(),
|
||||
ParseError::RegexExpr { message } => format!("invalid Regex expression: {message}"),
|
||||
ParseError::DuplicateSection { .. } => "the section is already defined".to_string(),
|
||||
ParseError::RequestSection { .. } => {
|
||||
ParseError::DuplicateSection => "the section is already defined".to_string(),
|
||||
ParseError::RequestSection => {
|
||||
"this is not a valid section for a request".to_string()
|
||||
}
|
||||
ParseError::ResponseSection { .. } => {
|
||||
ParseError::ResponseSection => {
|
||||
"this is not a valid section for a response".to_string()
|
||||
}
|
||||
ParseError::EscapeChar { .. } => "the escaping sequence is not valid".to_string(),
|
||||
ParseError::InvalidCookieAttribute { .. } => {
|
||||
ParseError::EscapeChar => "the escaping sequence is not valid".to_string(),
|
||||
ParseError::InvalidCookieAttribute => {
|
||||
"the cookie attribute is not valid".to_string()
|
||||
}
|
||||
ParseError::OddNumberOfHexDigits { .. } => {
|
||||
ParseError::OddNumberOfHexDigits => {
|
||||
"expecting an even number of hex digits".to_string()
|
||||
}
|
||||
ParseError::UrlIllegalCharacter(c) => format!("illegal character <{c}>"),
|
||||
|
@ -247,7 +247,7 @@ impl HtmlFormatter {
|
||||
|
||||
fn fmt_variable_value(&mut self, option: &VariableValue) {
|
||||
match option {
|
||||
VariableValue::Null { .. } => self.fmt_span("null", "null"),
|
||||
VariableValue::Null => self.fmt_span("null", "null"),
|
||||
VariableValue::Bool(v) => self.fmt_bool(*v),
|
||||
VariableValue::Integer(v) => self.fmt_number(v),
|
||||
VariableValue::Float(v) => self.fmt_number(&v.encoded),
|
||||
@ -330,8 +330,8 @@ impl HtmlFormatter {
|
||||
|
||||
fn fmt_query_value(&mut self, query_value: &QueryValue) {
|
||||
match query_value {
|
||||
QueryValue::Status {} => self.fmt_span("query-type", "status"),
|
||||
QueryValue::Url {} => self.fmt_span("query-type", "url"),
|
||||
QueryValue::Status => self.fmt_span("query-type", "status"),
|
||||
QueryValue::Url => self.fmt_span("query-type", "url"),
|
||||
QueryValue::Header { space0, name } => {
|
||||
self.fmt_span("query-type", "header");
|
||||
self.fmt_space(space0);
|
||||
@ -342,7 +342,7 @@ impl HtmlFormatter {
|
||||
self.fmt_space(space0);
|
||||
self.fmt_cookie_path(expr);
|
||||
}
|
||||
QueryValue::Body {} => self.fmt_span("query-type", "body"),
|
||||
QueryValue::Body => self.fmt_span("query-type", "body"),
|
||||
QueryValue::Xpath { space0, expr } => {
|
||||
self.fmt_span("query-type", "xpath");
|
||||
self.fmt_space(space0);
|
||||
@ -363,10 +363,10 @@ impl HtmlFormatter {
|
||||
self.fmt_space(space0);
|
||||
self.fmt_template(name);
|
||||
}
|
||||
QueryValue::Duration {} => self.fmt_span("query-type", "duration"),
|
||||
QueryValue::Bytes {} => self.fmt_span("query-type", "bytes"),
|
||||
QueryValue::Sha256 {} => self.fmt_span("query-type", "sha256"),
|
||||
QueryValue::Md5 {} => self.fmt_span("query-type", "md5"),
|
||||
QueryValue::Duration => self.fmt_span("query-type", "duration"),
|
||||
QueryValue::Bytes => self.fmt_span("query-type", "bytes"),
|
||||
QueryValue::Sha256 => self.fmt_span("query-type", "sha256"),
|
||||
QueryValue::Md5 => self.fmt_span("query-type", "md5"),
|
||||
QueryValue::Certificate {
|
||||
space0,
|
||||
attribute_name: field,
|
||||
@ -497,14 +497,14 @@ impl HtmlFormatter {
|
||||
self.fmt_space(space0);
|
||||
self.fmt_predicate_value(value);
|
||||
}
|
||||
PredicateFuncValue::IsInteger {} => {}
|
||||
PredicateFuncValue::IsFloat {} => {}
|
||||
PredicateFuncValue::IsBoolean {} => {}
|
||||
PredicateFuncValue::IsString {} => {}
|
||||
PredicateFuncValue::IsCollection {} => {}
|
||||
PredicateFuncValue::IsDate {} => {}
|
||||
PredicateFuncValue::Exist {} => {}
|
||||
PredicateFuncValue::IsEmpty {} => {}
|
||||
PredicateFuncValue::IsInteger => {}
|
||||
PredicateFuncValue::IsFloat => {}
|
||||
PredicateFuncValue::IsBoolean => {}
|
||||
PredicateFuncValue::IsString => {}
|
||||
PredicateFuncValue::IsCollection => {}
|
||||
PredicateFuncValue::IsDate => {}
|
||||
PredicateFuncValue::Exist => {}
|
||||
PredicateFuncValue::IsEmpty => {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -518,7 +518,7 @@ impl HtmlFormatter {
|
||||
PredicateValue::Hex(value) => self.fmt_hex(value),
|
||||
PredicateValue::Base64(value) => self.fmt_base64(value),
|
||||
PredicateValue::Expression(value) => self.fmt_expr(value),
|
||||
PredicateValue::Null {} => self.fmt_span("null", "null"),
|
||||
PredicateValue::Null => self.fmt_span("null", "null"),
|
||||
PredicateValue::Regex(value) => self.fmt_regex(value),
|
||||
};
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ fn cookiepath_attribute_name(reader: &mut Reader) -> ParseResult<'static, Cookie
|
||||
_ => Err(Error {
|
||||
pos: start,
|
||||
recoverable: false,
|
||||
inner: ParseError::InvalidCookieAttribute {},
|
||||
inner: ParseError::InvalidCookieAttribute,
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -166,13 +166,13 @@ mod tests {
|
||||
let mut reader = Reader::new("cookie1[");
|
||||
let error = cookiepath(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 9 });
|
||||
assert_eq!(error.inner, ParseError::InvalidCookieAttribute {});
|
||||
assert_eq!(error.inner, ParseError::InvalidCookieAttribute);
|
||||
assert!(!error.recoverable);
|
||||
|
||||
let mut reader = Reader::new("cookie1[{{field]");
|
||||
let error = cookiepath(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 9 });
|
||||
assert_eq!(error.inner, ParseError::InvalidCookieAttribute {});
|
||||
assert_eq!(error.inner, ParseError::InvalidCookieAttribute);
|
||||
assert!(!error.recoverable);
|
||||
}
|
||||
|
||||
@ -195,6 +195,6 @@ mod tests {
|
||||
let mut reader = Reader::new("unknown");
|
||||
let error = cookiepath_attribute_name(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 1 });
|
||||
assert_eq!(error.inner, ParseError::InvalidCookieAttribute {});
|
||||
assert_eq!(error.inner, ParseError::InvalidCookieAttribute);
|
||||
}
|
||||
}
|
||||
|
@ -29,25 +29,25 @@ pub enum ParseError {
|
||||
Expecting { value: String },
|
||||
|
||||
Method { name: String },
|
||||
Version {},
|
||||
Status {},
|
||||
Filename {},
|
||||
FileContentType {},
|
||||
Space {},
|
||||
Version,
|
||||
Status,
|
||||
Filename,
|
||||
FileContentType,
|
||||
Space,
|
||||
RequestSectionName { name: String },
|
||||
ResponseSectionName { name: String },
|
||||
JsonpathExpr {},
|
||||
XPathExpr {},
|
||||
TemplateVariable {},
|
||||
Json {},
|
||||
Xml {},
|
||||
JsonPathExpr,
|
||||
XPathExpr,
|
||||
TemplateVariable,
|
||||
Json,
|
||||
Xml,
|
||||
Predicate,
|
||||
PredicateValue,
|
||||
RegexExpr { message: String },
|
||||
|
||||
Unexpected { character: String },
|
||||
Eof {},
|
||||
Url {},
|
||||
Eof,
|
||||
Url,
|
||||
|
||||
DuplicateSection,
|
||||
RequestSection,
|
||||
|
@ -62,7 +62,7 @@ fn variable_name(reader: &mut Reader) -> ParseResult<'static, Variable> {
|
||||
return Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::TemplateVariable {},
|
||||
inner: ParseError::TemplateVariable,
|
||||
});
|
||||
}
|
||||
Ok(Variable {
|
||||
|
@ -32,7 +32,7 @@ pub fn parse(reader: &mut Reader) -> ParseResult<'static, Filename> {
|
||||
return Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::Filename {},
|
||||
inner: ParseError::Filename,
|
||||
});
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ mod tests {
|
||||
fn test_filename_error() {
|
||||
let mut reader = Reader::new("???");
|
||||
let error = parse(&mut reader).err().unwrap();
|
||||
assert_eq!(error.inner, ParseError::Filename {});
|
||||
assert_eq!(error.inner, ParseError::Filename);
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 1 });
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ pub fn parse(reader: &mut Reader) -> ParseResult<'static, JsonValue> {
|
||||
|
||||
pub fn null_value(reader: &mut Reader) -> ParseResult<'static, JsonValue> {
|
||||
try_literal("null", reader)?;
|
||||
Ok(JsonValue::Null {})
|
||||
Ok(JsonValue::Null)
|
||||
}
|
||||
|
||||
pub fn boolean_value(reader: &mut Reader) -> ParseResult<'static, JsonValue> {
|
||||
@ -136,7 +136,7 @@ fn escape_char(reader: &mut Reader) -> ParseResult<'static, char> {
|
||||
_ => Err(error::Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: error::ParseError::EscapeChar {},
|
||||
inner: error::ParseError::EscapeChar,
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -148,7 +148,7 @@ fn unicode(reader: &mut Reader) -> ParseResult<'static, char> {
|
||||
return Err(error::Error {
|
||||
pos: reader.clone().state.pos,
|
||||
recoverable: false,
|
||||
inner: error::ParseError::Unicode {},
|
||||
inner: error::ParseError::Unicode,
|
||||
})
|
||||
}
|
||||
Some(c) => c,
|
||||
@ -270,7 +270,7 @@ fn list_element(reader: &mut Reader) -> ParseResult<'static, JsonListElement> {
|
||||
return Err(error::Error {
|
||||
pos: save,
|
||||
recoverable: false,
|
||||
inner: error::ParseError::Json {},
|
||||
inner: error::ParseError::Json,
|
||||
})
|
||||
}
|
||||
};
|
||||
@ -317,7 +317,7 @@ fn key(reader: &mut Reader) -> ParseResult<'static, Template> {
|
||||
Err(error::Error {
|
||||
pos: save.pos,
|
||||
recoverable: false,
|
||||
inner: error::ParseError::Json {},
|
||||
inner: error::ParseError::Json,
|
||||
})
|
||||
} else {
|
||||
Ok(name)
|
||||
@ -338,7 +338,7 @@ fn object_element(reader: &mut Reader) -> ParseResult<'static, JsonObjectElement
|
||||
return Err(error::Error {
|
||||
pos: save,
|
||||
recoverable: false,
|
||||
inner: error::ParseError::Json {},
|
||||
inner: error::ParseError::Json,
|
||||
})
|
||||
}
|
||||
};
|
||||
@ -367,20 +367,20 @@ mod tests {
|
||||
let mut reader = Reader::new("{ \"a\":\n}");
|
||||
let error = parse(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 7 });
|
||||
assert_eq!(error.inner, error::ParseError::Json {});
|
||||
assert_eq!(error.inner, error::ParseError::Json);
|
||||
assert!(!error.recoverable);
|
||||
|
||||
let mut reader = Reader::new("[0,1,]");
|
||||
let error = parse(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 6 });
|
||||
assert_eq!(error.inner, error::ParseError::Json {});
|
||||
assert_eq!(error.inner, error::ParseError::Json);
|
||||
assert!(!error.recoverable);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_null_value() {
|
||||
let mut reader = Reader::new("null");
|
||||
assert_eq!(null_value(&mut reader).unwrap(), JsonValue::Null {});
|
||||
assert_eq!(null_value(&mut reader).unwrap(), JsonValue::Null);
|
||||
assert_eq!(reader.state.cursor, 4);
|
||||
|
||||
let mut reader = Reader::new("true");
|
||||
@ -762,7 +762,7 @@ mod tests {
|
||||
let mut reader = Reader::new("[1, 2,]");
|
||||
let error = list_value(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 7 });
|
||||
assert_eq!(error.inner, error::ParseError::Json {});
|
||||
assert_eq!(error.inner, error::ParseError::Json);
|
||||
assert!(!error.recoverable);
|
||||
}
|
||||
|
||||
@ -843,7 +843,7 @@ mod tests {
|
||||
let mut reader = Reader::new("{ \"a\":\n}");
|
||||
let error = object_value(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 7 });
|
||||
assert_eq!(error.inner, error::ParseError::Json {});
|
||||
assert_eq!(error.inner, error::ParseError::Json);
|
||||
assert!(!error.recoverable);
|
||||
}
|
||||
|
||||
@ -887,7 +887,7 @@ mod tests {
|
||||
let mut reader = Reader::new("\"name\":\n");
|
||||
let error = object_element(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 8 });
|
||||
assert_eq!(error.inner, error::ParseError::Json {});
|
||||
assert_eq!(error.inner, error::ParseError::Json);
|
||||
assert!(!error.recoverable);
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ fn whitespace(reader: &mut Reader) -> ParseResult<'static, Whitespace> {
|
||||
None => Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: true,
|
||||
inner: ParseError::Space {},
|
||||
inner: ParseError::Space,
|
||||
}),
|
||||
Some(c) => {
|
||||
if c == ' ' || c == '\t' || c == '\n' || c == '\r' {
|
||||
@ -169,7 +169,7 @@ fn whitespace(reader: &mut Reader) -> ParseResult<'static, Whitespace> {
|
||||
Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: true,
|
||||
inner: ParseError::Space {},
|
||||
inner: ParseError::Space,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ fn version(reader: &mut Reader) -> ParseResult<'static, Version> {
|
||||
Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::Version {},
|
||||
inner: ParseError::Version,
|
||||
})
|
||||
}
|
||||
Some(' ') => Ok(Version {
|
||||
@ -189,7 +189,7 @@ fn version(reader: &mut Reader) -> ParseResult<'static, Version> {
|
||||
_ => Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::Version {},
|
||||
inner: ParseError::Version,
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -204,7 +204,7 @@ fn status(reader: &mut Reader) -> ParseResult<'static, Status> {
|
||||
return Err(Error {
|
||||
pos: start,
|
||||
recoverable: false,
|
||||
inner: ParseError::Status {},
|
||||
inner: ParseError::Status,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -178,7 +178,7 @@ fn greater_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncV
|
||||
Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::PredicateValue {},
|
||||
inner: ParseError::PredicateValue,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -205,7 +205,7 @@ fn greater_or_equal_predicate(reader: &mut Reader) -> ParseResult<'static, Predi
|
||||
Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::PredicateValue {},
|
||||
inner: ParseError::PredicateValue,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -232,7 +232,7 @@ fn less_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncValu
|
||||
Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::PredicateValue {},
|
||||
inner: ParseError::PredicateValue,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -259,7 +259,7 @@ fn less_or_equal_predicate(reader: &mut Reader) -> ParseResult<'static, Predicat
|
||||
Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::PredicateValue {},
|
||||
inner: ParseError::PredicateValue,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -273,7 +273,7 @@ fn start_with_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFu
|
||||
return Err(Error {
|
||||
pos: save.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::PredicateValue {},
|
||||
inner: ParseError::PredicateValue,
|
||||
});
|
||||
}
|
||||
Ok(PredicateFuncValue::StartWith { space0, value })
|
||||
@ -288,7 +288,7 @@ fn end_with_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFunc
|
||||
return Err(Error {
|
||||
pos: save.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::PredicateValue {},
|
||||
inner: ParseError::PredicateValue,
|
||||
});
|
||||
}
|
||||
Ok(PredicateFuncValue::EndWith { space0, value })
|
||||
@ -303,7 +303,7 @@ fn contain_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncV
|
||||
return Err(Error {
|
||||
pos: save.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::PredicateValue {},
|
||||
inner: ParseError::PredicateValue,
|
||||
});
|
||||
}
|
||||
Ok(PredicateFuncValue::Contain { space0, value })
|
||||
@ -325,7 +325,7 @@ fn match_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncVal
|
||||
return Err(Error {
|
||||
pos: save.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::PredicateValue {},
|
||||
inner: ParseError::PredicateValue,
|
||||
});
|
||||
}
|
||||
Ok(PredicateFuncValue::Match { space0, value })
|
||||
@ -333,42 +333,42 @@ fn match_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncVal
|
||||
|
||||
fn integer_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncValue> {
|
||||
try_literal("isInteger", reader)?;
|
||||
Ok(PredicateFuncValue::IsInteger {})
|
||||
Ok(PredicateFuncValue::IsInteger)
|
||||
}
|
||||
|
||||
fn float_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncValue> {
|
||||
try_literal("isFloat", reader)?;
|
||||
Ok(PredicateFuncValue::IsFloat {})
|
||||
Ok(PredicateFuncValue::IsFloat)
|
||||
}
|
||||
|
||||
fn boolean_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncValue> {
|
||||
try_literal("isBoolean", reader)?;
|
||||
Ok(PredicateFuncValue::IsBoolean {})
|
||||
Ok(PredicateFuncValue::IsBoolean)
|
||||
}
|
||||
|
||||
fn string_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncValue> {
|
||||
try_literal("isString", reader)?;
|
||||
Ok(PredicateFuncValue::IsString {})
|
||||
Ok(PredicateFuncValue::IsString)
|
||||
}
|
||||
|
||||
fn collection_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncValue> {
|
||||
try_literal("isCollection", reader)?;
|
||||
Ok(PredicateFuncValue::IsCollection {})
|
||||
Ok(PredicateFuncValue::IsCollection)
|
||||
}
|
||||
|
||||
fn date_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncValue> {
|
||||
try_literal("isDate", reader)?;
|
||||
Ok(PredicateFuncValue::IsDate {})
|
||||
Ok(PredicateFuncValue::IsDate)
|
||||
}
|
||||
|
||||
fn exist_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncValue> {
|
||||
try_literal("exists", reader)?;
|
||||
Ok(PredicateFuncValue::Exist {})
|
||||
Ok(PredicateFuncValue::Exist)
|
||||
}
|
||||
|
||||
fn is_empty_predicate(reader: &mut Reader) -> ParseResult<'static, PredicateFuncValue> {
|
||||
try_literal("isEmpty", reader)?;
|
||||
Ok(PredicateFuncValue::IsEmpty {})
|
||||
Ok(PredicateFuncValue::IsEmpty)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -437,7 +437,7 @@ mod tests {
|
||||
let error = predicate_func(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 1 });
|
||||
assert!(!error.recoverable);
|
||||
assert_eq!(error.inner, ParseError::Predicate {});
|
||||
assert_eq!(error.inner, ParseError::Predicate);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -560,13 +560,13 @@ mod tests {
|
||||
}
|
||||
);
|
||||
assert!(!error.recoverable);
|
||||
assert_eq!(error.inner, ParseError::PredicateValue {});
|
||||
assert_eq!(error.inner, ParseError::PredicateValue);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_predicate() {
|
||||
let mut reader = Reader::new("isDate");
|
||||
let result = date_predicate(&mut reader);
|
||||
assert_eq!(result.unwrap(), PredicateFuncValue::IsDate {});
|
||||
assert_eq!(result.unwrap(), PredicateFuncValue::IsDate);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ pub fn predicate_value(reader: &mut Reader) -> ParseResult<'static, PredicateVal
|
||||
choice(
|
||||
&[
|
||||
|p1| match null(p1) {
|
||||
Ok(()) => Ok(PredicateValue::Null {}),
|
||||
Ok(()) => Ok(PredicateValue::Null),
|
||||
Err(e) => Err(e),
|
||||
},
|
||||
|p1| match boolean(p1) {
|
||||
@ -115,7 +115,7 @@ mod tests {
|
||||
let mut reader = Reader::new("xx");
|
||||
let error = predicate_value(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 1 });
|
||||
assert_eq!(error.inner, ParseError::PredicateValue {});
|
||||
assert_eq!(error.inner, ParseError::PredicateValue);
|
||||
assert!(!error.recoverable);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ pub fn space(reader: &mut Reader) -> ParseResult<'static, Whitespace> {
|
||||
None => Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: true,
|
||||
inner: ParseError::Space {},
|
||||
inner: ParseError::Space,
|
||||
}),
|
||||
Some(c) => {
|
||||
if c == ' ' || c == '\t' {
|
||||
@ -45,7 +45,7 @@ pub fn space(reader: &mut Reader) -> ParseResult<'static, Whitespace> {
|
||||
Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: true,
|
||||
inner: ParseError::Space {},
|
||||
inner: ParseError::Space,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -313,7 +313,7 @@ pub fn hex(reader: &mut Reader) -> ParseResult<'static, Hex> {
|
||||
return Err(Error {
|
||||
pos: reader.state.pos.clone(),
|
||||
recoverable: false,
|
||||
inner: ParseError::OddNumberOfHexDigits {},
|
||||
inner: ParseError::OddNumberOfHexDigits,
|
||||
});
|
||||
}
|
||||
let encoded = reader.peek_back(start);
|
||||
@ -345,7 +345,7 @@ pub fn regex(reader: &mut Reader) -> ParseResult<'static, Regex> {
|
||||
return Err(Error {
|
||||
pos: reader.state.pos.clone(),
|
||||
recoverable: false,
|
||||
inner: ParseError::Eof {},
|
||||
inner: ParseError::Eof,
|
||||
})
|
||||
}
|
||||
Some('/') => break,
|
||||
@ -579,13 +579,13 @@ pub fn hex_digit(reader: &mut Reader) -> ParseResult<'static, u32> {
|
||||
None => Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: true,
|
||||
inner: ParseError::HexDigit {},
|
||||
inner: ParseError::HexDigit,
|
||||
}),
|
||||
},
|
||||
None => Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: true,
|
||||
inner: ParseError::HexDigit {},
|
||||
inner: ParseError::HexDigit,
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -1069,7 +1069,7 @@ mod tests {
|
||||
let mut reader = Reader::new("x");
|
||||
let error = hex_digit(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 1 });
|
||||
assert_eq!(error.inner, ParseError::HexDigit {});
|
||||
assert_eq!(error.inner, ParseError::HexDigit);
|
||||
assert!(error.recoverable);
|
||||
}
|
||||
|
||||
@ -1115,7 +1115,7 @@ mod tests {
|
||||
let mut reader = Reader::new("hex,012;");
|
||||
let error = hex(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 8 });
|
||||
assert_eq!(error.inner, ParseError::OddNumberOfHexDigits {});
|
||||
assert_eq!(error.inner, ParseError::OddNumberOfHexDigits);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1164,7 +1164,7 @@ mod tests {
|
||||
let error = regex(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 5 });
|
||||
assert!(!error.recoverable);
|
||||
assert_eq!(error.inner, ParseError::Eof {});
|
||||
assert_eq!(error.inner, ParseError::Eof);
|
||||
|
||||
let mut reader = Reader::new("/x{a}/");
|
||||
let error = regex(&mut reader).err().unwrap();
|
||||
|
@ -57,12 +57,12 @@ fn query_value(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
|
||||
fn status_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
try_literal("status", reader)?;
|
||||
Ok(QueryValue::Status {})
|
||||
Ok(QueryValue::Status)
|
||||
}
|
||||
|
||||
fn url_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
try_literal("url", reader)?;
|
||||
Ok(QueryValue::Url {})
|
||||
Ok(QueryValue::Url)
|
||||
}
|
||||
|
||||
fn header_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
@ -92,7 +92,7 @@ fn cookie_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
|
||||
fn body_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
try_literal("body", reader)?;
|
||||
Ok(QueryValue::Body {})
|
||||
Ok(QueryValue::Body)
|
||||
}
|
||||
|
||||
fn xpath_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
@ -162,22 +162,22 @@ fn variable_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
|
||||
fn duration_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
try_literal("duration", reader)?;
|
||||
Ok(QueryValue::Duration {})
|
||||
Ok(QueryValue::Duration)
|
||||
}
|
||||
|
||||
fn bytes_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
try_literal("bytes", reader)?;
|
||||
Ok(QueryValue::Bytes {})
|
||||
Ok(QueryValue::Bytes)
|
||||
}
|
||||
|
||||
fn sha256_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
try_literal("sha256", reader)?;
|
||||
Ok(QueryValue::Sha256 {})
|
||||
Ok(QueryValue::Sha256)
|
||||
}
|
||||
|
||||
fn md5_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
try_literal("md5", reader)?;
|
||||
Ok(QueryValue::Md5 {})
|
||||
Ok(QueryValue::Md5)
|
||||
}
|
||||
|
||||
fn certificate_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
|
||||
@ -227,7 +227,7 @@ mod tests {
|
||||
query(&mut reader).unwrap(),
|
||||
Query {
|
||||
source_info: SourceInfo::new(1, 1, 1, 7),
|
||||
value: QueryValue::Status {},
|
||||
value: QueryValue::Status,
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -239,7 +239,7 @@ mod tests {
|
||||
query(&mut reader).unwrap(),
|
||||
Query {
|
||||
source_info: SourceInfo::new(1, 1, 1, 7),
|
||||
value: QueryValue::Status {},
|
||||
value: QueryValue::Status,
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -390,7 +390,7 @@ mod tests {
|
||||
query(&mut reader).unwrap(),
|
||||
Query {
|
||||
source_info: SourceInfo::new(1, 1, 1, 5),
|
||||
value: QueryValue::Body {},
|
||||
value: QueryValue::Body,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
|
@ -282,7 +282,7 @@ fn file_content_type(reader: &mut Reader) -> ParseResult<'static, String> {
|
||||
return Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::FileContentType {},
|
||||
inner: ParseError::FileContentType,
|
||||
});
|
||||
}
|
||||
Ok(buf)
|
||||
@ -597,7 +597,7 @@ fn variable_value(reader: &mut Reader) -> ParseResult<'static, VariableValue> {
|
||||
choice(
|
||||
&[
|
||||
|p1| match null(p1) {
|
||||
Ok(()) => Ok(VariableValue::Null {}),
|
||||
Ok(()) => Ok(VariableValue::Null),
|
||||
Err(e) => Err(e),
|
||||
},
|
||||
|p1| match boolean(p1) {
|
||||
@ -967,7 +967,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_variable_value() {
|
||||
let mut reader = Reader::new("null");
|
||||
assert_eq!(variable_value(&mut reader).unwrap(), VariableValue::Null {});
|
||||
assert_eq!(variable_value(&mut reader).unwrap(), VariableValue::Null);
|
||||
|
||||
let mut reader = Reader::new("true");
|
||||
assert_eq!(
|
||||
|
@ -290,7 +290,7 @@ fn escape_char(reader: &mut Reader) -> ParseResult<'static, char> {
|
||||
_ => Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::EscapeChar {},
|
||||
inner: ParseError::EscapeChar,
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -303,7 +303,7 @@ fn unicode(reader: &mut Reader) -> ParseResult<'static, char> {
|
||||
return Err(Error {
|
||||
pos: reader.clone().state.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::Unicode {},
|
||||
inner: ParseError::Unicode,
|
||||
});
|
||||
}
|
||||
Some(c) => c,
|
||||
@ -560,7 +560,7 @@ mod tests {
|
||||
let mut reader = Reader::new("\\l");
|
||||
let error = unquoted_string_key(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 2 });
|
||||
assert_eq!(error.inner, ParseError::EscapeChar {});
|
||||
assert_eq!(error.inner, ParseError::EscapeChar);
|
||||
|
||||
let mut reader = Reader::new(r#"{"id":1}"#);
|
||||
let error = unquoted_string_key(&mut reader).err().unwrap();
|
||||
|
@ -26,61 +26,61 @@ pub struct EncodedString {
|
||||
|
||||
pub fn templatize(encoded_string: EncodedString) -> ParseResult<'static, Vec<TemplateElement>> {
|
||||
enum State {
|
||||
String {},
|
||||
Template {},
|
||||
FirstOpenBracket {},
|
||||
FirstCloseBracket {},
|
||||
String,
|
||||
Template,
|
||||
FirstOpenBracket,
|
||||
FirstCloseBracket,
|
||||
}
|
||||
|
||||
let mut elements = vec![];
|
||||
|
||||
let mut value = "".to_string();
|
||||
let mut encoded = "".to_string();
|
||||
let mut state = State::String {};
|
||||
let mut state = State::String;
|
||||
let mut expression_start = None;
|
||||
|
||||
for (c, s, pos) in encoded_string.chars {
|
||||
match state {
|
||||
State::String {} => {
|
||||
State::String => {
|
||||
if s.as_str() == "{" {
|
||||
state = State::FirstOpenBracket {};
|
||||
state = State::FirstOpenBracket;
|
||||
} else {
|
||||
value.push(c);
|
||||
encoded.push_str(&s.clone());
|
||||
}
|
||||
}
|
||||
|
||||
State::FirstOpenBracket {} => {
|
||||
State::FirstOpenBracket => {
|
||||
if s.as_str() == "{" {
|
||||
if !value.is_empty() {
|
||||
elements.push(TemplateElement::String { value, encoded });
|
||||
value = "".to_string();
|
||||
encoded = "".to_string();
|
||||
}
|
||||
state = State::Template {};
|
||||
state = State::Template;
|
||||
} else {
|
||||
value.push('{');
|
||||
encoded.push('{');
|
||||
|
||||
value.push(c);
|
||||
encoded.push_str(&s.clone());
|
||||
state = State::String {};
|
||||
state = State::String;
|
||||
}
|
||||
}
|
||||
|
||||
State::Template {} => {
|
||||
State::Template => {
|
||||
if expression_start.is_none() {
|
||||
expression_start = Some(pos);
|
||||
}
|
||||
if s.as_str() == "}" {
|
||||
state = State::FirstCloseBracket {};
|
||||
state = State::FirstCloseBracket;
|
||||
} else {
|
||||
value.push(c);
|
||||
encoded.push_str(&s.clone());
|
||||
}
|
||||
}
|
||||
|
||||
State::FirstCloseBracket {} => {
|
||||
State::FirstCloseBracket => {
|
||||
if s.as_str() == "}" {
|
||||
let mut reader = Reader::new(encoded.as_str());
|
||||
reader.state = ReaderState {
|
||||
@ -92,7 +92,7 @@ pub fn templatize(encoded_string: EncodedString) -> ParseResult<'static, Vec<Tem
|
||||
value = "".to_string();
|
||||
encoded = "".to_string();
|
||||
expression_start = None;
|
||||
state = State::String {};
|
||||
state = State::String;
|
||||
} else {
|
||||
value.push('}');
|
||||
value.push(c);
|
||||
@ -104,12 +104,12 @@ pub fn templatize(encoded_string: EncodedString) -> ParseResult<'static, Vec<Tem
|
||||
}
|
||||
|
||||
match state {
|
||||
State::String {} => {}
|
||||
State::FirstOpenBracket {} => {
|
||||
State::String => {}
|
||||
State::FirstOpenBracket => {
|
||||
value.push('{');
|
||||
encoded.push('{');
|
||||
}
|
||||
State::Template {} | State::FirstCloseBracket {} => {
|
||||
State::Template | State::FirstCloseBracket => {
|
||||
return Err(error::Error {
|
||||
pos: encoded_string.source_info.end,
|
||||
recoverable: false,
|
||||
|
@ -33,7 +33,7 @@ pub fn url(reader: &mut Reader) -> ParseResult<'static, Template> {
|
||||
return Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::Url {},
|
||||
inner: ParseError::Url,
|
||||
});
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ pub fn url(reader: &mut Reader) -> ParseResult<'static, Template> {
|
||||
return Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::Url {},
|
||||
inner: ParseError::Url,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ pub fn parse(reader: &mut Reader) -> ParseResult<'static, String> {
|
||||
return Err(Error {
|
||||
pos: Pos { line: 1, column: 1 },
|
||||
recoverable: true,
|
||||
inner: ParseError::Xml {},
|
||||
inner: ParseError::Xml,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -52,7 +52,7 @@ pub fn parse(reader: &mut Reader) -> ParseResult<'static, String> {
|
||||
Err(Error {
|
||||
pos: start.pos,
|
||||
recoverable: false,
|
||||
inner: ParseError::Xml {},
|
||||
inner: ParseError::Xml,
|
||||
})
|
||||
}
|
||||
|
||||
@ -69,30 +69,30 @@ mod tests {
|
||||
let mut reader = Reader::new("");
|
||||
let error = parse(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 1 });
|
||||
assert_eq!(error.inner, ParseError::Xml {});
|
||||
assert_eq!(error.inner, ParseError::Xml);
|
||||
assert!(error.recoverable);
|
||||
|
||||
let mut reader = Reader::new("x");
|
||||
let error = parse(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 1 });
|
||||
assert_eq!(error.inner, ParseError::Xml {});
|
||||
assert_eq!(error.inner, ParseError::Xml);
|
||||
assert!(error.recoverable);
|
||||
|
||||
let mut reader = Reader::new("<<");
|
||||
let error = parse(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 1 });
|
||||
assert_eq!(error.inner, ParseError::Xml {});
|
||||
assert_eq!(error.inner, ParseError::Xml);
|
||||
assert!(!error.recoverable);
|
||||
|
||||
let mut reader = Reader::new("<users><user /></users");
|
||||
let error = parse(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 1 });
|
||||
assert_eq!(error.inner, ParseError::Xml {});
|
||||
assert_eq!(error.inner, ParseError::Xml);
|
||||
|
||||
let mut reader = Reader::new("<users aa><user /></users");
|
||||
let error = parse(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 1 });
|
||||
assert_eq!(error.inner, ParseError::Xml {});
|
||||
assert_eq!(error.inner, ParseError::Xml);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -340,13 +340,13 @@ impl ToJson for Query {
|
||||
fn query_value_attributes(query_value: &QueryValue) -> Vec<(String, JValue)> {
|
||||
let mut attributes = vec![];
|
||||
match query_value {
|
||||
QueryValue::Status {} => {
|
||||
QueryValue::Status => {
|
||||
attributes.push(("type".to_string(), JValue::String("status".to_string())));
|
||||
}
|
||||
QueryValue::Url {} => {
|
||||
QueryValue::Url => {
|
||||
attributes.push(("type".to_string(), JValue::String("url".to_string())));
|
||||
}
|
||||
QueryValue::Body {} => {
|
||||
QueryValue::Body => {
|
||||
attributes.push(("type".to_string(), JValue::String("body".to_string())));
|
||||
}
|
||||
QueryValue::Jsonpath { expr, .. } => {
|
||||
@ -373,16 +373,16 @@ fn query_value_attributes(query_value: &QueryValue) -> Vec<(String, JValue)> {
|
||||
attributes.push(("type".to_string(), JValue::String("variable".to_string())));
|
||||
attributes.push(("name".to_string(), JValue::String(name.to_string())));
|
||||
}
|
||||
QueryValue::Duration {} => {
|
||||
QueryValue::Duration => {
|
||||
attributes.push(("type".to_string(), JValue::String("duration".to_string())));
|
||||
}
|
||||
QueryValue::Bytes {} => {
|
||||
QueryValue::Bytes => {
|
||||
attributes.push(("type".to_string(), JValue::String("bytes".to_string())));
|
||||
}
|
||||
QueryValue::Sha256 {} => {
|
||||
QueryValue::Sha256 => {
|
||||
attributes.push(("type".to_string(), JValue::String("sha256".to_string())));
|
||||
}
|
||||
QueryValue::Md5 {} => {
|
||||
QueryValue::Md5 => {
|
||||
attributes.push(("type".to_string(), JValue::String("md5".to_string())));
|
||||
}
|
||||
QueryValue::Certificate {
|
||||
@ -488,31 +488,31 @@ impl ToJson for Predicate {
|
||||
attributes.push(("type".to_string(), JValue::String("match".to_string())));
|
||||
add_predicate_value(&mut attributes, value);
|
||||
}
|
||||
PredicateFuncValue::IsInteger {} => {
|
||||
PredicateFuncValue::IsInteger => {
|
||||
attributes.push(("type".to_string(), JValue::String("isInteger".to_string())));
|
||||
}
|
||||
PredicateFuncValue::IsFloat {} => {
|
||||
PredicateFuncValue::IsFloat => {
|
||||
attributes.push(("type".to_string(), JValue::String("isFloat".to_string())));
|
||||
}
|
||||
PredicateFuncValue::IsBoolean {} => {
|
||||
PredicateFuncValue::IsBoolean => {
|
||||
attributes.push(("type".to_string(), JValue::String("isBoolean".to_string())));
|
||||
}
|
||||
PredicateFuncValue::IsString {} => {
|
||||
PredicateFuncValue::IsString => {
|
||||
attributes.push(("type".to_string(), JValue::String("isString".to_string())));
|
||||
}
|
||||
PredicateFuncValue::IsCollection {} => {
|
||||
PredicateFuncValue::IsCollection => {
|
||||
attributes.push((
|
||||
"type".to_string(),
|
||||
JValue::String("isCollection".to_string()),
|
||||
));
|
||||
}
|
||||
PredicateFuncValue::IsDate {} => {
|
||||
PredicateFuncValue::IsDate => {
|
||||
attributes.push(("type".to_string(), JValue::String("isDate".to_string())));
|
||||
}
|
||||
PredicateFuncValue::Exist {} => {
|
||||
PredicateFuncValue::Exist => {
|
||||
attributes.push(("type".to_string(), JValue::String("exist".to_string())));
|
||||
}
|
||||
PredicateFuncValue::IsEmpty {} => {
|
||||
PredicateFuncValue::IsEmpty => {
|
||||
attributes.push(("type".to_string(), JValue::String("isEmpty".to_string())));
|
||||
}
|
||||
}
|
||||
@ -535,7 +535,7 @@ fn json_predicate_value(predicate_value: PredicateValue) -> (JValue, Option<Stri
|
||||
PredicateValue::Integer(value) => (JValue::Number(value.to_string()), None),
|
||||
PredicateValue::Float(value) => (JValue::Number(value.to_string()), None),
|
||||
PredicateValue::Bool(value) => (JValue::Boolean(value), None),
|
||||
PredicateValue::Null {} => (JValue::Null, None),
|
||||
PredicateValue::Null => (JValue::Null, None),
|
||||
PredicateValue::Hex(value) => {
|
||||
let base64_string = general_purpose::STANDARD.encode(value.value);
|
||||
(JValue::String(base64_string), Some("base64".to_string()))
|
||||
@ -554,7 +554,7 @@ fn json_predicate_value(predicate_value: PredicateValue) -> (JValue, Option<Stri
|
||||
impl ToJson for JsonValue {
|
||||
fn to_json(&self) -> JValue {
|
||||
match self {
|
||||
JsonValue::Null {} => JValue::Null {},
|
||||
JsonValue::Null => JValue::Null,
|
||||
JsonValue::Number(s) => JValue::Number(s.to_string()),
|
||||
JsonValue::String(s) => JValue::String(s.to_string()),
|
||||
JsonValue::Boolean(v) => JValue::Boolean(*v),
|
||||
|
@ -95,7 +95,7 @@ pub mod tests {
|
||||
|
||||
#[test]
|
||||
pub fn format_scalars() {
|
||||
assert_eq!(JValue::Null {}.format(), "null");
|
||||
assert_eq!(JValue::Null.format(), "null");
|
||||
assert_eq!(JValue::Number("1.0".to_string()).format(), "1.0");
|
||||
assert_eq!(JValue::String("hello".to_string()).format(), "\"hello\"");
|
||||
assert_eq!(JValue::Boolean(true).format(), "true");
|
||||
|
@ -401,8 +401,8 @@ impl Tokenizable for QueryValue {
|
||||
fn tokenize(&self) -> Vec<Token> {
|
||||
let mut tokens: Vec<Token> = vec![];
|
||||
match self.clone() {
|
||||
QueryValue::Status {} => tokens.push(Token::QueryType(String::from("status"))),
|
||||
QueryValue::Url {} => tokens.push(Token::QueryType(String::from("url"))),
|
||||
QueryValue::Status => tokens.push(Token::QueryType(String::from("status"))),
|
||||
QueryValue::Url => tokens.push(Token::QueryType(String::from("url"))),
|
||||
QueryValue::Header { space0, name } => {
|
||||
tokens.push(Token::QueryType(String::from("header")));
|
||||
tokens.append(&mut space0.tokenize());
|
||||
@ -415,7 +415,7 @@ impl Tokenizable for QueryValue {
|
||||
tokens.append(&mut expr.tokenize());
|
||||
tokens.push(Token::CodeDelimiter("\"".to_string()));
|
||||
}
|
||||
QueryValue::Body {} => tokens.push(Token::QueryType(String::from("body"))),
|
||||
QueryValue::Body => tokens.push(Token::QueryType(String::from("body"))),
|
||||
QueryValue::Xpath { space0, expr } => {
|
||||
tokens.push(Token::QueryType(String::from("xpath")));
|
||||
tokens.append(&mut space0.tokenize());
|
||||
@ -436,10 +436,10 @@ impl Tokenizable for QueryValue {
|
||||
tokens.append(&mut space0.tokenize());
|
||||
tokens.append(&mut name.tokenize());
|
||||
}
|
||||
QueryValue::Duration {} => tokens.push(Token::QueryType(String::from("duration"))),
|
||||
QueryValue::Bytes {} => tokens.push(Token::QueryType(String::from("bytes"))),
|
||||
QueryValue::Sha256 {} => tokens.push(Token::QueryType(String::from("sha256"))),
|
||||
QueryValue::Md5 {} => tokens.push(Token::QueryType(String::from("md5"))),
|
||||
QueryValue::Duration => tokens.push(Token::QueryType(String::from("duration"))),
|
||||
QueryValue::Bytes => tokens.push(Token::QueryType(String::from("bytes"))),
|
||||
QueryValue::Sha256 => tokens.push(Token::QueryType(String::from("sha256"))),
|
||||
QueryValue::Md5 => tokens.push(Token::QueryType(String::from("md5"))),
|
||||
QueryValue::Certificate {
|
||||
space0,
|
||||
attribute_name: field,
|
||||
@ -575,28 +575,28 @@ impl Tokenizable for PredicateFuncValue {
|
||||
tokens.append(&mut value.tokenize());
|
||||
}
|
||||
|
||||
PredicateFuncValue::IsInteger {} => {
|
||||
PredicateFuncValue::IsInteger => {
|
||||
tokens.push(Token::PredicateType(self.name()));
|
||||
}
|
||||
PredicateFuncValue::IsFloat {} => {
|
||||
PredicateFuncValue::IsFloat => {
|
||||
tokens.push(Token::PredicateType(self.name()));
|
||||
}
|
||||
PredicateFuncValue::IsBoolean {} => {
|
||||
PredicateFuncValue::IsBoolean => {
|
||||
tokens.push(Token::PredicateType(self.name()));
|
||||
}
|
||||
PredicateFuncValue::IsString {} => {
|
||||
PredicateFuncValue::IsString => {
|
||||
tokens.push(Token::PredicateType(self.name()));
|
||||
}
|
||||
PredicateFuncValue::IsCollection {} => {
|
||||
PredicateFuncValue::IsCollection => {
|
||||
tokens.push(Token::PredicateType(self.name()));
|
||||
}
|
||||
PredicateFuncValue::IsDate {} => {
|
||||
PredicateFuncValue::IsDate => {
|
||||
tokens.push(Token::PredicateType(self.name()));
|
||||
}
|
||||
PredicateFuncValue::Exist {} => {
|
||||
PredicateFuncValue::Exist => {
|
||||
tokens.push(Token::PredicateType(self.name()));
|
||||
}
|
||||
PredicateFuncValue::IsEmpty {} => {
|
||||
PredicateFuncValue::IsEmpty => {
|
||||
tokens.push(Token::PredicateType(self.name()));
|
||||
}
|
||||
}
|
||||
@ -612,7 +612,7 @@ impl Tokenizable for PredicateValue {
|
||||
PredicateValue::Integer(value) => vec![Token::Number(value.to_string())],
|
||||
PredicateValue::Float(value) => vec![Token::Number(value.to_string())],
|
||||
PredicateValue::Bool(value) => vec![Token::Boolean(value.to_string())],
|
||||
PredicateValue::Null {} => vec![Token::Keyword("null".to_string())],
|
||||
PredicateValue::Null => vec![Token::Keyword("null".to_string())],
|
||||
PredicateValue::Hex(value) => vec![Token::String(value.to_string())],
|
||||
PredicateValue::Base64(value) => value.tokenize(),
|
||||
PredicateValue::Expression(value) => value.tokenize(),
|
||||
@ -816,7 +816,7 @@ impl Tokenizable for JsonValue {
|
||||
}
|
||||
tokens.push(Token::CodeDelimiter("}".to_string()));
|
||||
}
|
||||
JsonValue::Null {} => {
|
||||
JsonValue::Null => {
|
||||
tokens.push(Token::Keyword("null".to_string()));
|
||||
}
|
||||
JsonValue::Expression(exp) => {
|
||||
@ -918,7 +918,7 @@ impl Tokenizable for VariableDefinition {
|
||||
impl Tokenizable for VariableValue {
|
||||
fn tokenize(&self) -> Vec<Token> {
|
||||
match self {
|
||||
VariableValue::Null { .. } => vec![Token::Keyword("null".to_string())],
|
||||
VariableValue::Null => vec![Token::Keyword("null".to_string())],
|
||||
VariableValue::Bool(v) => vec![Token::Boolean(v.to_string())],
|
||||
VariableValue::Integer(v) => vec![Token::Number(v.to_string())],
|
||||
VariableValue::Float(v) => vec![Token::Number(v.to_string())],
|
||||
|
@ -25,7 +25,7 @@ pub struct Error {
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum LinterError {
|
||||
UnnecessarySpace {},
|
||||
UnnecessaryJsonEncoding {},
|
||||
OneSpace {},
|
||||
UnnecessarySpace,
|
||||
UnnecessaryJsonEncoding,
|
||||
OneSpace,
|
||||
}
|
||||
|
@ -32,17 +32,17 @@ impl Error for linter::Error {
|
||||
|
||||
fn description(&self) -> String {
|
||||
match self.inner {
|
||||
LinterError::UnnecessarySpace { .. } => "Unnecessary space".to_string(),
|
||||
LinterError::UnnecessaryJsonEncoding {} => "Unnecessary json encoding".to_string(),
|
||||
LinterError::OneSpace {} => "One space ".to_string(),
|
||||
LinterError::UnnecessarySpace => "Unnecessary space".to_string(),
|
||||
LinterError::UnnecessaryJsonEncoding => "Unnecessary json encoding".to_string(),
|
||||
LinterError::OneSpace => "One space ".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn fixme(&self) -> String {
|
||||
match self.inner {
|
||||
LinterError::UnnecessarySpace { .. } => "Remove space".to_string(),
|
||||
LinterError::UnnecessaryJsonEncoding {} => "Use Simple String".to_string(),
|
||||
LinterError::OneSpace {} => "Use only one space".to_string(),
|
||||
LinterError::UnnecessarySpace => "Remove space".to_string(),
|
||||
LinterError::UnnecessaryJsonEncoding => "Use Simple String".to_string(),
|
||||
LinterError::OneSpace => "Use only one space".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,13 +53,13 @@ fn check_request(request: &Request) -> Vec<Error> {
|
||||
if !request.space0.value.is_empty() {
|
||||
errors.push(Error {
|
||||
source_info: request.space0.source_info.clone(),
|
||||
inner: LinterError::UnnecessarySpace {},
|
||||
inner: LinterError::UnnecessarySpace,
|
||||
});
|
||||
}
|
||||
if request.space1.value != " " {
|
||||
errors.push(Error {
|
||||
source_info: request.space1.source_info.clone(),
|
||||
inner: LinterError::OneSpace {},
|
||||
inner: LinterError::OneSpace,
|
||||
});
|
||||
}
|
||||
for error in check_line_terminator(&request.line_terminator0) {
|
||||
@ -101,7 +101,7 @@ fn check_response(response: &Response) -> Vec<Error> {
|
||||
if !response.space0.value.is_empty() {
|
||||
errors.push(Error {
|
||||
source_info: response.space0.source_info.clone(),
|
||||
inner: LinterError::UnnecessarySpace {},
|
||||
inner: LinterError::UnnecessarySpace,
|
||||
});
|
||||
}
|
||||
errors
|
||||
@ -232,8 +232,8 @@ fn lint_query(query: &Query) -> Query {
|
||||
|
||||
fn lint_query_value(query_value: &QueryValue) -> QueryValue {
|
||||
match query_value {
|
||||
QueryValue::Status {} => QueryValue::Status {},
|
||||
QueryValue::Url {} => QueryValue::Url {},
|
||||
QueryValue::Status => QueryValue::Status,
|
||||
QueryValue::Url => QueryValue::Url,
|
||||
QueryValue::Header { name, .. } => QueryValue::Header {
|
||||
name: name.clone(),
|
||||
space0: one_whitespace(),
|
||||
@ -251,7 +251,7 @@ fn lint_query_value(query_value: &QueryValue) -> QueryValue {
|
||||
},
|
||||
}
|
||||
}
|
||||
QueryValue::Body {} => QueryValue::Body {},
|
||||
QueryValue::Body => QueryValue::Body,
|
||||
QueryValue::Xpath { expr, .. } => QueryValue::Xpath {
|
||||
expr: expr.clone(),
|
||||
space0: one_whitespace(),
|
||||
@ -268,10 +268,10 @@ fn lint_query_value(query_value: &QueryValue) -> QueryValue {
|
||||
name: name.clone(),
|
||||
space0: one_whitespace(),
|
||||
},
|
||||
QueryValue::Duration {} => QueryValue::Duration {},
|
||||
QueryValue::Bytes {} => QueryValue::Bytes {},
|
||||
QueryValue::Sha256 {} => QueryValue::Sha256 {},
|
||||
QueryValue::Md5 {} => QueryValue::Md5 {},
|
||||
QueryValue::Duration => QueryValue::Duration,
|
||||
QueryValue::Bytes => QueryValue::Bytes,
|
||||
QueryValue::Sha256 => QueryValue::Sha256,
|
||||
QueryValue::Md5 => QueryValue::Md5,
|
||||
QueryValue::Certificate {
|
||||
attribute_name: field,
|
||||
..
|
||||
@ -388,14 +388,14 @@ fn lint_predicate_func_value(predicate_func_value: &PredicateFuncValue) -> Predi
|
||||
space0: one_whitespace(),
|
||||
value: lint_predicate_value(value),
|
||||
},
|
||||
PredicateFuncValue::IsInteger {} => PredicateFuncValue::IsInteger {},
|
||||
PredicateFuncValue::IsFloat {} => PredicateFuncValue::IsFloat {},
|
||||
PredicateFuncValue::IsBoolean {} => PredicateFuncValue::IsBoolean {},
|
||||
PredicateFuncValue::IsString {} => PredicateFuncValue::IsString {},
|
||||
PredicateFuncValue::IsCollection {} => PredicateFuncValue::IsCollection {},
|
||||
PredicateFuncValue::IsDate {} => PredicateFuncValue::IsDate {},
|
||||
PredicateFuncValue::Exist {} => PredicateFuncValue::Exist {},
|
||||
PredicateFuncValue::IsEmpty {} => PredicateFuncValue::IsEmpty {},
|
||||
PredicateFuncValue::IsInteger => PredicateFuncValue::IsInteger,
|
||||
PredicateFuncValue::IsFloat => PredicateFuncValue::IsFloat,
|
||||
PredicateFuncValue::IsBoolean => PredicateFuncValue::IsBoolean,
|
||||
PredicateFuncValue::IsString => PredicateFuncValue::IsString,
|
||||
PredicateFuncValue::IsCollection => PredicateFuncValue::IsCollection,
|
||||
PredicateFuncValue::IsDate => PredicateFuncValue::IsDate,
|
||||
PredicateFuncValue::Exist => PredicateFuncValue::Exist,
|
||||
PredicateFuncValue::IsEmpty => PredicateFuncValue::IsEmpty,
|
||||
}
|
||||
}
|
||||
|
||||
@ -408,7 +408,7 @@ fn lint_predicate_value(predicate_value: &PredicateValue) -> PredicateValue {
|
||||
PredicateValue::Integer(value) => PredicateValue::Integer(*value),
|
||||
PredicateValue::Float(value) => PredicateValue::Float(value.clone()),
|
||||
PredicateValue::Bool(value) => PredicateValue::Bool(*value),
|
||||
PredicateValue::Null {} => PredicateValue::Null {},
|
||||
PredicateValue::Null => PredicateValue::Null,
|
||||
PredicateValue::Hex(value) => PredicateValue::Hex(lint_hex(value)),
|
||||
PredicateValue::Base64(value) => PredicateValue::Base64(lint_base64(value)),
|
||||
PredicateValue::Expression(value) => PredicateValue::Expression(value.clone()),
|
||||
@ -574,7 +574,7 @@ fn check_line_terminator(line_terminator: &LineTerminator) -> Vec<Error> {
|
||||
if !line_terminator.space0.value.is_empty() {
|
||||
errors.push(Error {
|
||||
source_info: line_terminator.space0.source_info.clone(),
|
||||
inner: LinterError::UnnecessarySpace {},
|
||||
inner: LinterError::UnnecessarySpace,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user