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,65 +160,6 @@ impl<I> FindSp<I>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! assert_parses_to {
|
|
||||||
( $parser: path, $input: expr, $expected: expr ) => {{
|
|
||||||
let mut par = $parser();
|
|
||||||
let result = par.parse(&$input[..]);
|
|
||||||
assert_eq!(result, Ok(($expected, &[][..])));
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_find_sp_variable() {
|
|
||||||
let sym = edn::PlainSymbol::new("?x");
|
|
||||||
let input = [edn::Value::PlainSymbol(sym.clone())];
|
|
||||||
assert_parses_to!(FindSp::variable, input, Variable(sym));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_find_scalar() {
|
|
||||||
let sym = edn::PlainSymbol::new("?x");
|
|
||||||
let period = edn::PlainSymbol::new(".");
|
|
||||||
let input = [edn::Value::PlainSymbol(sym.clone()), edn::Value::PlainSymbol(period.clone())];
|
|
||||||
assert_parses_to!(FindSp::find_scalar,
|
|
||||||
input,
|
|
||||||
FindSpec::FindScalar(Element::Variable(Variable(sym))));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_find_coll() {
|
|
||||||
let sym = edn::PlainSymbol::new("?x");
|
|
||||||
let period = edn::PlainSymbol::new("...");
|
|
||||||
let input = [edn::Value::Vector(vec![edn::Value::PlainSymbol(sym.clone()),
|
|
||||||
edn::Value::PlainSymbol(period.clone())])];
|
|
||||||
assert_parses_to!(FindSp::find_coll,
|
|
||||||
input,
|
|
||||||
FindSpec::FindColl(Element::Variable(Variable(sym))));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_find_rel() {
|
|
||||||
let vx = edn::PlainSymbol::new("?x");
|
|
||||||
let vy = edn::PlainSymbol::new("?y");
|
|
||||||
let input = [edn::Value::PlainSymbol(vx.clone()), edn::Value::PlainSymbol(vy.clone())];
|
|
||||||
assert_parses_to!(FindSp::find_rel,
|
|
||||||
input,
|
|
||||||
FindSpec::FindRel(vec![Element::Variable(Variable(vx)),
|
|
||||||
Element::Variable(Variable(vy))]));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_find_tuple() {
|
|
||||||
let vx = edn::PlainSymbol::new("?x");
|
|
||||||
let vy = edn::PlainSymbol::new("?y");
|
|
||||||
let input = [edn::Value::Vector(vec![edn::Value::PlainSymbol(vx.clone()),
|
|
||||||
edn::Value::PlainSymbol(vy.clone())])];
|
|
||||||
assert_parses_to!(FindSp::find_tuple,
|
|
||||||
input,
|
|
||||||
FindSpec::FindTuple(vec![Element::Variable(Variable(vx)),
|
|
||||||
Element::Variable(Variable(vy))]));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse a sequence of values into one of four find specs.
|
// 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.
|
// `:find` must be an array of plain var symbols (?foo), pull expressions, and aggregates.
|
||||||
|
@ -238,8 +179,78 @@ pub fn find_seq_to_find_spec(find: &[edn::Value]) -> FindParseResult {
|
||||||
.map_err(|_| FindParseError::Err)
|
.map_err(|_| FindParseError::Err)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn test_find_processing() {
|
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 {
|
||||||
|
( $parser: path, $input: expr, $expected: expr ) => {{
|
||||||
|
let mut par = $parser();
|
||||||
|
let result = par.parse(&$input[..]);
|
||||||
|
assert_eq!(result, Ok(($expected, &[][..])));
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_find_sp_variable() {
|
||||||
|
let sym = edn::PlainSymbol::new("?x");
|
||||||
|
let input = [edn::Value::PlainSymbol(sym.clone())];
|
||||||
|
assert_parses_to!(FindSp::variable, input, Variable(sym));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_find_scalar() {
|
||||||
|
let sym = edn::PlainSymbol::new("?x");
|
||||||
|
let period = edn::PlainSymbol::new(".");
|
||||||
|
let input = [edn::Value::PlainSymbol(sym.clone()), edn::Value::PlainSymbol(period.clone())];
|
||||||
|
assert_parses_to!(FindSp::find_scalar,
|
||||||
|
input,
|
||||||
|
FindSpec::FindScalar(Element::Variable(Variable(sym))));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_find_coll() {
|
||||||
|
let sym = edn::PlainSymbol::new("?x");
|
||||||
|
let period = edn::PlainSymbol::new("...");
|
||||||
|
let input = [edn::Value::Vector(vec![edn::Value::PlainSymbol(sym.clone()),
|
||||||
|
edn::Value::PlainSymbol(period.clone())])];
|
||||||
|
assert_parses_to!(FindSp::find_coll,
|
||||||
|
input,
|
||||||
|
FindSpec::FindColl(Element::Variable(Variable(sym))));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_find_rel() {
|
||||||
|
let vx = edn::PlainSymbol::new("?x");
|
||||||
|
let vy = edn::PlainSymbol::new("?y");
|
||||||
|
let input = [edn::Value::PlainSymbol(vx.clone()), edn::Value::PlainSymbol(vy.clone())];
|
||||||
|
assert_parses_to!(FindSp::find_rel,
|
||||||
|
input,
|
||||||
|
FindSpec::FindRel(vec![Element::Variable(Variable(vx)),
|
||||||
|
Element::Variable(Variable(vy))]));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_find_tuple() {
|
||||||
|
let vx = edn::PlainSymbol::new("?x");
|
||||||
|
let vy = edn::PlainSymbol::new("?y");
|
||||||
|
let input = [edn::Value::Vector(vec![edn::Value::PlainSymbol(vx.clone()),
|
||||||
|
edn::Value::PlainSymbol(vy.clone())])];
|
||||||
|
assert_parses_to!(FindSp::find_tuple,
|
||||||
|
input,
|
||||||
|
FindSpec::FindTuple(vec![Element::Variable(Variable(vx)),
|
||||||
|
Element::Variable(Variable(vy))]));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_find_processing() {
|
||||||
let vx = edn::PlainSymbol::new("?x");
|
let vx = edn::PlainSymbol::new("?x");
|
||||||
let vy = edn::PlainSymbol::new("?y");
|
let vy = edn::PlainSymbol::new("?y");
|
||||||
let ellipsis = edn::PlainSymbol::new("...");
|
let ellipsis = edn::PlainSymbol::new("...");
|
||||||
|
@ -262,4 +273,5 @@ fn test_find_processing() {
|
||||||
assert_eq!(Ok(FindSpec::FindRel(vec![Element::Variable(Variable(vx.clone())),
|
assert_eq!(Ok(FindSpec::FindRel(vec![Element::Variable(Variable(vx.clone())),
|
||||||
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