mentat/query-algebrizer/tests/type_reqs.rs
Richard Newman e33fe71c47 Rework caching and use it inside the query engine. (#553) r=emily
This puts caching in mentat_db, adds a reverse lookup capability for
unique attributes, and populates bidirectional caches with a single
SQL cursor walk.

Differentiate between begin_read and begin_uncached_read.

Note that we still allow toggling within InProgress, because there might be
transient local state that makes starting a new transaction impossible.
2018-02-21 11:51:45 -08:00

86 lines
2.7 KiB
Rust

// Copyright 2016 Mozilla
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
extern crate mentat_core;
extern crate mentat_query;
extern crate mentat_query_algebrizer;
extern crate mentat_query_parser;
mod utils;
use utils::{
alg,
SchemaBuilder,
bails,
};
use mentat_core::{
Schema,
ValueType,
};
use mentat_query_algebrizer::Known;
fn prepopulated_schema() -> Schema {
SchemaBuilder::new()
.define_simple_attr("test", "boolean", ValueType::Boolean, false)
.define_simple_attr("test", "long", ValueType::Long, false)
.define_simple_attr("test", "double", ValueType::Double, false)
.define_simple_attr("test", "string", ValueType::String, false)
.define_simple_attr("test", "keyword", ValueType::Keyword, false)
.define_simple_attr("test", "uuid", ValueType::Uuid, false)
.define_simple_attr("test", "instant", ValueType::Instant, false)
.define_simple_attr("test", "ref", ValueType::Ref, false)
.schema
}
#[test]
fn test_empty_known() {
let type_names = [
"boolean",
"long",
"double",
"string",
"keyword",
"uuid",
"instant",
"ref",
];
let schema = prepopulated_schema();
let known = Known::for_schema(&schema);
for known_type in type_names.iter() {
for required in type_names.iter() {
let q = format!("[:find ?e :where [?e :test/{} ?v] [({} ?v)]]",
known_type, required);
println!("Query: {}", q);
let cc = alg(known, &q);
// It should only be empty if the known type and our requirement differ.
assert_eq!(cc.empty_because.is_some(), known_type != required,
"known_type = {}; required = {}", known_type, required);
}
}
}
#[test]
fn test_multiple() {
let schema = prepopulated_schema();
let known = Known::for_schema(&schema);
let q = "[:find ?e :where [?e _ ?v] [(long ?v)] [(double ?v)]]";
let cc = alg(known, &q);
assert!(cc.empty_because.is_some());
}
#[test]
fn test_unbound() {
let schema = prepopulated_schema();
let known = Known::for_schema(&schema);
bails(known, "[:find ?e :where [(string ?e)]]");
}