Skip to content

Commit

Permalink
additional test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgerlag committed Jul 17, 2024
1 parent 3780f5e commit 163b710
Show file tree
Hide file tree
Showing 4 changed files with 369 additions and 200 deletions.
10 changes: 7 additions & 3 deletions core/src/evaluation/expressions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use async_recursion::async_recursion;
use chrono::{
Datelike, Duration, FixedOffset, NaiveDate, NaiveDateTime, NaiveTime, Timelike, Weekday,
};
use drasi_query_ast::ast::{self, ParentExpression};
use drasi_query_ast::ast;

use crate::evaluation::temporal_constants;
use crate::evaluation::variable_value::duration::Duration as DurationStruct;
Expand All @@ -21,7 +21,7 @@ use crate::interface::{ResultKey, ResultOwner};
use crate::{evaluation::variable_value::VariableValue, interface::ResultIndex};

use super::{
context::{ExpressionEvaluationContext, QueryVariables, SideEffects},
context::{ExpressionEvaluationContext, SideEffects},
functions::{aggregation::Accumulator, Function, FunctionRegistry},
EvaluationError,
};
Expand Down Expand Up @@ -1631,14 +1631,18 @@ impl ExpressionEvaluator {
.await?;
match items {
VariableValue::List(items) => {
let mut result = VariableValue::Null;
let mut result = match context.get_variable(accumulator_variable.clone()) {
Some(value) => value.clone(),
None => VariableValue::Null,
};
let mut variables = context.clone_variables();
for item in items {
if let Some(filter) = &expression.filter {
variables
.insert(expression.item_identifier.to_string().into(), item.clone());
let local_context =
ExpressionEvaluationContext::new(&variables, context.get_clock());

if !self.evaluate_predicate(&local_context, filter).await? {
continue;
}
Expand Down
25 changes: 25 additions & 0 deletions core/src/evaluation/expressions/tests/list_construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,31 @@ async fn test_list_comprehension_property_with_mapping_only() {
);
}

#[tokio::test]
async fn test_list_comprehension_property_with_mapping_only_non_numeric() {
let expr = "[x IN ['foo', 'bar'] | x + 'baz']";

let expr = drasi_query_cypher::parse_expression(expr).unwrap();
let function_registry = Arc::new(FunctionRegistry::new());
let ari = Arc::new(InMemoryResultIndex::new());
let evaluator = ExpressionEvaluator::new(function_registry.clone(), ari.clone());

let variables = QueryVariables::new();
let context =
ExpressionEvaluationContext::new(&variables, Arc::new(InstantQueryClock::new(0, 0)));

assert_eq!(
evaluator
.evaluate_expression(&context, &expr)
.await
.unwrap(),
VariableValue::List(vec![
VariableValue::String(String::from("foobaz")),
VariableValue::String(String::from("barbaz")),
])
);
}

#[tokio::test]
async fn test_list_comprehension_property() {
let expr = "[x IN [123,342,12,34,-12] where x > 0| x - 10]"; //for each element in param1, return the value property
Expand Down
Loading

0 comments on commit 163b710

Please sign in to comment.