cargo fmt

This commit is contained in:
Guillaume Mourier 2022-10-28 19:10:58 +02:00 committed by Louis Dureuil
parent 0d71c80ba6
commit b297b5deb0
No known key found for this signature in database
3 changed files with 25 additions and 6 deletions

View File

@ -6,7 +6,10 @@ use nom::sequence::{delimited, terminated};
use nom::{InputIter, InputLength, InputTake, Slice}; use nom::{InputIter, InputLength, InputTake, Slice};
use crate::error::{ExpectedValueKind, NomErrorExt}; use crate::error::{ExpectedValueKind, NomErrorExt};
use crate::{parse_geo_point, parse_geo_radius, parse_geo_bounding_box, Error, ErrorKind, IResult, Span, Token}; use crate::{
parse_geo_bounding_box, parse_geo_point, parse_geo_radius, Error, ErrorKind, IResult, Span,
Token,
};
/// This function goes through all characters in the [Span] if it finds any escaped character (`\`). /// This function goes through all characters in the [Span] if it finds any escaped character (`\`).
/// It generates a new string with all `\` removed from the [Span]. /// It generates a new string with all `\` removed from the [Span].
@ -91,7 +94,9 @@ pub fn parse_value(input: Span) -> IResult<Token> {
} }
} }
match parse_geo_radius(input) { match parse_geo_radius(input) {
Ok(_) => return Err(nom::Err::Failure(Error::new_from_kind(input, ErrorKind::MisusedGeoRadius))), Ok(_) => {
return Err(nom::Err::Failure(Error::new_from_kind(input, ErrorKind::MisusedGeoRadius)))
}
// if we encountered a failure it means the user badly wrote a _geoRadius filter. // if we encountered a failure it means the user badly wrote a _geoRadius filter.
// But instead of showing him how to fix his syntax we are going to tell him he should not use this filter as a value. // But instead of showing him how to fix his syntax we are going to tell him he should not use this filter as a value.
Err(e) if e.is_failure() => { Err(e) if e.is_failure() => {
@ -101,11 +106,19 @@ pub fn parse_value(input: Span) -> IResult<Token> {
} }
match parse_geo_bounding_box(input) { match parse_geo_bounding_box(input) {
Ok(_) => return Err(nom::Err::Failure(Error::new_from_kind(input, ErrorKind::MisusedGeoBoundingBox))), Ok(_) => {
return Err(nom::Err::Failure(Error::new_from_kind(
input,
ErrorKind::MisusedGeoBoundingBox,
)))
}
// if we encountered a failure it means the user badly wrote a _geoBoundingBox filter. // if we encountered a failure it means the user badly wrote a _geoBoundingBox filter.
// But instead of showing him how to fix his syntax we are going to tell him he should not use this filter as a value. // But instead of showing him how to fix his syntax we are going to tell him he should not use this filter as a value.
Err(e) if e.is_failure() => { Err(e) if e.is_failure() => {
return Err(nom::Err::Failure(Error::new_from_kind(input, ErrorKind::MisusedGeoBoundingBox))) return Err(nom::Err::Failure(Error::new_from_kind(
input,
ErrorKind::MisusedGeoBoundingBox,
)))
} }
_ => (), _ => (),
} }

View File

@ -92,7 +92,10 @@ impl FromStr for Member {
Ok(Member::Geo([lat, lng])) Ok(Member::Geo([lat, lng]))
} }
None => { None => {
if is_reserved_keyword(text) || text.starts_with("_geoRadius(") || text.starts_with("_geoBoundingBox(") { if is_reserved_keyword(text)
|| text.starts_with("_geoRadius(")
|| text.starts_with("_geoBoundingBox(")
{
return Err(AscDescError::ReservedKeyword { name: text.to_string() })?; return Err(AscDescError::ReservedKeyword { name: text.to_string() })?;
} }
Ok(Member::Field(text.to_string())) Ok(Member::Field(text.to_string()))

View File

@ -160,7 +160,10 @@ mod tests {
("_geoRadius:asc", ReservedNameForFilter { name: S("_geoRadius") }), ("_geoRadius:asc", ReservedNameForFilter { name: S("_geoRadius") }),
("_geoRadius(42, 75, 59):asc", ReservedNameForFilter { name: S("_geoRadius") }), ("_geoRadius(42, 75, 59):asc", ReservedNameForFilter { name: S("_geoRadius") }),
("_geoBoundingBox:asc", ReservedNameForFilter { name: S("_geoBoundingBox") }), ("_geoBoundingBox:asc", ReservedNameForFilter { name: S("_geoBoundingBox") }),
("_geoBoundingBox((42, 75), (75, 59)):asc", ReservedNameForFilter { name: S("_geoBoundingBox") }), (
"_geoBoundingBox((42, 75), (75, 59)):asc",
ReservedNameForFilter { name: S("_geoBoundingBox") },
),
]; ];
for (input, expected) in invalid_criteria { for (input, expected) in invalid_criteria {