Add a test that late inputs aren't allowed in ground.
This commit is contained in:
parent
c2ec1a6bdf
commit
54bdd382fb
2 changed files with 38 additions and 1 deletions
|
@ -159,7 +159,12 @@ impl ConjoiningClauses {
|
||||||
match self.bound_value(&in_var) {
|
match self.bound_value(&in_var) {
|
||||||
// The type is already known if it's a bound variable….
|
// The type is already known if it's a bound variable….
|
||||||
Some(ref in_value) => Ok(Val(in_value.clone())),
|
Some(ref in_value) => Ok(Val(in_value.clone())),
|
||||||
None => bail!(ErrorKind::UnboundVariable((*in_var.0).clone())),
|
None => {
|
||||||
|
// The variable is present in `:in`, but it hasn't yet been provided.
|
||||||
|
// This is a restriction we will eventually relax: we don't yet have a way
|
||||||
|
// to collect variables as part of a computed table or substitution.
|
||||||
|
bail!(ErrorKind::UnboundVariable((*in_var.0).clone()))
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ extern crate mentat_query;
|
||||||
extern crate mentat_query_algebrizer;
|
extern crate mentat_query_algebrizer;
|
||||||
extern crate mentat_query_parser;
|
extern crate mentat_query_parser;
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use mentat_core::{
|
use mentat_core::{
|
||||||
Attribute,
|
Attribute,
|
||||||
Entid,
|
Entid,
|
||||||
|
@ -37,7 +39,9 @@ use mentat_query_algebrizer::{
|
||||||
ComputedTable,
|
ComputedTable,
|
||||||
Error,
|
Error,
|
||||||
ErrorKind,
|
ErrorKind,
|
||||||
|
QueryInputs,
|
||||||
algebrize,
|
algebrize,
|
||||||
|
algebrize_with_inputs,
|
||||||
};
|
};
|
||||||
|
|
||||||
// These are helpers that tests use to build Schema instances.
|
// These are helpers that tests use to build Schema instances.
|
||||||
|
@ -92,6 +96,11 @@ fn bails(schema: &Schema, input: &str) -> Error {
|
||||||
algebrize(schema.into(), parsed).expect_err("algebrize to have failed")
|
algebrize(schema.into(), parsed).expect_err("algebrize to have failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bails_with_inputs(schema: &Schema, input: &str, inputs: QueryInputs) -> Error {
|
||||||
|
let parsed = parse_find_string(input).expect("query input to have parsed");
|
||||||
|
algebrize_with_inputs(schema, parsed, 0, inputs).expect_err("algebrize to have failed")
|
||||||
|
}
|
||||||
|
|
||||||
fn alg(schema: &Schema, input: &str) -> ConjoiningClauses {
|
fn alg(schema: &Schema, input: &str) -> ConjoiningClauses {
|
||||||
let parsed = parse_find_string(input).expect("query input to have parsed");
|
let parsed = parse_find_string(input).expect("query input to have parsed");
|
||||||
algebrize(schema.into(), parsed).expect("algebrizing to have succeeded").cc
|
algebrize(schema.into(), parsed).expect("algebrizing to have succeeded").cc
|
||||||
|
@ -313,3 +322,26 @@ fn test_ground_nonexistent_variable_invalid() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_unbound_input_variable_invalid() {
|
||||||
|
let schema = prepopulated_schema();
|
||||||
|
let q = r#"[:find ?y ?age :in ?x :where [(ground [?x]) [?y ...]] [?y :foo/age ?age]]"#;
|
||||||
|
|
||||||
|
// This fails even if we know the type: we don't support grounding bindings
|
||||||
|
// that aren't known at algebrizing time.
|
||||||
|
let mut types = BTreeMap::default();
|
||||||
|
types.insert(Variable::from_valid_name("?x"), ValueType::Ref);
|
||||||
|
|
||||||
|
let i = QueryInputs::new(types, BTreeMap::default()).expect("valid QueryInputs");
|
||||||
|
|
||||||
|
let e = bails_with_inputs(&schema, &q, i);
|
||||||
|
match e {
|
||||||
|
Error(ErrorKind::UnboundVariable(v), _) => {
|
||||||
|
assert_eq!(v.0, "?x");
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
panic!();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue