|
| 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 Cypher from "../.."; |
| 21 | +import { TestClause } from "../../utils/TestClause"; |
| 22 | + |
| 23 | +describe("ListRange", () => { |
| 24 | + test("get 0 .. 2 from list", () => { |
| 25 | + const list = new Cypher.List([new Cypher.Literal("1"), new Cypher.Literal("2"), new Cypher.Literal("3")]); |
| 26 | + const listIndex = Cypher.listRange(list, 0, 2); |
| 27 | + const queryResult = new TestClause(listIndex).build(); |
| 28 | + |
| 29 | + expect(queryResult.cypher).toMatchInlineSnapshot(`"[\\"1\\", \\"2\\", \\"3\\"][0..2]"`); |
| 30 | + expect(queryResult.params).toMatchInlineSnapshot(`{}`); |
| 31 | + }); |
| 32 | + |
| 33 | + test("get 2 .. -1 from list", () => { |
| 34 | + const list = new Cypher.List([new Cypher.Literal("1"), new Cypher.Literal("2"), new Cypher.Literal("3")]); |
| 35 | + const listIndex = Cypher.listRange(list, 2, -1); |
| 36 | + const queryResult = new TestClause(listIndex).build(); |
| 37 | + |
| 38 | + expect(queryResult.cypher).toMatchInlineSnapshot(`"[\\"1\\", \\"2\\", \\"3\\"][2..-1]"`); |
| 39 | + expect(queryResult.params).toMatchInlineSnapshot(`{}`); |
| 40 | + }); |
| 41 | + |
| 42 | + test("get range from arbitrary expression", () => { |
| 43 | + const collect = Cypher.collect(new Cypher.Variable()); |
| 44 | + const listIndex = Cypher.listRange(collect, 2, 3); |
| 45 | + const queryResult = new TestClause(listIndex).build(); |
| 46 | + |
| 47 | + expect(queryResult.cypher).toMatchInlineSnapshot(`"collect(var0)[2..3]"`); |
| 48 | + expect(queryResult.params).toMatchInlineSnapshot(`{}`); |
| 49 | + }); |
| 50 | +}); |
0 commit comments