|
| 1 | +/* |
| 2 | + * Copyright (c) "Neo4j" |
| 3 | + * Neo4j Sweden AB [http://neo4j.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import * as Cypher from "../../src"; |
| 21 | +import { TestClause } from "../../src/utils/TestClause"; |
| 22 | + |
| 23 | +describe("https://github.com/neo4j/cypher-builder/pull/547", () => { |
| 24 | + test("escaped reserved var name IN in case ... then using index", () => { |
| 25 | + const testParam = new Cypher.Param("Hello"); |
| 26 | + const reserveVar = new Cypher.NamedVariable("in"); |
| 27 | + |
| 28 | + const caseClause = new Cypher.Case(testParam).when(reserveVar.index(1)).then(new Cypher.Literal(true)); |
| 29 | + |
| 30 | + const queryResult = new TestClause(caseClause).build(); |
| 31 | + |
| 32 | + expect(queryResult.cypher).toMatchInlineSnapshot(` |
| 33 | +"CASE $param0 |
| 34 | + WHEN \`in\`[1] THEN true |
| 35 | +END" |
| 36 | +`); |
| 37 | + |
| 38 | + expect(queryResult.params).toMatchInlineSnapshot(` |
| 39 | + { |
| 40 | + "param0": "Hello", |
| 41 | + } |
| 42 | + `); |
| 43 | + }); |
| 44 | + |
| 45 | + test("escaped reserved var name IN in case ... then using property", () => { |
| 46 | + const testParam = new Cypher.Param("Hello"); |
| 47 | + const reserveVar = new Cypher.NamedVariable("in"); |
| 48 | + |
| 49 | + const caseClause = new Cypher.Case(testParam).when(reserveVar.property("a")).then(new Cypher.Literal(true)); |
| 50 | + |
| 51 | + const queryResult = new TestClause(caseClause).build(); |
| 52 | + |
| 53 | + expect(queryResult.cypher).toMatchInlineSnapshot(` |
| 54 | +"CASE $param0 |
| 55 | + WHEN \`in\`.a THEN true |
| 56 | +END" |
| 57 | +`); |
| 58 | + |
| 59 | + expect(queryResult.params).toMatchInlineSnapshot(` |
| 60 | + { |
| 61 | + "param0": "Hello", |
| 62 | + } |
| 63 | + `); |
| 64 | + }); |
| 65 | +}); |
0 commit comments