1
0
Fork 0

documentation for ternary operator shortcut

This commit is contained in:
jsteemann 2017-01-30 17:27:13 +01:00
parent ec1e05975f
commit 2c431ea9f1
2 changed files with 31 additions and 1 deletions

View File

@ -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.

View File

@ -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);
},
};
}