Skip to content

Commit

Permalink
Add tests for nested conditional expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
PThorpe92 committed Jan 8, 2025
1 parent fa0e7d5 commit 1837978
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/translate/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ pub fn translate_condition_expr(
match expr {
ast::Expr::Between { .. } => todo!(),
ast::Expr::Binary(lhs, ast::Operator::And, rhs) => {
// We’re in an AND, so short-circuit on false:
// In a binary AND, never jump to the 'jump_target_when_true' label on the first condition, because
// the second condition must also be true.
let _ = translate_condition_expr(
program,
referenced_tables,
Expand All @@ -44,7 +45,6 @@ pub fn translate_condition_expr(
},
resolver,
);
// Then evaluate RHS with the parent's metadata (still AND)
let _ = translate_condition_expr(
program,
referenced_tables,
Expand Down
22 changes: 22 additions & 0 deletions testing/where.test
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,25 @@ do_execsql_test where-between-true-and-2 {
select id from users where id between true and 2;
} {1
2}

do_execsql_test nested-parens-conditionals-or-and-or {
SELECT count(*) FROM users WHERE ((age > 25 OR age < 18) AND (city = 'Boston' OR state = 'MA'));
} {146}

do_execsql_test nested-parens-conditionals-and-or-and {
SELECT * FROM users WHERE (((age > 18 AND city = 'New Mario') OR age = 92) AND city = 'Lake Paul');
} {{9989|Timothy|Harrison|[email protected]|+1-447-830-5123|782 Wright Harbors|Lake Paul|ID|52330|92}}


do_execsql_test nested-parens-conditionals-and-double-or {
SELECT * FROM users WHERE ((age > 30 OR age < 20) AND (state = 'NY' OR state = 'CA')) AND first_name glob 'An*' order by id;
} {{1738|Angelica|Pena|[email protected]|(867)536-1578x039|663 Jacqueline Estate Apt. 652|Clairehaven|NY|64172|74
1811|Andrew|Mckee|[email protected]|359.939.9548|19809 Blair Junction Apt. 438|New Lawrencefort|NY|26240|42
3773|Andrew|Peterson|[email protected]|(405)410-4972x90408|90513 Munoz Radial Apt. 786|Travisfurt|CA|52951|43
3875|Anthony|Cordova|[email protected]|+1-356-999-4070x557|77081 Aguilar Turnpike|Michaelfurt|CA|73353|37
4909|Andrew|Carson|[email protected]|823.423.1516|78514 Luke Springs|Lake Crystal|CA|49481|74
5498|Anna|Hall|[email protected]|9778473725|5803 Taylor Tunnel|New Nicholaston|NY|21825|14
6340|Angela|Freeman|[email protected]|501.372.4720|3912 Ricardo Mission|West Nancyville|NY|60823|34
8171|Andrea|Lee|[email protected]|001-594-430-0646|452 Anthony Stravenue|Sandraville|CA|28572|12
9110|Anthony|Barrett|[email protected]|(562)928-9177x8454|86166 Foster Inlet Apt. 284|North Jeffreyburgh|CA|80147|97
9279|Annette|Lynn|[email protected]|(272)700-7181|2676 Laura Points Apt. 683|Tristanville|NY|48646|91}}

0 comments on commit 1837978

Please sign in to comment.