From db25013b10e91d04bbaf4f7db6fe6f14e37f287b Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 12 Jun 2015 17:54:45 +0200 Subject: [PATCH] added test cases --- UnitTests/Makefile.unittests | 1 + js/server/tests/aql-attribute-access.js | 140 ++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 js/server/tests/aql-attribute-access.js diff --git a/UnitTests/Makefile.unittests b/UnitTests/Makefile.unittests index 63a6dd2ecc..84a6cb2690 100755 --- a/UnitTests/Makefile.unittests +++ b/UnitTests/Makefile.unittests @@ -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 \ diff --git a/js/server/tests/aql-attribute-access.js b/js/server/tests/aql-attribute-access.js new file mode 100644 index 0000000000..19dd8caf30 --- /dev/null +++ b/js/server/tests/aql-attribute-access.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: