update tests to properly reflect answer order.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rusty-wam"
|
name = "rusty-wam"
|
||||||
version = "0.7.4"
|
version = "0.7.5"
|
||||||
authors = ["Mark Thom"]
|
authors = ["Mark Thom"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -346,8 +346,8 @@ impl QueryTerm {
|
|||||||
match self {
|
match self {
|
||||||
&QueryTerm::Arg(_) => 3,
|
&QueryTerm::Arg(_) => 3,
|
||||||
&QueryTerm::Catch(_) => 3,
|
&QueryTerm::Catch(_) => 3,
|
||||||
&QueryTerm::Throw(_) => 1,
|
|
||||||
&QueryTerm::Display(_) => 1,
|
&QueryTerm::Display(_) => 1,
|
||||||
|
&QueryTerm::Throw(_) => 1,
|
||||||
&QueryTerm::DuplicateTerm(_) => 2,
|
&QueryTerm::DuplicateTerm(_) => 2,
|
||||||
&QueryTerm::Functor(_) => 3,
|
&QueryTerm::Functor(_) => 3,
|
||||||
&QueryTerm::Inlined(ref term) => term.arity(),
|
&QueryTerm::Inlined(ref term) => term.arity(),
|
||||||
@@ -384,8 +384,8 @@ impl<'a> ClauseType<'a> {
|
|||||||
&ClauseType::Arg => "arg",
|
&ClauseType::Arg => "arg",
|
||||||
&ClauseType::CallN => "call",
|
&ClauseType::CallN => "call",
|
||||||
&ClauseType::Catch => "catch",
|
&ClauseType::Catch => "catch",
|
||||||
&ClauseType::Deep(_, _, name, _) => name.as_str(),
|
|
||||||
&ClauseType::Display => "display",
|
&ClauseType::Display => "display",
|
||||||
|
&ClauseType::Deep(_, _, name, _) => name.as_str(),
|
||||||
&ClauseType::DuplicateTerm => "duplicate_term",
|
&ClauseType::DuplicateTerm => "duplicate_term",
|
||||||
&ClauseType::Functor => "functor",
|
&ClauseType::Functor => "functor",
|
||||||
&ClauseType::Is => "is",
|
&ClauseType::Is => "is",
|
||||||
@@ -765,9 +765,9 @@ pub enum ControlInstruction {
|
|||||||
CallN(usize), // arity.
|
CallN(usize), // arity.
|
||||||
CatchCall,
|
CatchCall,
|
||||||
CatchExecute,
|
CatchExecute,
|
||||||
Deallocate,
|
|
||||||
DisplayCall,
|
DisplayCall,
|
||||||
DisplayExecute,
|
DisplayExecute,
|
||||||
|
Deallocate,
|
||||||
DuplicateTermCall,
|
DuplicateTermCall,
|
||||||
DuplicateTermExecute,
|
DuplicateTermExecute,
|
||||||
Execute(TabledRc<Atom>, usize),
|
Execute(TabledRc<Atom>, usize),
|
||||||
|
|||||||
@@ -578,12 +578,8 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
|
|||||||
code
|
code
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_query_line(&mut self,
|
fn compile_query_line(&mut self, term: &'a QueryTerm, term_loc: GenContext,
|
||||||
term: &'a QueryTerm,
|
code: &mut Code, index: usize, is_exposed: bool)
|
||||||
term_loc: GenContext,
|
|
||||||
code: &mut Code,
|
|
||||||
index: usize,
|
|
||||||
is_exposed: bool)
|
|
||||||
{
|
{
|
||||||
self.marker.reset_arg(term.arity());
|
self.marker.reset_arg(term.arity());
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ impl<'a> VariableFixtures<'a>
|
|||||||
// 1. move the use sets of each variable to a local HashMap, use_set
|
// 1. move the use sets of each variable to a local HashMap, use_set
|
||||||
// (iterate mutably, swap mutable refs).
|
// (iterate mutably, swap mutable refs).
|
||||||
// 2. drain use_set. For each use set of U, add into the
|
// 2. drain use_set. For each use set of U, add into the
|
||||||
// no-use sets of appropriate variables T /= U.
|
// no-use sets of appropriate variables T =/= U.
|
||||||
// 3. Move the use sets back to their original locations in the fixture.
|
// 3. Move the use sets back to their original locations in the fixture.
|
||||||
// Compute the conflict set of u.
|
// Compute the conflict set of u.
|
||||||
|
|
||||||
|
|||||||
@@ -112,9 +112,9 @@ impl fmt::Display for ControlInstruction {
|
|||||||
&ControlInstruction::CatchExecute =>
|
&ControlInstruction::CatchExecute =>
|
||||||
write!(f, "execute_catch"),
|
write!(f, "execute_catch"),
|
||||||
&ControlInstruction::DisplayCall =>
|
&ControlInstruction::DisplayCall =>
|
||||||
write!(f, "call_display"),
|
write!(f, "display_call"),
|
||||||
&ControlInstruction::DisplayExecute =>
|
&ControlInstruction::DisplayExecute =>
|
||||||
write!(f, "execute_display"),
|
write!(f, "display_execute"),
|
||||||
&ControlInstruction::DuplicateTermCall =>
|
&ControlInstruction::DuplicateTermCall =>
|
||||||
write!(f, "call_duplicate_term"),
|
write!(f, "call_duplicate_term"),
|
||||||
&ControlInstruction::DuplicateTermExecute =>
|
&ControlInstruction::DuplicateTermExecute =>
|
||||||
|
|||||||
@@ -40,10 +40,6 @@ impl<'a> QueryIterator<'a> {
|
|||||||
let state = TermIterState::Clause(0, ClauseType::Catch, terms);
|
let state = TermIterState::Clause(0, ClauseType::Catch, terms);
|
||||||
QueryIterator { state_stack: vec![state] }
|
QueryIterator { state_stack: vec![state] }
|
||||||
},
|
},
|
||||||
&QueryTerm::Display(ref terms) => {
|
|
||||||
let state = TermIterState::Clause(0, ClauseType::Display, terms);
|
|
||||||
QueryIterator { state_stack: vec![state] }
|
|
||||||
},
|
|
||||||
&QueryTerm::DuplicateTerm(ref terms) => {
|
&QueryTerm::DuplicateTerm(ref terms) => {
|
||||||
let state = TermIterState::Clause(0, ClauseType::DuplicateTerm, terms);
|
let state = TermIterState::Clause(0, ClauseType::DuplicateTerm, terms);
|
||||||
QueryIterator { state_stack: vec![state] }
|
QueryIterator { state_stack: vec![state] }
|
||||||
@@ -56,6 +52,10 @@ impl<'a> QueryIterator<'a> {
|
|||||||
let state = TermIterState::Clause(0, ClauseType::Functor, terms);
|
let state = TermIterState::Clause(0, ClauseType::Functor, terms);
|
||||||
QueryIterator { state_stack: vec![state] }
|
QueryIterator { state_stack: vec![state] }
|
||||||
},
|
},
|
||||||
|
&QueryTerm::Display(ref terms) => {
|
||||||
|
let state = TermIterState::Clause(0, ClauseType::Display, terms);
|
||||||
|
QueryIterator { state_stack: vec![state] }
|
||||||
|
},
|
||||||
&QueryTerm::Inlined(InlinedQueryTerm::CompareNumber(_, ref terms))
|
&QueryTerm::Inlined(InlinedQueryTerm::CompareNumber(_, ref terms))
|
||||||
| &QueryTerm::Is(ref terms) => {
|
| &QueryTerm::Is(ref terms) => {
|
||||||
let state = TermIterState::Clause(0, ClauseType::Is, terms);
|
let state = TermIterState::Clause(0, ClauseType::Is, terms);
|
||||||
|
|||||||
Submodule src/prolog/parser updated: 87d3b043bb...aa164cabe6
@@ -6,65 +6,76 @@ use prolog::machine::*;
|
|||||||
use prolog::parser::toplevel::*;
|
use prolog::parser::toplevel::*;
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
use std::mem::swap;
|
||||||
|
|
||||||
pub struct TestOutputter {
|
pub struct TestOutputter {
|
||||||
contents: Vec<String>
|
results: Vec<HashSet<String>>,
|
||||||
|
contents: HashSet<String>,
|
||||||
|
focus: String
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TestOutputter {
|
||||||
|
fn cache(&mut self) {
|
||||||
|
self.begin_new_var();
|
||||||
|
|
||||||
|
let mut contents = HashSet::new();
|
||||||
|
swap(&mut contents, &mut self.contents);
|
||||||
|
|
||||||
|
self.results.push(contents);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HeapCellValueOutputter for TestOutputter {
|
impl HeapCellValueOutputter for TestOutputter {
|
||||||
type Output = HashSet<String>;
|
type Output = Vec<HashSet<String>>;
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
TestOutputter { contents: vec![] }
|
TestOutputter { results: vec![],
|
||||||
|
contents: HashSet::new(),
|
||||||
|
focus: String::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn append(&mut self, contents: &str) {
|
fn append(&mut self, focus: &str) {
|
||||||
if let Some(ref mut result) = self.contents.last_mut() {
|
self.focus += focus;
|
||||||
**result += contents;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn begin_new_var(&mut self) {
|
fn begin_new_var(&mut self) {
|
||||||
self.contents.push(String::new());
|
if !self.focus.is_empty() {
|
||||||
|
let mut focus = String::new();
|
||||||
|
swap(&mut focus, &mut self.focus);
|
||||||
|
|
||||||
|
self.contents.insert(focus);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn result(self) -> Self::Output {
|
fn result(self) -> Self::Output {
|
||||||
self.contents.into_iter().collect()
|
self.results
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ends_with(&self, s: &str) -> bool {
|
fn ends_with(&self, s: &str) -> bool {
|
||||||
if let Some(ref result) = self.contents.last() {
|
self.focus.ends_with(s)
|
||||||
result.ends_with(s)
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn len(&self) -> usize {
|
fn len(&self) -> usize {
|
||||||
if let Some(ref result) = self.contents.last() {
|
self.focus.len()
|
||||||
result.len()
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn truncate(&mut self, len: usize) {
|
fn truncate(&mut self, len: usize) {
|
||||||
if let Some(ref mut result) = self.contents.last_mut() {
|
self.focus.truncate(len);
|
||||||
result.truncate(len);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect_test_output<'a>(wam: &mut Machine, alloc_locs: AllocVarDict<'a>,
|
pub fn collect_test_output<'a>(wam: &mut Machine, alloc_locs: AllocVarDict<'a>,
|
||||||
mut heap_locs: HeapVarDict<'a>)
|
mut heap_locs: HeapVarDict<'a>)
|
||||||
-> HashSet<String>
|
-> Vec<HashSet<String>>
|
||||||
{
|
{
|
||||||
let mut output = TestOutputter::new();
|
let mut output = TestOutputter::new();
|
||||||
output = wam.heap_view(&heap_locs, output);
|
output = wam.heap_view(&heap_locs, output);
|
||||||
|
output.cache();
|
||||||
|
|
||||||
while let EvalSession::SubsequentQuerySuccess = wam.continue_query(&alloc_locs, &mut heap_locs)
|
while let EvalSession::SubsequentQuerySuccess = wam.continue_query(&alloc_locs, &mut heap_locs)
|
||||||
{
|
{
|
||||||
output = wam.heap_view(&heap_locs, output);
|
output = wam.heap_view(&heap_locs, output);
|
||||||
|
output.cache();
|
||||||
}
|
}
|
||||||
|
|
||||||
output.result()
|
output.result()
|
||||||
@@ -72,10 +83,11 @@ pub fn collect_test_output<'a>(wam: &mut Machine, alloc_locs: AllocVarDict<'a>,
|
|||||||
|
|
||||||
pub fn collect_test_output_with_limit<'a>(wam: &mut Machine, alloc_locs: AllocVarDict<'a>,
|
pub fn collect_test_output_with_limit<'a>(wam: &mut Machine, alloc_locs: AllocVarDict<'a>,
|
||||||
mut heap_locs: HeapVarDict<'a>, limit: usize)
|
mut heap_locs: HeapVarDict<'a>, limit: usize)
|
||||||
-> HashSet<String>
|
-> Vec<HashSet<String>>
|
||||||
{
|
{
|
||||||
let mut output = TestOutputter::new();
|
let mut output = TestOutputter::new();
|
||||||
output = wam.heap_view(&heap_locs, output);
|
output = wam.heap_view(&heap_locs, output);
|
||||||
|
output.cache();
|
||||||
|
|
||||||
let mut count = 1;
|
let mut count = 1;
|
||||||
|
|
||||||
@@ -86,6 +98,7 @@ pub fn collect_test_output_with_limit<'a>(wam: &mut Machine, alloc_locs: AllocVa
|
|||||||
while let EvalSession::SubsequentQuerySuccess = wam.continue_query(&alloc_locs, &mut heap_locs)
|
while let EvalSession::SubsequentQuerySuccess = wam.continue_query(&alloc_locs, &mut heap_locs)
|
||||||
{
|
{
|
||||||
output = wam.heap_view(&heap_locs, output);
|
output = wam.heap_view(&heap_locs, output);
|
||||||
|
output.cache();
|
||||||
|
|
||||||
count += 1;
|
count += 1;
|
||||||
|
|
||||||
@@ -116,7 +129,7 @@ pub fn submit(wam: &mut Machine, buffer: &str) -> bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn submit_query(wam: &mut Machine, buffer: &str, result: HashSet<String>) -> bool
|
pub fn submit_query(wam: &mut Machine, buffer: &str, result: Vec<HashSet<String>>) -> bool
|
||||||
{
|
{
|
||||||
wam.reset();
|
wam.reset();
|
||||||
|
|
||||||
@@ -134,7 +147,7 @@ pub fn submit_query(wam: &mut Machine, buffer: &str, result: HashSet<String>) ->
|
|||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn submit_query_with_limit(wam: &mut Machine, buffer: &str,
|
pub fn submit_query_with_limit(wam: &mut Machine, buffer: &str,
|
||||||
result: HashSet<String>, limit: usize)
|
result: Vec<HashSet<String>>, limit: usize)
|
||||||
-> bool
|
-> bool
|
||||||
{
|
{
|
||||||
wam.reset();
|
wam.reset();
|
||||||
@@ -161,8 +174,8 @@ macro_rules! expand_strs {
|
|||||||
|
|
||||||
#[allow(unused_macros)]
|
#[allow(unused_macros)]
|
||||||
macro_rules! assert_prolog_success_with_limit {
|
macro_rules! assert_prolog_success_with_limit {
|
||||||
($wam:expr, $buf:expr, $res:expr, $limit:expr) => (
|
($wam:expr, $buf:expr, [$($res:expr),*], $limit:expr) => (
|
||||||
assert!(submit_query_with_limit($wam, $buf, expand_strs!($res), $limit))
|
assert!(submit_query_with_limit($wam, $buf, vec![$(expand_strs!($res)),*], $limit))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,8 +188,8 @@ macro_rules! assert_prolog_failure {
|
|||||||
|
|
||||||
#[allow(unused_macros)]
|
#[allow(unused_macros)]
|
||||||
macro_rules! assert_prolog_success {
|
macro_rules! assert_prolog_success {
|
||||||
($wam:expr, $query:expr, $res:expr) => (
|
($wam:expr, $query:expr, [$($res:expr),*]) => (
|
||||||
assert!(submit_query($wam, $query, expand_strs!($res)))
|
assert!(submit_query($wam, $query, vec![$(expand_strs!($res)),*]))
|
||||||
);
|
);
|
||||||
($wam:expr, $buf:expr) => (
|
($wam:expr, $buf:expr) => (
|
||||||
assert_eq!(submit($wam, $buf), true)
|
assert_eq!(submit($wam, $buf), true)
|
||||||
|
|||||||
1041
src/tests.rs
1041
src/tests.rs
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user