From 1170bbbff92074f0cdf26a6ef97bfd997dc1f049 Mon Sep 17 00:00:00 2001 From: Ashleyhx Date: Thu, 21 Dec 2023 16:47:26 -0500 Subject: [PATCH] tests for Map --- test/test_files/tck/expressions/map/Map1.test | 150 ++++++++++++++++ test/test_files/tck/expressions/map/Map2.test | 165 ++++++++++++++++++ test/test_files/tck/expressions/map/Map3.test | 100 +++++++++++ 3 files changed, 415 insertions(+) create mode 100644 test/test_files/tck/expressions/map/Map1.test create mode 100644 test/test_files/tck/expressions/map/Map2.test create mode 100644 test/test_files/tck/expressions/map/Map3.test diff --git a/test/test_files/tck/expressions/map/Map1.test b/test/test_files/tck/expressions/map/Map1.test new file mode 100644 index 00000000000..989484b2952 --- /dev/null +++ b/test/test_files/tck/expressions/map/Map1.test @@ -0,0 +1,150 @@ +-GROUP TCKMap1 +-DATASET CSV tck + +-- + + +# Statically access a field of a non-null map +-CASE Scenario1 +-STATEMENT WITH {existing: 42, notMissing: null} AS m + RETURN m.notMissing, m.existing; +## Outcome: the result should be, in any order: +---- 1 +|42 + +# Statically access a field of a null map +-CASE Scenario2 +-SKIP +-STATEMENT WITH null AS m + RETURN m.missing; +## Outcome: the result should be, in any order: +---- 1 +null + +# Statically access a field of a map resulting from an expression +-CASE Scenario3 +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +-STATEMENT WITH [{existing: 42, notMissing: null}, {existing: 42, notMissing: null}] AS list + RETURN (list[1]).notMissing, (list[1]).existing; +## Outcome: the result should be, in any order: +---- 1 +|42 + +# Statically access a field is case-sensitive +-CASE Scenario4 +-STATEMENT WITH {name: 'Mats', nome: 'Pontus'} AS map + RETURN map.name AS result; +## Outcome: the result should be, in any order: +---- 1 +Mats + +-STATEMENT WITH {name: 'Mats', Name: 'Pontus'} AS map + RETURN map.name AS result; +## Outcome: the result should be, in any order: +---- 1 +Mats + + +-STATEMENT WITH {name: 'Mats', Name: 'Pontus'} AS map + RETURN map.nAMe AS result; +## Outcome: the result should be, in any order: +---- 1 +Mats + +-CASE Scenario4_error +-SKIP +-STATEMENT WITH {name: 'Mats', Name: 'Pontus'} AS map + RETURN map.Name AS result; +## Outcome: the result should be, in any order: +---- 1 +Pontus + +-STATEMENT WITH {name: 'Mats', Name: 'Pontus'} AS map + RETURN map.nAMe AS result; +## Outcome: the result should be, in any order: +---- 1 + + +# Statically access a field with a delimited identifier +-CASE Scenario5 +-SKIP +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +-STATEMENT WITH {name: 'Mats', nome: 'Pontus'} AS map + RETURN map.`name` AS result; +## Outcome: the result should be, in any order: +---- 1 +Mats + +-STATEMENT WITH {name: 'Mats', nome: 'Pontus'} AS map + RETURN map.`nome` AS result; +## Outcome: the result should be, in any order: +---- 1 +Pontus + +-STATEMENT WITH {name: 'Mats', nome: 'Pontus'} AS map + RETURN map.`Mats` AS result; +## Outcome: the result should be, in any order: +---- 1 +null + +-STATEMENT WITH {name: 'Mats', nome: 'Pontus'} AS map + RETURN map.`null` AS result; +## Outcome: the result should be, in any order: +---- 1 +null + +-STATEMENT WITH {null: 'Mats', NULL: 'Pontus'} AS map + RETURN map.`null` AS result; +## Outcome: the result should be, in any order: +---- 1 +Mats + +-STATEMENT WITH {null: 'Mats', NULL: 'Pontus'} AS map + RETURN map.NULL` AS result; +## Outcome: the result should be, in any order: +---- 1 +Pontus + +# Fail when performing property access on a non-map +-CASE Scenario6 +-STATEMENT WITH 123 AS nonMap + RETURN nonMap.num; +## Outcome: an Error should be raised at compile time: InvalidArgumentType +---- error +Binder exception: nonMap has data type INT64 but (NODE,REL,STRUCT) was expected. + +-STATEMENT WITH 42.45 AS nonMap + RETURN nonMap.num; +## Outcome: an Error should be raised at compile time: InvalidArgumentType +---- error +Binder exception: nonMap has data type DOUBLE but (NODE,REL,STRUCT) was expected. + +-STATEMENT WITH True AS nonMap + RETURN nonMap.num; +## Outcome: an Error should be raised at compile time: InvalidArgumentType +---- error +Binder exception: nonMap has data type BOOL but (NODE,REL,STRUCT) was expected. + +-STATEMENT WITH False AS nonMap + RETURN nonMap.num; +## Outcome: an Error should be raised at compile time: InvalidArgumentType +---- error +Binder exception: nonMap has data type BOOL but (NODE,REL,STRUCT) was expected. + +-STATEMENT WITH 'string' AS nonMap + RETURN nonMap.num; +## Outcome: an Error should be raised at compile time: InvalidArgumentType +---- error +Binder exception: nonMap has data type STRING but (NODE,REL,STRUCT) was expected. + +-STATEMENT WITH [123, True] AS nonMap + RETURN nonMap.num; +## Outcome: an Error should be raised at compile time: InvalidArgumentType +---- error +Binder exception: Cannot bind LIST_CREATION with parameter type INT64 and BOOL. diff --git a/test/test_files/tck/expressions/map/Map2.test b/test/test_files/tck/expressions/map/Map2.test new file mode 100644 index 00000000000..eea4e3df282 --- /dev/null +++ b/test/test_files/tck/expressions/map/Map2.test @@ -0,0 +1,165 @@ +-GROUP TCKMap2 +-DATASET CSV tck + +-- + + +# Dynamically access a field based on parameters when there is no type information +-CASE Scenario1 +-SKIP +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +## Context: parameters are: +#parameters are: +#expr|{name: 'Apa'} +#idx|'name' +-STATEMENT WITH $expr AS expr, $idx AS idx + RETURN expr[idx] AS value; +## Outcome: the result should be, in any order: +---- 1 +Apa + +# Dynamically access a field based on parameters when there is rhs type information +-CASE Scenario2 +-SKIP +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +## Context: parameters are: +#parameters are: +#expr|{name: 'Apa'} +#idx|'name' +-STATEMENT WITH $expr AS expr, $idx AS idx + RETURN expr[toString(idx)] AS value; +## Outcome: the result should be, in any order: +---- 1 +Apa + +# Dynamically access a field on null results in null +-CASE Scenario3 +-SKIP +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +-STATEMENT WITH null AS expr, 'x' AS idx + RETURN expr[idx] AS value; +## Outcome: the result should be, in any order: +---- 1 +null + +# Dynamically access a field with null results in null +-CASE Scenario4 +-SKIP +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +-STATEMENT WITH map(['name'], ['Mats']) AS expr, null AS idx + RETURN expr[idx] AS value; +## Outcome: the result should be, in any order: +---- 1 +null + +# Dynamically access a field is case-sensitive +-CASE Scenario5 +-SKIP +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +-STATEMENT WITH map(['name', 'nome'], ['Mats', 'Pontus']) AS map + RETURN map['name'] AS result; +## Outcome: the result should be, in any order: +---- 1 +Mats + +-STATEMENT WITH map(['name', 'Name'], ['Mats', 'Pontus']) AS map + RETURN map['name'] AS result; +## Outcome: the result should be, in any order: +---- 1 +Mats + +-STATEMENT WITH {name: 'Mats', Name: 'Pontus'} AS map + RETURN map['Name'] AS result; +## Outcome: the result should be, in any order: +---- 1 +Pontus + +-STATEMENT WITH {name: 'Mats', Name: 'Pontus'} AS map + RETURN map['nAMe'] AS result; +## Outcome: the result should be, in any order: +---- 1 +null + +-STATEMENT WITH {name: 'Mats', nome: 'Pontus'} AS map + RETURN map['null'] AS result; +## Outcome: the result should be, in any order: +---- 1 +null + +-STATEMENT WITH {null: 'Mats', NULL: 'Pontus'} AS map + RETURN map['null'] AS result; +## Outcome: the result should be, in any order: +---- 1 +Mats + +-STATEMENT WITH {null: 'Mats', NULL: 'Pontus'} AS map + RETURN map['NULL'] AS result; +## Outcome: the result should be, in any order: +---- 1 +Pontus + +# Fail at runtime when attempting to index with an Int into a Map +-CASE Scenario6 +-SKIP +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +## Context: parameters are: +#parameters are: +#expr|{name: 'Apa'} +#idx|0 +-STATEMENT WITH $expr AS expr, $idx AS idx + RETURN expr[idx]; +## Outcome: an Error should be raised at runtime: MapElementAccessByNonString +---- error +1 + +# Fail at runtime when trying to index into a map with a non-string +-CASE Scenario13 +-SKIP +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +## Context: parameters are: +#parameters are: +#expr|{name: 'Apa'} +#idx|12.3 +-STATEMENT WITH $expr AS expr, $idx AS idx + RETURN expr[idx]; +## Outcome: a TypeError should be raised at runtime: MapElementAccessByNonString +---- error +TypeError: Map element access by non-string + +# Fail at runtime when trying to index something which is not a map +-CASE Scenario7 +-SKIP +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +## Context: parameters are: +#parameters are: +#expr|100 +#idx|0 +-STATEMENT WITH $expr AS expr, $idx AS idx + RETURN expr[idx]; +## Outcome: an Error should be raised at any time: InvalidArgumentType +---- error +Invalid argument type diff --git a/test/test_files/tck/expressions/map/Map3.test b/test/test_files/tck/expressions/map/Map3.test new file mode 100644 index 00000000000..fb6cb2ca653 --- /dev/null +++ b/test/test_files/tck/expressions/map/Map3.test @@ -0,0 +1,100 @@ +-GROUP TCKMap3 +-DATASET CSV tck + +-- + + +# Using `keys()` on a literal map +-CASE Scenario1 +-SKIP +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +-STATEMENT RETURN map_keys( +map(['Alice','age', 'address'], + ['Alice', 38, map(['city', 'residential'], ['London', True])])) AS k; +## Outcome: the result should be (ignoring element order for lists): +---- 1 +['name', 'age', 'address'] + +# Using `keys()` on a parameter map +-CASE Scenario2 +-SKIP +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +## Context: parameters are: +#parameters are: +#param|{name: 'Alice', age: 38, address: {city: 'London', residential: true}} +-STATEMENT RETURN ($param) AS k; +## Outcome: the result should be (ignoring element order for lists): +---- 1 +['address', 'name', 'age'] + +# Using `keys()` on null map +-CASE Scenario3 +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +-STATEMENT WITH map([],[]) AS m + RETURN map_keys(m), map_keys(map([],[])); +## Outcome: the result should be, in any order: +---- 1 +[]|[] + +# Using `keys()` on map with null values +-CASE Scenario4 +## VERIFY + +-STATEMENT RETURN map_keys(map([], [])) AS keys; +## Outcome: the result should be (ignoring element order for lists): +---- 1 +[] + +-STATEMENT RETURN map_keys(map(['k'], [1])) AS keys; +## Outcome: the result should be (ignoring element order for lists): +---- 1 +[k] + +-STATEMENT RETURN map_keys(map(['k'], [null])) AS keys; +## Outcome: the result should be (ignoring element order for lists): +---- 1 +[k] + +-STATEMENT RETURN map_keys(map(['k', 'l'], [null, 1])) AS keys; +## Outcome: the result should be (ignoring element order for lists): +---- 1 +[k,l] + +-STATEMENT RETURN map_keys(map(['k', 'l'], [1, null])) AS keys; +## Outcome: the result should be (ignoring element order for lists): +---- 1 +[k,l] + +-STATEMENT RETURN map_keys(map(['k', 'l'], [null, null])) AS keys; +## Outcome: the result should be (ignoring element order for lists): +---- 1 +[k,l] + +-STATEMENT RETURN map_keys(map(['k', 'l', 'm'], [1, null, 1])) AS keys; +## Outcome: the result should be (ignoring element order for lists): +---- 1 +[k,l,m] + +# Using `keys()` and `IN` to check field existence +-CASE Scenario5 +-SKIP +## VERIFY +-STATEMENT CREATE NODE TABLE A(ID SERIAL, name STRING, PRIMARY KEY(ID)); +---- ok +## Context: any graph +-STATEMENT WITH {exists: 42, notMissing: null} AS map + RETURN 'exists' IN keys(map) AS a, + 'notMissing' IN keys(map) AS b, + 'missing' IN keys(map) AS c; +## Outcome: the result should be, in any order: +---- 1 +True|True|False