Change DIFF clause to PATCH

This commit is contained in:
Tobie Morgan Hitchcock 2022-01-21 13:23:28 +00:00
parent adff751a7e
commit f30b953e19

View file

@ -17,7 +17,7 @@ use std::fmt;
pub enum Data { pub enum Data {
EmptyExpression, EmptyExpression,
SetExpression(Vec<(Idiom, Operator, Value)>), SetExpression(Vec<(Idiom, Operator, Value)>),
DiffExpression(Array), PatchExpression(Array),
MergeExpression(Object), MergeExpression(Object),
ReplaceExpression(Object), ReplaceExpression(Object),
ContentExpression(Object), ContentExpression(Object),
@ -44,7 +44,7 @@ impl fmt::Display for Data {
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", ") .join(", ")
), ),
Data::DiffExpression(v) => write!(f, "DIFF {}", v), Data::PatchExpression(v) => write!(f, "PATCH {}", v),
Data::MergeExpression(v) => write!(f, "MERGE {}", v), Data::MergeExpression(v) => write!(f, "MERGE {}", v),
Data::ReplaceExpression(v) => write!(f, "REPLACE {}", v), Data::ReplaceExpression(v) => write!(f, "REPLACE {}", v),
Data::ContentExpression(v) => write!(f, "CONTENT {}", v), Data::ContentExpression(v) => write!(f, "CONTENT {}", v),
@ -79,7 +79,7 @@ impl fmt::Display for Data {
} }
pub fn data(i: &str) -> IResult<&str, Data> { pub fn data(i: &str) -> IResult<&str, Data> {
alt((set, diff, merge, replace, content))(i) alt((set, patch, merge, replace, content))(i)
} }
fn set(i: &str) -> IResult<&str, Data> { fn set(i: &str) -> IResult<&str, Data> {
@ -96,11 +96,11 @@ fn set(i: &str) -> IResult<&str, Data> {
Ok((i, Data::SetExpression(v))) Ok((i, Data::SetExpression(v)))
} }
fn diff(i: &str) -> IResult<&str, Data> { fn patch(i: &str) -> IResult<&str, Data> {
let (i, _) = tag_no_case("DIFF")(i)?; let (i, _) = tag_no_case("PATCH")(i)?;
let (i, _) = shouldbespace(i)?; let (i, _) = shouldbespace(i)?;
let (i, v) = array(i)?; let (i, v) = array(i)?;
Ok((i, Data::DiffExpression(v))) Ok((i, Data::PatchExpression(v)))
} }
fn merge(i: &str) -> IResult<&str, Data> { fn merge(i: &str) -> IResult<&str, Data> {
@ -191,12 +191,12 @@ mod tests {
} }
#[test] #[test]
fn diff_statement() { fn patch_statement() {
let sql = "DIFF [{ field: true }]"; let sql = "PATCH [{ field: true }]";
let res = data(sql); let res = patch(sql);
assert!(res.is_ok()); assert!(res.is_ok());
let out = res.unwrap().1; let out = res.unwrap().1;
assert_eq!("DIFF [{ field: true }]", format!("{}", out)); assert_eq!("PATCH [{ field: true }]", format!("{}", out));
} }
#[test] #[test]