mirror of https://gitee.com/bigwinds/arangodb
added tests
This commit is contained in:
parent
ba783a4584
commit
ef1f56c42c
|
@ -47,6 +47,8 @@ var ArangoError = arangodb.ArangoError;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var getStorage = function () {
|
||||
"use strict";
|
||||
|
||||
var functions = db._collection("_aqlfunctions");
|
||||
|
||||
if (functions === null) {
|
||||
|
@ -65,6 +67,8 @@ var getStorage = function () {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var getFiltered = function (group) {
|
||||
"use strict";
|
||||
|
||||
var result = [ ];
|
||||
|
||||
if (group !== null && group !== undefined && group.length > 0) {
|
||||
|
@ -92,6 +96,8 @@ var getFiltered = function (group) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var validateName = function (name) {
|
||||
"use strict";
|
||||
|
||||
if (typeof name !== 'string' ||
|
||||
! name.match(/^[a-zA-Z0-9_]+(::[a-zA-Z0-9_]+)+$/) ||
|
||||
name.substr(0, 1) === "_") {
|
||||
|
@ -108,12 +114,14 @@ var validateName = function (name) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var stringifyFunction = function (code, name) {
|
||||
"use strict";
|
||||
|
||||
if (typeof code === 'function') {
|
||||
code = String(code);
|
||||
code = String(code) + "\n";
|
||||
}
|
||||
|
||||
if (typeof code === 'string') {
|
||||
code = "(" + code + ")";
|
||||
code = "(\n" + code + "\n)";
|
||||
|
||||
if (! internal.parse) {
|
||||
// no parsing possible. assume always valid
|
||||
|
@ -164,6 +172,8 @@ var stringifyFunction = function (code, name) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var unregisterFunction = function (name) {
|
||||
"use strict";
|
||||
|
||||
var func = null;
|
||||
|
||||
validateName(name);
|
||||
|
@ -210,6 +220,8 @@ var unregisterFunction = function (name) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var unregisterFunctionsGroup = function (group) {
|
||||
"use strict";
|
||||
|
||||
if (group.length === 0) {
|
||||
var err = new ArangoError();
|
||||
err.errorNum = arangodb.errors.ERROR_BAD_PARAMETER.code;
|
||||
|
@ -364,10 +376,12 @@ var registerFunction = function (name, code, isDeterministic) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var toArrayFunctions = function (group) {
|
||||
"use strict";
|
||||
|
||||
var result = [ ];
|
||||
|
||||
getFiltered(group).forEach(function (f) {
|
||||
result.push({ name: f.name, code: f.code.substr(1, f.code.length - 2) });
|
||||
result.push({ name: f.name, code: f.code.substr(1, f.code.length - 2).trim() });
|
||||
});
|
||||
|
||||
return result;
|
||||
|
|
|
@ -493,6 +493,36 @@ function AqlFunctionsSuite () {
|
|||
assertEqual([ [ true, false, null, 1, 2, -4, [ 5.5, { a: 1, "b": "def" } ] ] ], actual);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief register a function and run a query
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testQueryStringWithComments : function () {
|
||||
unregister("UnitTests::tryme");
|
||||
aqlfunctions.register("UnitTests::tryme", function (what) { return true; }, true);
|
||||
|
||||
var actual = db._createStatement({ query: "// foo\n /* bar\nbaz\n*/ RETURN UnitTests::tryme(4) // some comment" }).execute().toArray();
|
||||
assertEqual([ true ], actual);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief register a function and run a query
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testQueryFuncWithComments : function () {
|
||||
unregister("UnitTests::tryme");
|
||||
aqlfunctions.register("UnitTests::tryme", function (what) {
|
||||
// foo
|
||||
/* bar
|
||||
baz
|
||||
*/
|
||||
return [ true, false, null, 1, 2, -4, [ 5.5, { a: 1, "b": "def" } ] ] // some comment
|
||||
}, true);
|
||||
|
||||
var actual = db._createStatement({ query: "RETURN UnitTests::tryme()" }).execute().toArray();
|
||||
assertEqual([ [ true, false, null, 1, 2, -4, [ 5.5, { a: 1, "b": "def" } ] ] ], actual);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test for specific problem with docs returned by user functions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue