From a7b10872e04f614eba0a409220eb28a9006714b3 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Tue, 10 Oct 2017 12:52:50 -0700 Subject: [PATCH] Failing test. --- tests/query.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/query.rs b/tests/query.rs index 6255dc4d..f3a03afd 100644 --- a/tests/query.rs +++ b/tests/query.rs @@ -611,6 +611,34 @@ fn test_simple_aggregation() { [:db/add "d" :foo/age 28] ]"#).unwrap().tempids; + // Count how many vegetarians there are. This is not the same as `count-distinct`. + // Note the distinction between including `:with` and not. + let r = conn.q_once(&mut c, + r#"[:find (count ?veg) + :where + [_ :foo/is-vegetarian ?veg] + [(ground true) ?veg]]"#, None); + match r { + Result::Ok(QueryResults::Rel(vals)) => { + assert_eq!(vals, vec![vec![TypedValue::Long(1)]]); + }, + Result::Ok(r) => panic!("Expected query to work, got {:?}", r), + Result::Err(e) => panic!("Expected query to work, got {:?}", e), + } + + let r = conn.q_once(&mut c, + r#"[:find (count ?veg) . + :with ?person + :where + [?person :foo/is-vegetarian ?veg] + [(ground true) ?veg]]"#, None); + match r { + Result::Ok(QueryResults::Scalar(Some(val))) => { + assert_eq!(val, TypedValue::Long(2)); + }, + _ => panic!("Expected query to work."), + } + // What are the oldest and youngest ages? let r = conn.q_once(&mut c, r#"[:find [(min ?age) (max ?age)]