http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2434a649/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/exports-test.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/exports-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/exports-test.js new file mode 100644 index 0000000..3864a4a --- /dev/null +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/exports-test.js @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/** + * @author Jorge Bay Gondra + */ +'use strict'; + +var assert = require('assert'); +var glvModule = require('../../'); + +describe('API', function () { + it('should export fields under process', function () { + assert.ok(glvModule); + assert.ok(glvModule.process); + assert.strictEqual(typeof glvModule.process.Bytecode, 'function'); + assert.strictEqual(typeof glvModule.process.EnumValue, 'function'); + assert.strictEqual(typeof glvModule.process.P, 'function'); + assert.strictEqual(typeof glvModule.process.Traversal, 'function'); + assert.strictEqual(typeof glvModule.process.TraversalSideEffects, 'function'); + assert.strictEqual(typeof glvModule.process.TraversalStrategies, 'function'); + assert.strictEqual(typeof glvModule.process.TraversalStrategy, 'function'); + assert.strictEqual(typeof glvModule.process.Traverser, 'function'); + assert.strictEqual(typeof glvModule.process.GraphTraversal, 'function'); + assert.strictEqual(typeof glvModule.process.GraphTraversalSource, 'function'); + assert.strictEqual(typeof glvModule.process.barrier, 'object'); + assert.strictEqual(typeof glvModule.process.cardinality, 'object'); + assert.strictEqual(typeof glvModule.process.column, 'object'); + assert.strictEqual(typeof glvModule.process.direction, 'object'); + assert.strictEqual(typeof glvModule.process.direction.both, 'object'); + assert.strictEqual(glvModule.process.direction.both.elementName, 'BOTH'); + assert.strictEqual(typeof glvModule.process.operator, 'object'); + assert.strictEqual(typeof glvModule.process.order, 'object'); + assert.strictEqual(typeof glvModule.process.pop, 'object'); + assert.strictEqual(typeof glvModule.process.scope, 'object'); + assert.strictEqual(typeof glvModule.process.t, 'object'); + assert.ok(glvModule.process.statics); + }); + it('should expose fields under structure', function () { + assert.ok(glvModule.structure); + assert.ok(glvModule.structure.io); + assert.strictEqual(typeof glvModule.structure.io.GraphSONReader, 'function'); + assert.strictEqual(typeof glvModule.structure.io.GraphSONWriter, 'function'); + assert.strictEqual(typeof glvModule.structure.Edge, 'function'); + assert.strictEqual(typeof glvModule.structure.Graph, 'function'); + assert.strictEqual(typeof glvModule.structure.Path, 'function'); + assert.strictEqual(typeof glvModule.structure.Property, 'function'); + assert.strictEqual(typeof glvModule.structure.Vertex, 'function'); + assert.strictEqual(typeof glvModule.structure.VertexProperty, 'function'); + }); + it('should expose fields under driver', function () { + assert.ok(glvModule.driver); + assert.strictEqual(typeof glvModule.driver.RemoteConnection, 'function'); + assert.strictEqual(typeof glvModule.driver.RemoteStrategy, 'function'); + assert.strictEqual(typeof glvModule.driver.RemoteTraversal, 'function'); + }); +}); \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2434a649/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js new file mode 100644 index 0000000..ed5beb3 --- /dev/null +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/graphson-test.js @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/** + * @author Jorge Bay Gondra + */ +'use strict'; + +var assert = require('assert'); +var graph = require('../../lib/structure/graph'); +var t = require('../../lib/process/traversal.js'); +var gs = require('../../lib/structure/io/graph-serializer.js'); +var GraphSONReader = gs.GraphSONReader; +var GraphSONWriter = gs.GraphSONWriter; +var P = t.P; + +describe('GraphSONReader', function () { + it('should parse GraphSON int32, float and double to Number from GraphSON', function () { + var reader = new GraphSONReader(); + [ + [ 'g:Int32', 31 ], + [ 'g:Float', 31.3], + [ 'g:Double', 31.2] + ].forEach(function (item) { + var result = reader.read({ + "@type": item[0], + "@value": item[1] + }); + assert.strictEqual(typeof result, 'number'); + assert.strictEqual(result, item[1]); + }); + }); + it('should parse vertices from GraphSON', function () { + var obj = { + "@type":"g:Vertex", "@value":{"id":{"@type":"g:Int32","@value":1},"label":"person", + "properties":{"name":[{"id":{"@type":"g:Int64","@value":0},"value":"marko"}], + "age":[{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29}}]}}}; + var reader = new GraphSONReader(obj); + var result = reader.read(obj); + assert.ok(result instanceof graph.Vertex); + assert.strictEqual(result.label, 'person'); + assert.strictEqual(typeof result.id, 'number'); + assert.ok(result.properties); + assert.ok(result.properties['name']); + assert.strictEqual(result.properties['name'].length, 1); + assert.strictEqual(result.properties['name'][0].value, 'marko'); + assert.ok(result.properties['age']); + assert.strictEqual(result.properties['age'].length, 1); + assert.strictEqual(result.properties['age'][0].value, 29); + }); + it('should parse paths from GraphSON', function () { + var obj = {"@type":"g:Path","@value":{"labels":[["a"],["b","c"],[]],"objects":[ + { + "@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":1},"label":"person", + "properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":0}, + "value":"marko","label":"name"}}],"age":[{ + "@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":1}, + "value":{"@type":"g:Int32","@value":29},"label":"age"}}]}}}, + { + "@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":3},"label":"software", + "properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":4}, + "value":"lop","label":"name"}}], + "lang":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":5}, + "value":"java","label":"lang"}}]}}}, + "lop"]}}; + var reader = new GraphSONReader(obj); + var result = reader.read(obj); + assert.ok(result); + assert.ok(result.objects); + assert.ok(result.labels); + assert.strictEqual(result.objects[2], 'lop'); + assert.ok(result.objects[0] instanceof graph.Vertex); + assert.ok(result.objects[1] instanceof graph.Vertex); + assert.strictEqual(result.objects[0].label, 'person'); + assert.strictEqual(result.objects[1].label, 'software'); + }); +}); +describe('GraphSONWriter', function () { + it('should write numbers', function () { + var writer = new GraphSONWriter(); + assert.strictEqual(writer.write(2), '2'); + }); + it('should write boolean values', function () { + var writer = new GraphSONWriter(); + assert.strictEqual(writer.write(true), 'true'); + assert.strictEqual(writer.write(false), 'false'); + }); + it('should write P', function () { + var writer = new GraphSONWriter(); + var expected = JSON.stringify({"@type":"g:P","@value":{"predicate":"and","value":[ + {"@type":"g:P","@value":{"predicate":"or","value":[{"@type":"g:P","@value":{"predicate":"lt","value":"b"}}, + {"@type":"g:P","@value":{"predicate":"gt","value":"c"}}]}}, + {"@type":"g:P","@value":{"predicate":"neq","value":"d"}}]}}); + assert.strictEqual(writer.write(P.lt("b").or(P.gt("c")).and(P.neq("d"))), expected); + }); +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2434a649/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/traversal-test.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/traversal-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/traversal-test.js new file mode 100644 index 0000000..c5271c9 --- /dev/null +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/traversal-test.js @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/** + * @author Jorge Bay Gondra + */ +'use strict'; + +var assert = require('assert'); +var graph = require('../../lib/structure/graph'); +var utils = require('../../lib/utils'); +var t = require('../../lib/process/traversal'); +var TraversalStrategies = require('../../lib/process/traversal-strategy').TraversalStrategies; + +describe('Traversal', function () { + describe('#getByteCode()', function () { + it('should add steps for with a string parameter', function () { + var g = new graph.Graph().traversal(); + var bytecode = g.V().out('created').getBytecode(); + assert.ok(bytecode); + assert.strictEqual(bytecode.sourceInstructions.length, 0); + assert.strictEqual(bytecode.stepInstructions.length, 2); + assert.strictEqual(bytecode.stepInstructions[0][0], 'V'); + assert.strictEqual(bytecode.stepInstructions[1][0], 'out'); + assert.strictEqual(bytecode.stepInstructions[1][1], 'created'); + }); + it('should add steps with an enum value', function () { + var g = new graph.Graph().traversal(); + var bytecode = g.V().order().by('age', t.order.decr).getBytecode(); + assert.ok(bytecode); + assert.strictEqual(bytecode.sourceInstructions.length, 0); + assert.strictEqual(bytecode.stepInstructions.length, 3); + assert.strictEqual(bytecode.stepInstructions[0][0], 'V'); + assert.strictEqual(bytecode.stepInstructions[1][0], 'order'); + assert.strictEqual(bytecode.stepInstructions[2][0], 'by'); + assert.strictEqual(bytecode.stepInstructions[2][1], 'age'); + assert.strictEqual(typeof bytecode.stepInstructions[2][2], 'object'); + assert.strictEqual(bytecode.stepInstructions[2][2].typeName, 'Order'); + assert.strictEqual(bytecode.stepInstructions[2][2].elementName, 'decr'); + }); + }); + describe('#next()', function () { + it('should apply the strategies and return a Promise with the iterator item', function () { + var strategyMock = { + apply: function (traversal) { + traversal.traversers = [ new t.Traverser(1, 1), new t.Traverser(2, 1) ]; + return utils.resolvedPromise(); + } + }; + var strategies = new TraversalStrategies(); + strategies.addStrategy(strategyMock); + var traversal = new t.Traversal(null, strategies, null); + return traversal.next() + .then(function (item) { + assert.strictEqual(item.value, 1); + assert.strictEqual(item.done, false); + return traversal.next(); + }) + .then(function (item) { + assert.strictEqual(item.value, 2); + assert.strictEqual(item.done, false); + return traversal.next(); + }) + .then(function (item) { + assert.strictEqual(item.value, null); + assert.strictEqual(item.done, true); + return traversal.next(); + }); + }); + }); + describe('#toList()', function () { + it('should apply the strategies and return a Promise with an array', function () { + var strategyMock = { + apply: function (traversal) { + traversal.traversers = [ new t.Traverser('a', 1), new t.Traverser('b', 1) ]; + return utils.resolvedPromise(); + } + }; + var strategies = new TraversalStrategies(); + strategies.addStrategy(strategyMock); + var traversal = new t.Traversal(null, strategies, null); + return traversal.toList().then(function (list) { + assert.ok(list); + assert.deepEqual(list, [ 'a', 'b' ]); + }); + }); + it('should return an empty array when traversers is empty', function () { + var strategyMock = { + apply: function (traversal) { + traversal.traversers = []; + return utils.resolvedPromise(); + } + }; + var strategies = new TraversalStrategies(); + strategies.addStrategy(strategyMock); + var traversal = new t.Traversal(null, strategies, null); + return traversal.toList().then(function (list) { + assert.ok(Array.isArray(list)); + assert.strictEqual(list.length, 0); + }); + }) + }); +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2434a649/gremlin-javascript/src/test/javascript/gremlin-javascript/helper.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/test/javascript/gremlin-javascript/helper.js b/gremlin-javascript/src/test/javascript/gremlin-javascript/helper.js deleted file mode 100644 index 858ed06..0000000 --- a/gremlin-javascript/src/test/javascript/gremlin-javascript/helper.js +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -/** - * @author Jorge Bay Gondra - */ -(function defineHelperModule() { - "use strict"; - - var assert = { - ok: function (condition, message) { - if (!condition) { - throw new AssertError(message || (condition + ' == true')); - } - }, - strictEqual: function (val1, val2, message) { - if (val1 !== val2) { - throw new AssertError(message || (val1 + ' === ' + val2)); - } - } - }; - - function loadLibModule(moduleName) { - if (typeof require !== 'undefined') { - moduleName = '../lib/' + moduleName; - return require(moduleName); - } - if (typeof load !== 'undefined' && typeof java !== 'undefined') { - moduleName = __DIR__ + '../../../main/javascript/gremlin-javascript/' + moduleName; - var path = new java.io.File(moduleName).getCanonicalPath(); - this.__dependencies = this.__dependencies || {}; - return this.__dependencies[path] = (this.__dependencies[path] || load(path)); - } - throw new Error('No module loader was found'); - } - - function AssertError(message) { - Error.call(this, message); - this.stack = (new Error(message)).stack; - if (typeof print !== 'undefined') { - print(this.stack); - } - } - - inherits(AssertError, Error); - - function inherits(ctor, superCtor) { - ctor.super_ = superCtor; - ctor.prototype = Object.create(superCtor.prototype, { - constructor: { - value: ctor, - enumerable: false, - writable: true, - configurable: true - } - }); - } - var toExport = { - assert: assert, - loadLibModule: loadLibModule - }; - if (typeof module !== 'undefined') { - // CommonJS - module.exports = toExport; - return; - } - return toExport; -}).call(this); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2434a649/gremlin-javascript/src/test/javascript/gremlin-javascript/test-exports.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/test/javascript/gremlin-javascript/test-exports.js b/gremlin-javascript/src/test/javascript/gremlin-javascript/test-exports.js deleted file mode 100644 index b9265c7..0000000 --- a/gremlin-javascript/src/test/javascript/gremlin-javascript/test-exports.js +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -/** - * @author Jorge Bay Gondra - */ -(function defineTestCases() { - "use strict"; - - var helper = loadModule.call(this, './helper.js'); - var assert = helper.assert; - var glvModule = helper.loadLibModule.call(this, './index.js'); - - [ - function testExports() { - assert.ok(glvModule); - - assert.ok(glvModule.process); - assert.strictEqual(typeof glvModule.process.Bytecode, 'function'); - assert.strictEqual(typeof glvModule.process.EnumValue, 'function'); - assert.strictEqual(typeof glvModule.process.P, 'function'); - assert.strictEqual(typeof glvModule.process.Traversal, 'function'); - assert.strictEqual(typeof glvModule.process.TraversalSideEffects, 'function'); - assert.strictEqual(typeof glvModule.process.TraversalStrategies, 'function'); - assert.strictEqual(typeof glvModule.process.TraversalStrategy, 'function'); - assert.strictEqual(typeof glvModule.process.Traverser, 'function'); - assert.strictEqual(typeof glvModule.process.GraphTraversal, 'function'); - assert.strictEqual(typeof glvModule.process.GraphTraversalSource, 'function'); - assert.strictEqual(typeof glvModule.process.barrier, 'object'); - assert.strictEqual(typeof glvModule.process.cardinality, 'object'); - assert.strictEqual(typeof glvModule.process.column, 'object'); - assert.strictEqual(typeof glvModule.process.direction, 'object'); - assert.strictEqual(typeof glvModule.process.operator, 'object'); - assert.strictEqual(typeof glvModule.process.order, 'object'); - assert.strictEqual(typeof glvModule.process.pop, 'object'); - assert.strictEqual(typeof glvModule.process.scope, 'object'); - assert.strictEqual(typeof glvModule.process.t, 'object'); - - - assert.ok(glvModule.process.statics); - - assert.ok(glvModule.structure); - assert.ok(glvModule.structure.io); - assert.strictEqual(typeof glvModule.structure.io.GraphSONReader, 'function'); - assert.strictEqual(typeof glvModule.structure.io.GraphSONWriter, 'function'); - assert.strictEqual(typeof glvModule.structure.Edge, 'function'); - assert.strictEqual(typeof glvModule.structure.Graph, 'function'); - assert.strictEqual(typeof glvModule.structure.Path, 'function'); - assert.strictEqual(typeof glvModule.structure.Property, 'function'); - assert.strictEqual(typeof glvModule.structure.Vertex, 'function'); - assert.strictEqual(typeof glvModule.structure.VertexProperty, 'function'); - - assert.ok(glvModule.driver); - assert.strictEqual(typeof glvModule.driver.RemoteConnection, 'function'); - assert.strictEqual(typeof glvModule.driver.RemoteStrategy, 'function'); - assert.strictEqual(typeof glvModule.driver.RemoteTraversal, 'function'); - } - ].forEach(function (testCase) { - testCase.call(null); - }); - - function loadModule(moduleName) { - if (typeof require !== 'undefined') { - return require(moduleName); - } - if (typeof load !== 'undefined') { - return load(__DIR__ + moduleName); - } - throw new Error('No module loader was found'); - } -}).call(this); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2434a649/gremlin-javascript/src/test/javascript/gremlin-javascript/test-graphson.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/test/javascript/gremlin-javascript/test-graphson.js b/gremlin-javascript/src/test/javascript/gremlin-javascript/test-graphson.js deleted file mode 100644 index 418a9dd..0000000 --- a/gremlin-javascript/src/test/javascript/gremlin-javascript/test-graphson.js +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -/** - * @author Jorge Bay Gondra - */ -(function defineTestCases() { - "use strict"; - - var helper = loadModule.call(this, './helper.js'); - var assert = helper.assert; - var graph = helper.loadLibModule.call(this, 'structure/graph.js'); - var t = helper.loadLibModule.call(this, 'process/traversal.js'); - var gs = helper.loadLibModule.call(this, 'structure/io/graph-serializer.js'); - var GraphSONReader = gs.GraphSONReader; - var GraphSONWriter = gs.GraphSONWriter; - var P = t.P; - - [ - function testReadNumbers() { - var reader = new GraphSONReader(); - [ - [{ - "@type": "g:Int32", - "@value": 31 - }, 31], - [{ - "@type": "g:Float", - "@value": 31.3 - }, 31.3], - [{ - "@type": "g:Double", - "@value": 31.2 - }, 31.2] - ].forEach(function (item) { - var result = reader.read(item[0]); - assert.strictEqual(result, item[1]); - assert.strictEqual(typeof result, 'number'); - }); - }, - function testReadGraph() { - var obj = {"@type":"g:Vertex", "@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","outE":{"created":[{"id":{"@type":"g:Int32","@value":9}, "inV":{"@type":"g:Int32","@value":3},"properties":{"weight":{"@type":"g:Double","@value":0.4}}}],"knows":[{"id":{"@type":"g:Int32","@value":7},"inV":{"@type":"g:Int32","@value":2},"properties":{"weight":{"@type":"g:Double","@value":0.5}}},{"id":{"@type":"g:Int32","@value":8},"inV":{"@type":"g:Int32","@value":4},"properties":{"weight":{"@type":"g:Double","@value":1.0}}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":0},"value":"marko"}],"age":[{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29}}]}}}; - var reader = new GraphSONReader(obj); - var result = reader.read(obj); - assert.ok(result instanceof graph.Vertex); - assert.strictEqual(result.label, 'person'); - assert.strictEqual(typeof result.id, 'number'); - }, - function testReadPath() { - var obj = {"@type":"g:Path","@value":{"labels":[["a"],["b","c"],[]],"objects":[ - {"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":0},"value":"marko","label":"name"}}],"age":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29},"label":"age"}}]}}}, - {"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":3},"label":"software","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":4},"value":"lop","label":"name"}}],"lang":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":5},"value":"java","label":"lang"}}]}}}, - "lop"]}}; - var reader = new GraphSONReader(obj); - var result = reader.read(obj); - assert.ok(result); - assert.ok(result.objects); - assert.ok(result.labels); - assert.strictEqual(result.objects[2], 'lop'); - assert.ok(result.objects[0] instanceof graph.Vertex); - assert.ok(result.objects[1] instanceof graph.Vertex); - assert.strictEqual(result.objects[0].label, 'person'); - assert.strictEqual(result.objects[1].label, 'software'); - }, - function testWriteNumber() { - var writer = new GraphSONWriter(); - assert.strictEqual(writer.write(2), '2'); - }, - function testWriteBoolean() { - var writer = new GraphSONWriter(); - assert.strictEqual(writer.write(true), 'true'); - assert.strictEqual(writer.write(false), 'false'); - }, - function testWriteP() { - var writer = new GraphSONWriter(); - var expected = JSON.stringify({"@type":"g:P","@value":{"predicate":"and","value":[{"@type":"g:P","@value":{"predicate":"or","value":[{"@type":"g:P","@value":{"predicate":"lt","value":"b"}},{"@type":"g:P","@value":{"predicate":"gt","value":"c"}}]}},{"@type":"g:P","@value":{"predicate":"neq","value":"d"}}]}}); - assert.strictEqual(writer.write(P.lt("b").or(P.gt("c")).and(P.neq("d"))), expected); - } - ].forEach(function (testCase) { - testCase.call(null); - }); - - function loadModule(moduleName) { - if (typeof require !== 'undefined') { - return require(moduleName); - } - if (typeof load !== 'undefined') { - return load(__DIR__ + moduleName); - } - throw new Error('No module loader was found'); - } -}).call(this); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2434a649/gremlin-javascript/src/test/javascript/gremlin-javascript/test-traversal.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/test/javascript/gremlin-javascript/test-traversal.js b/gremlin-javascript/src/test/javascript/gremlin-javascript/test-traversal.js deleted file mode 100644 index 1ec4253..0000000 --- a/gremlin-javascript/src/test/javascript/gremlin-javascript/test-traversal.js +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -/** - * @author Jorge Bay Gondra - */ -(function defineTestCases() { - "use strict"; - - var helper = loadModule.call(this, './helper.js'); - var assert = helper.assert; - var graph = helper.loadLibModule.call(this, 'structure/graph.js'); - var t = helper.loadLibModule.call(this, 'process/traversal.js'); - - [ - function testBytecode1() { - var g = new graph.Graph().traversal(); - var bytecode = g.V().out('created').getBytecode(); - assert.ok(bytecode); - assert.strictEqual(bytecode.sourceInstructions.length, 0); - assert.strictEqual(bytecode.stepInstructions.length, 2); - assert.strictEqual(bytecode.stepInstructions[0][0], 'V'); - assert.strictEqual(bytecode.stepInstructions[1][0], 'out'); - assert.strictEqual(bytecode.stepInstructions[1][1], 'created'); - }, - function testBytecode2() { - var g = new graph.Graph().traversal(); - var bytecode = g.V().order().by('age', t.order.decr).getBytecode(); - assert.ok(bytecode); - assert.strictEqual(bytecode.sourceInstructions.length, 0); - assert.strictEqual(bytecode.stepInstructions.length, 3); - assert.strictEqual(bytecode.stepInstructions[0][0], 'V'); - assert.strictEqual(bytecode.stepInstructions[1][0], 'order'); - assert.strictEqual(bytecode.stepInstructions[2][0], 'by'); - assert.strictEqual(bytecode.stepInstructions[2][1], 'age'); - assert.strictEqual(typeof bytecode.stepInstructions[2][2], 'object'); - assert.strictEqual(bytecode.stepInstructions[2][2].typeName, 'Order'); - assert.strictEqual(bytecode.stepInstructions[2][2].elementName, 'decr'); - } - ].forEach(function (testCase) { - testCase.call(null); - }); - - function loadModule(moduleName) { - if (typeof require !== 'undefined') { - return require(moduleName); - } - if (typeof load !== 'undefined') { - return load(__DIR__ + moduleName); - } - throw new Error('No module loader was found'); - } -}).call(this); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2434a649/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 0082048..a8422d1 100644 --- a/pom.xml +++ b/pom.xml @@ -322,6 +322,10 @@ limitations under the License. <exclude>**/*.csproj</exclude> <exclude>**/.vs/**</exclude> <exclude>**/NuGet.Config</exclude> + <exclude>**/gremlin-javascript/node_modules/**</exclude> + <exclude>**/node/node_modules/**</exclude> + <exclude>**/node/node</exclude> + <exclude>**/npm-debug.log</exclude> </excludes> <licenses> <license implementation="org.apache.rat.analysis.license.ApacheSoftwareLicense20"/>