Move query-parser test functions into a submodule.
This commit is contained in:
parent
932a42866c
commit
f1a55c9f12
1 changed files with 93 additions and 81 deletions
|
@ -160,6 +160,36 @@ impl<I> FindSp<I>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse a sequence of values into one of four find specs.
|
||||||
|
//
|
||||||
|
// `:find` must be an array of plain var symbols (?foo), pull expressions, and aggregates.
|
||||||
|
// For now we only support variables and the annotations necessary to declare which
|
||||||
|
// flavor of :find we want:
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// `?x ?y ?z ` = FindRel
|
||||||
|
// `[?x ...] ` = FindColl
|
||||||
|
// `?x . ` = FindScalar
|
||||||
|
// `[?x ?y ?z]` = FindTuple
|
||||||
|
//
|
||||||
|
pub fn find_seq_to_find_spec(find: &[edn::Value]) -> FindParseResult {
|
||||||
|
FindSp::find()
|
||||||
|
.parse(find)
|
||||||
|
.map(|x| x.0)
|
||||||
|
.map_err(|_| FindParseError::Err)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
extern crate combine;
|
||||||
|
extern crate edn;
|
||||||
|
extern crate mentat_query;
|
||||||
|
|
||||||
|
use self::combine::Parser;
|
||||||
|
use self::mentat_query::{Element, FindSpec, Variable};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
macro_rules! assert_parses_to {
|
macro_rules! assert_parses_to {
|
||||||
( $parser: path, $input: expr, $expected: expr ) => {{
|
( $parser: path, $input: expr, $expected: expr ) => {{
|
||||||
let mut par = $parser();
|
let mut par = $parser();
|
||||||
|
@ -219,25 +249,6 @@ fn test_find_tuple() {
|
||||||
Element::Variable(Variable(vy))]));
|
Element::Variable(Variable(vy))]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse a sequence of values into one of four find specs.
|
|
||||||
//
|
|
||||||
// `:find` must be an array of plain var symbols (?foo), pull expressions, and aggregates.
|
|
||||||
// For now we only support variables and the annotations necessary to declare which
|
|
||||||
// flavor of :find we want:
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// `?x ?y ?z ` = FindRel
|
|
||||||
// `[?x ...] ` = FindColl
|
|
||||||
// `?x . ` = FindScalar
|
|
||||||
// `[?x ?y ?z]` = FindTuple
|
|
||||||
//
|
|
||||||
pub fn find_seq_to_find_spec(find: &[edn::Value]) -> FindParseResult {
|
|
||||||
FindSp::find()
|
|
||||||
.parse(find)
|
|
||||||
.map(|x| x.0)
|
|
||||||
.map_err(|_| FindParseError::Err)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_find_processing() {
|
fn test_find_processing() {
|
||||||
let vx = edn::PlainSymbol::new("?x");
|
let vx = edn::PlainSymbol::new("?x");
|
||||||
|
@ -263,3 +274,4 @@ fn test_find_processing() {
|
||||||
Element::Variable(Variable(vy.clone()))])),
|
Element::Variable(Variable(vy.clone()))])),
|
||||||
find_seq_to_find_spec(&rel));
|
find_seq_to_find_spec(&rel));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue