From d2761c6bf61c19c25465aea946473b18e45a0cb6 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 17 Oct 2022 03:13:10 +0100 Subject: [PATCH] Ensure `RELATE` statements parse correctly with parameters Closes #1313 --- lib/src/sql/param.rs | 6 ++++++ lib/src/sql/statements/relate.rs | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/src/sql/param.rs b/lib/src/sql/param.rs index 6b601cb5..cc90e62e 100644 --- a/lib/src/sql/param.rs +++ b/lib/src/sql/param.rs @@ -86,6 +86,12 @@ pub fn param(i: &str) -> IResult<&str, Param> { Ok((i, Param::from(v))) } +pub fn basic(i: &str) -> IResult<&str, Param> { + let (i, _) = char('$')(i)?; + let (i, v) = idiom::basic(i)?; + Ok((i, Param::from(v))) +} + #[cfg(test)] mod tests { diff --git a/lib/src/sql/statements/relate.rs b/lib/src/sql/statements/relate.rs index 6a0f582d..2564a35b 100644 --- a/lib/src/sql/statements/relate.rs +++ b/lib/src/sql/statements/relate.rs @@ -12,7 +12,7 @@ use crate::sql::comment::shouldbespace; use crate::sql::data::{data, Data}; use crate::sql::error::IResult; use crate::sql::output::{output, Output}; -use crate::sql::param::param; +use crate::sql::param::basic as param; use crate::sql::subquery::subquery; use crate::sql::table::{table, Table}; use crate::sql::thing::thing; @@ -271,7 +271,7 @@ mod tests { #[test] fn relate_statement_in() { - let sql = "RELATE person:tobie->like->animal:koala"; + let sql = "RELATE animal:koala<-like<-person:tobie"; let res = relate(sql); assert!(res.is_ok()); let out = res.unwrap().1; @@ -280,10 +280,19 @@ mod tests { #[test] fn relate_statement_out() { - let sql = "RELATE animal:koala<-like<-person:tobie"; + let sql = "RELATE person:tobie->like->animal:koala"; let res = relate(sql); assert!(res.is_ok()); let out = res.unwrap().1; assert_eq!("RELATE person:tobie -> like -> animal:koala", format!("{}", out)) } + + #[test] + fn relate_statement_params() { + let sql = "RELATE $tobie->like->$koala"; + let res = relate(sql); + assert!(res.is_ok()); + let out = res.unwrap().1; + assert_eq!("RELATE $tobie -> like -> $koala", format!("{}", out)) + } }