From commits-return-25562-archive-asf-public=cust-asf.ponee.io@tinkerpop.apache.org Fri Jan 19 09:30:38 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id 97A9E180791 for ; Fri, 19 Jan 2018 09:30:38 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 8805D160C52; Fri, 19 Jan 2018 08:30:38 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id ABB54160C49 for ; Fri, 19 Jan 2018 09:30:37 +0100 (CET) Received: (qmail 61492 invoked by uid 500); 19 Jan 2018 08:30:36 -0000 Mailing-List: contact commits-help@tinkerpop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tinkerpop.apache.org Delivered-To: mailing list commits@tinkerpop.apache.org Received: (qmail 61415 invoked by uid 99); 19 Jan 2018 08:30:36 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Jan 2018 08:30:36 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2B0BCE7E01; Fri, 19 Jan 2018 08:30:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jorgebg@apache.org To: commits@tinkerpop.apache.org Date: Fri, 19 Jan 2018 08:30:38 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [04/44] tinkerpop git commit: Javascript GLV http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2d850565/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 new file mode 100644 index 0000000..e44ef90 --- /dev/null +++ b/gremlin-javascript/src/test/javascript/gremlin-javascript/test-graphson.js @@ -0,0 +1,108 @@ +/* + * 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 testWriteNumber() { + 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/2d850565/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 new file mode 100644 index 0000000..477df91 --- /dev/null +++ b/gremlin-javascript/src/test/javascript/gremlin-javascript/test-traversal.js @@ -0,0 +1,54 @@ +/* + * 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'); + + [ + function testBytecode() { + 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'); + } + ].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/2d850565/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 075c89f..9603d76 100644 --- a/pom.xml +++ b/pom.xml @@ -120,6 +120,7 @@ limitations under the License. gremlin-groovy gremlin-groovy-test tinkergraph-gremlin + gremlin-javascript gremlin-python gremlin-dotnet hadoop-gremlin