Skip to content

Commit

Permalink
Refactor Regression Tests for CASE statement (#1268)
Browse files Browse the repository at this point in the history
Added some new cases to CASE statement regression tests to capture
cases that were not tested for before.

Refactored existing test cases to improve readability
  • Loading branch information
dehowef authored Oct 16, 2023
1 parent 8d4f513 commit 1846a14
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 21 deletions.
72 changes: 57 additions & 15 deletions regress/expected/expr.out
Original file line number Diff line number Diff line change
Expand Up @@ -6352,32 +6352,22 @@ NOTICE: graph "case_statement" has been created

(1 row)

SELECT * FROM cypher('case_statement', $$CREATE ({i: 1, j: null})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 1, i: 1, j: null})-[:connected_to {id: 1, k:0}]->({id: 2, i: 'a', j: 'b'})$$) AS (result agtype);
result
--------
(0 rows)

SELECT * FROM cypher('case_statement', $$CREATE ({i: 'a', j: 'b'})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 3, i: 0, j: 1})-[:connected_to {id: 2, k:1}]->({id: 4, i: true, j: false})$$) AS (result agtype);
result
--------
(0 rows)

SELECT * FROM cypher('case_statement', $$CREATE ({i: 0, j: 1})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 5, i: [], j: [0,1,2]})$$) AS (result agtype);
result
--------
(0 rows)

SELECT * FROM cypher('case_statement', $$CREATE ({i: true, j: false})$$) AS (result agtype);
result
--------
(0 rows)

SELECT * FROM cypher('case_statement', $$CREATE ({i: [], j: [0,1,2]})$$) AS (result agtype);
result
--------
(0 rows)

SELECT * FROM cypher('case_statement', $$CREATE ({i: {}, j: {i:1}})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 6, i: {}, j: {i:1}})$$) AS (result agtype);
result
--------
(0 rows)
Expand Down Expand Up @@ -6462,6 +6452,57 @@ $$ ) AS (j agtype, case_statement agtype);
{"i": 1} | {"i": 1}
(6 rows)

--CASE agtype_vertex WHEN value THEN result END
SELECT * FROM cypher('case_statement', $$
MATCH (n)
RETURN CASE n
WHEN null THEN 'should not return me'
WHEN 'agtype_string' THEN 'wrong'
WHEN n THEN n
ELSE 'no n'
END
$$ ) AS (case_statement agtype);
case_statement
------------------------------------------------------------------------------------------------
{"id": 281474976710657, "label": "", "properties": {"i": 1, "id": 1}}::vertex
{"id": 281474976710658, "label": "", "properties": {"i": "a", "j": "b", "id": 2}}::vertex
{"id": 281474976710659, "label": "", "properties": {"i": 0, "j": 1, "id": 3}}::vertex
{"id": 281474976710660, "label": "", "properties": {"i": true, "j": false, "id": 4}}::vertex
{"id": 281474976710661, "label": "", "properties": {"i": [], "j": [0, 1, 2], "id": 5}}::vertex
{"id": 281474976710662, "label": "", "properties": {"i": {}, "j": {"i": 1}, "id": 6}}::vertex
(6 rows)

--CASE with match and edges
SELECT * FROM cypher('case_statement', $$
MATCH (n)-[e]->(m)
RETURN CASE
WHEN null THEN 'should not return me'
WHEN n.i = 1 THEN n
WHEN n.i = 0 THEN m
ELSE 'none'
END
$$ ) AS (case_statement agtype);
case_statement
----------------------------------------------------------------------------------------------
{"id": 281474976710657, "label": "", "properties": {"i": 1, "id": 1}}::vertex
{"id": 281474976710660, "label": "", "properties": {"i": true, "j": false, "id": 4}}::vertex
(2 rows)

SELECT * FROM cypher('case_statement', $$
MATCH (n)-[e]->(m)
RETURN CASE
WHEN null THEN 'should not return me'
WHEN e.k = 1 THEN e
WHEN e.k = 0 THEN e
ELSE 'none'
END
$$ ) AS (case_statement agtype);
case_statement
-------------------------------------------------------------------------------------------------------------------------------------------------
{"id": 844424930131969, "label": "connected_to", "end_id": 281474976710658, "start_id": 281474976710657, "properties": {"k": 0, "id": 1}}::edge
{"id": 844424930131970, "label": "connected_to", "end_id": 281474976710660, "start_id": 281474976710659, "properties": {"k": 1, "id": 2}}::edge
(2 rows)

-- RETURN * and (u)--(v) optional forms
SELECT create_graph('opt_forms');
NOTICE: graph "opt_forms" has been created
Expand Down Expand Up @@ -7281,9 +7322,10 @@ NOTICE: graph "VLE" has been dropped
(1 row)

SELECT * FROM drop_graph('case_statement', true);
NOTICE: drop cascades to 2 other objects
NOTICE: drop cascades to 3 other objects
DETAIL: drop cascades to table case_statement._ag_label_vertex
drop cascades to table case_statement._ag_label_edge
drop cascades to table case_statement.connected_to
NOTICE: graph "case_statement" has been dropped
drop_graph
------------
Expand Down
43 changes: 37 additions & 6 deletions regress/sql/expr.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2637,12 +2637,10 @@ $$) AS (i agtype);

--CASE
SELECT create_graph('case_statement');
SELECT * FROM cypher('case_statement', $$CREATE ({i: 1, j: null})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({i: 'a', j: 'b'})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({i: 0, j: 1})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({i: true, j: false})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({i: [], j: [0,1,2]})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({i: {}, j: {i:1}})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 1, i: 1, j: null})-[:connected_to {id: 1, k:0}]->({id: 2, i: 'a', j: 'b'})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 3, i: 0, j: 1})-[:connected_to {id: 2, k:1}]->({id: 4, i: true, j: false})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 5, i: [], j: [0,1,2]})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 6, i: {}, j: {i:1}})$$) AS (result agtype);

--standalone case & edge cases
--base case
Expand Down Expand Up @@ -2688,6 +2686,39 @@ SELECT * FROM cypher('case_statement', $$
END
$$ ) AS (j agtype, case_statement agtype);

--CASE agtype_vertex WHEN value THEN result END
SELECT * FROM cypher('case_statement', $$
MATCH (n)
RETURN CASE n
WHEN null THEN 'should not return me'
WHEN 'agtype_string' THEN 'wrong'
WHEN n THEN n
ELSE 'no n'
END
$$ ) AS (case_statement agtype);

--CASE with match and edges
SELECT * FROM cypher('case_statement', $$
MATCH (n)-[e]->(m)
RETURN CASE
WHEN null THEN 'should not return me'
WHEN n.i = 1 THEN n
WHEN n.i = 0 THEN m
ELSE 'none'
END
$$ ) AS (case_statement agtype);

SELECT * FROM cypher('case_statement', $$
MATCH (n)-[e]->(m)
RETURN CASE
WHEN null THEN 'should not return me'
WHEN e.k = 1 THEN e
WHEN e.k = 0 THEN e
ELSE 'none'
END
$$ ) AS (case_statement agtype);


-- RETURN * and (u)--(v) optional forms
SELECT create_graph('opt_forms');
SELECT * FROM cypher('opt_forms', $$CREATE ({i:1})-[:KNOWS]->({i:2})<-[:KNOWS]-({i:3})$$)AS (result agtype);
Expand Down

0 comments on commit 1846a14

Please sign in to comment.