neo4j-contrib / sql2cypher

Experimental SQL to Cypher Transpiler using jooq and cypher-dsl
Apache License 2.0
26 stars 1 forks source link

Make test suite whitespace insensitive #24

Closed lukaseder closed 1 year ago

lukaseder commented 1 year ago

Not sure what you folk's thought are here, @jexp, @michael-simons, but I think it would be useful if the test suite wasn't whitespace sensitive. For example, I've added this test here: https://github.com/neo4j-contrib/sql2cypher/commit/b7b6925d88b91e70d3a257a61ea851b7c0befa71

=== `CASE` searched

The input

[source,sql,id=t7_1,name=select_with_string_functions]
----
SELECT
    CASE WHEN 1 = 2 THEN 3 END,
    CASE WHEN 1 = 2 THEN 3 ELSE 4 END,
    CASE WHEN 1 = 2 THEN 3 WHEN 4 = 5 THEN 6 END,
    CASE WHEN 1 = 2 THEN 3 WHEN 4 = 5 THEN 6 ELSE 7 END
----

will be transpiled to

[source,cypher,id=t7_1_expected]
----
RETURN CASE WHEN 1 = 2 THEN 3 END, CASE WHEN 1 = 2 THEN 3 ELSE 4 END, CASE WHEN 1 = 2 THEN 3 WHEN 4 = 5 THEN 6 END, CASE WHEN 1 = 2 THEN 3 WHEN 4 = 5 THEN 6 ELSE 7 END
----

I started formatting the input SQL, because the jOOQ parser doesn't care about it, and no assertion is run validating the input. However, the output has to be formatted exactly as it is, on a single line. Would be nice if we could focus on semantics only, in these tests, assuming that formatting tests are already implemented in Cypher DSL?

I.e. this should work as output:

----
RETURN
    CASE WHEN 1 = 2 THEN 3 END, 
    CASE WHEN 1 = 2 THEN 3 ELSE 4 END, 
    CASE WHEN 1 = 2 THEN 3 WHEN 4 = 5 THEN 6 END, 
    CASE WHEN 1 = 2 THEN 3 WHEN 4 = 5 THEN 6 ELSE 7 END
----

The simplest implementation would just replace "\\s+" by " " prior to asserting equality, but that would also replace things in string literals. Perhaps you have other ideas?

jexp commented 1 year ago

Perhaps we can parse the expected results with cypher-dsl and then format in the same style as the transpiler is configured?

lukaseder commented 1 year ago

Yes indeed, that would be more robust, and adds coverage to the cypher-dsl parser. Though it also assumes that the cypher-dsl supports all the features...