diff --git a/CHANGELOG b/CHANGELOG index af19ea4e13..b5978502c6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,16 @@ devel ----- +* added shortcut for AQL ternary operator + instead of `condition ? true-part : false-part` it is now possible to also use a + shortcut variant `condition ? : false-part`, e.g. + + FOR doc IN docs RETURN doc.value ?: 'not present' + + instead of + + FOR doc IN docs RETURN doc.value ? doc.value : 'not present' + * fixed wrong sorting order in cluster, if an index was used to sort with many shards. diff --git a/js/server/tests/aql/aql-ternary.js b/js/server/tests/aql/aql-ternary.js index a32c922c3e..c9c1cfa556 100644 --- a/js/server/tests/aql/aql-ternary.js +++ b/js/server/tests/aql/aql-ternary.js @@ -221,7 +221,27 @@ function ahuacatlTernaryTestSuite () { assertEqual([ 2 ], getQueryResults("RETURN NOOPT([ ] ? 2 : 3)")); assertEqual([ 2 ], getQueryResults("RETURN NOOPT([ 0 ] ? 2 : 3)")); assertEqual([ 2 ], getQueryResults("RETURN NOOPT({ } ? 2 : 3)")); - } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test ternary operator shortcut +//////////////////////////////////////////////////////////////////////////////// + + testTernaryShortcut : function () { + var expected = [ 'foo', 'foo', 1, 2 ]; + + var actual = getQueryResults("FOR i IN [ null, 0, 1, 2 ] RETURN i ? : 'foo'"); + assertEqual(expected, actual); + + actual = getQueryResults("FOR i IN [ null, 0, 1, 2 ] RETURN i ?: 'foo'"); + assertEqual(expected, actual); + + actual = getQueryResults("FOR i IN [ null, 0, 1, 2 ] RETURN NOOPT(i ? : 'foo')"); + assertEqual(expected, actual); + + actual = getQueryResults("FOR i IN [ null, 0, 1, 2 ] RETURN NOOPT(i ?: 'foo')"); + assertEqual(expected, actual); + }, }; }