mirror of https://gitee.com/bigwinds/arangodb
added test cases
This commit is contained in:
parent
78fd4a767e
commit
db25013b10
|
@ -554,6 +554,7 @@ unittests-shell-server-only:
|
|||
################################################################################
|
||||
|
||||
SHELL_SERVER_AQL = @top_srcdir@/js/server/tests/aql-arithmetic.js \
|
||||
@top_srcdir@/js/server/tests/aql-attribute-access.js \
|
||||
@top_srcdir@/js/server/tests/aql-bind.js \
|
||||
@top_srcdir@/js/server/tests/aql-call-apply.js \
|
||||
@top_srcdir@/js/server/tests/aql-complex.js \
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
/*jshint globalstrict:false, strict:false, maxlen: 700 */
|
||||
/*global assertEqual, AQL_EXECUTE */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tests for query language, attribute accesses
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Jan Steemann
|
||||
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var jsunity = require("jsunity");
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test suite
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function attributeAccessTestSuite () {
|
||||
var values = [
|
||||
{ name: "sir alfred", age: 60, loves: [ "lettuce", "flowers" ] },
|
||||
{ person: { name: "gadgetto", age: 50, loves: "gadgets" } },
|
||||
{ name: "everybody", loves: "sunshine" },
|
||||
{ name: "judge", loves: [ "order", "policing", "weapons" ] },
|
||||
"someone"
|
||||
];
|
||||
|
||||
return {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set up
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
setUp : function () {
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tear down
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
tearDown : function () {
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test non-existing attribute
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testNonExistingAttribute : function () {
|
||||
var result = AQL_EXECUTE("FOR value IN @values RETURN value.broken", { values: values }).json;
|
||||
assertEqual([ null, null, null, null, null ], result);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test partially existing attribute
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testPartiallyExistingAttribute : function () {
|
||||
var result = AQL_EXECUTE("FOR value IN @values RETURN value.name", { values: values }).json;
|
||||
assertEqual([ "sir alfred", null, "everybody", "judge", null ], result);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test partially existing sub-attribute
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testPartiallyExistingSubAttribute : function () {
|
||||
var result = AQL_EXECUTE("FOR value IN @values RETURN value.person.name", { values: values }).json;
|
||||
assertEqual([ null, "gadgetto", null, null, null ], result);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test function call result attribute
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testFunctionCallResultAttribute : function () {
|
||||
var result = AQL_EXECUTE("FOR value IN @values RETURN NOOPT(PASSTHRU(value.age))", { values: values }).json;
|
||||
assertEqual([ 60, null, null, null, null ], result);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test function call result sub-attribute
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testFunctionCallResultAttribute1 : function () {
|
||||
var result = AQL_EXECUTE("FOR value IN @values RETURN NOOPT(PASSTHRU(value.person.name))", { values: values }).json;
|
||||
assertEqual([ null, "gadgetto", null, null, null ], result);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test function call result sub-attribute
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testFunctionCallResultAttribute2 : function () {
|
||||
var result = AQL_EXECUTE("FOR value IN @values RETURN NOOPT(PASSTHRU(value).person).name", { values: values }).json;
|
||||
assertEqual([ null, "gadgetto", null, null, null ], result);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test subquery result attribute
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testSubqueryResultAttribute : function () {
|
||||
// won't work (accessing an attribute of an array)
|
||||
var result = AQL_EXECUTE("RETURN (FOR value IN @values RETURN value).name", { values: values }).json;
|
||||
assertEqual([ null ], result);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief executes the test suite
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
jsunity.run(attributeAccessTestSuite);
|
||||
|
||||
return jsunity.done();
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
|
||||
// End:
|
Loading…
Reference in New Issue