You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2018/02/01 15:30:19 UTC

[08/50] [abbrv] tinkerpop git commit: Parse maps and mark scenarios with lambdas as skipped

Parse maps and mark scenarios with lambdas as skipped


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/9339a837
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9339a837
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9339a837

Branch: refs/heads/TINKERPOP-1857
Commit: 9339a837b83aa6d72e22cd292fa8a68880b1b51e
Parents: 219ead0
Author: Jorge Bay Gondra <jo...@gmail.com>
Authored: Mon Nov 27 14:42:26 2017 +0100
Committer: Jorge Bay Gondra <jo...@gmail.com>
Committed: Fri Jan 19 09:30:16 2018 +0100

----------------------------------------------------------------------
 .../test/cucumber/feature-steps.js              | 84 ++++++++++++++++++--
 .../gremlin-javascript/test/cucumber/world.js   |  2 +-
 2 files changed, 78 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9339a837/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js
index 6625f29..8ec2bdc 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js
@@ -25,6 +25,7 @@
 const defineSupportCode = require('cucumber').defineSupportCode;
 const vm = require('vm');
 const expect = require('chai').expect;
+const util = require('util');
 const graphModule = require('../../lib/structure/graph');
 const graphTraversalModule = require('../../lib/process/graph-traversal');
 const traversalModule = require('../../lib/process/traversal');
@@ -32,6 +33,10 @@ const Graph = graphModule.Graph;
 const Path = graphModule.Path;
 const __ = graphTraversalModule.statics;
 
+// Determines whether the feature maps (m[]), are deserialized as objects (true) or maps (false).
+// Use false for GraphSON3.
+const mapAsObject = true;
+
 const parsers = [
   [ 'd\\[([\\d.]+)\\]\\.[ilfdm]', toNumeric ],
   [ 'v\\[(.+)\\]', toVertex ],
@@ -69,6 +74,8 @@ defineSupportCode(function(methods) {
   });
 
   methods.Given(/^using the parameter (.+) defined as "(.+)"$/, function (paramName, stringValue) {
+    // Remove escaped chars
+    stringValue = stringValue.replace(/\\"/g, '"');
     let p = Promise.resolve();
     if (this.graphName === 'empty') {
       p = this.loadEmptyGraphData();
@@ -76,6 +83,11 @@ defineSupportCode(function(methods) {
     const self = this;
     return p.then(() => {
       self.parameters[paramName] = parseValue.call(self, stringValue);
+    }).catch(err => {
+      if (err instanceof IgnoreError) {
+        return 'skipped';
+      }
+      throw err;
     });
   });
 
@@ -98,14 +110,14 @@ defineSupportCode(function(methods) {
     const expectedResult = resultTable.rows().map(row => parseRow.call(this, row));
     switch (characterizedAs) {
       case 'ordered':
-        console.log('--- ordered', expectedResult);
         expect(this.result).to.have.deep.ordered.members(expectedResult);
         break;
       case 'unordered':
-        console.log('--- unordered expected:', expectedResult);
-        console.log('--- obtained:', this.result);
         expect(this.result).to.have.deep.members(expectedResult);
         break;
+      case 'of':
+        expect(this.result).to.include.deep.members(expectedResult);
+        break;
     }
   });
 
@@ -117,7 +129,22 @@ defineSupportCode(function(methods) {
   });
 
   methods.Then(/^the result should have a count of (\d+)$/, function (stringCount) {
-    expect(this.result).to.have.lengthOf(parseInt(stringCount, 10));
+    const expected = parseInt(stringCount, 10);
+    if (!Array.isArray(this.result)) {
+      let count = 0;
+      if (this.result instanceof Map) {
+        count = this.result.size;
+      }
+      else if (typeof this.result === 'object') {
+        count = Object.keys(this.result).length;
+      }
+      else {
+        throw new Error('result not supported: ' + util.inspect(this.result));
+      }
+      expect(count).to.be.equal(expected);
+      return;
+    }
+    expect(this.result).to.have.lengthOf(expected);
   });
 
   methods.Then('nothing should happen because', _ => {});
@@ -187,7 +214,11 @@ function toVertexIdString(name) {
 }
 
 function toEdge(name) {
-  return this.getData().edges[name];
+  const e = this.getData().edges[name];
+  if (!e) {
+    throw new Error(util.format('Edge with key "%s" not found', name));
+  }
+  return e;
 }
 
 function toEdgeId(name) {
@@ -210,6 +241,45 @@ function toArray(stringList) {
   return stringList.split(',').map(x => parseValue.call(this, x));
 }
 
-function toMap() {}
+function toMap(stringMap) {
+  return parseMapValue.call(this, JSON.parse(stringMap));
+}
+
+function parseMapValue(value) {
+  if (typeof value === 'string') {
+    return parseValue.call(this, value);
+  }
+  if (Array.isArray(value)) {
+    return value.map(x => parseMapValue.call(this, x));
+  }
+  if (typeof value !== 'object') {
+    return value;
+  }
+  if (mapAsObject) {
+    const result = {};
+    Object.keys(value).forEach(key => {
+      result[key] = parseMapValue.call(this, value[key]);
+    });
+    return result;
+  }
+  const map = new Map();
+  Object.keys(value).forEach(key => {
+    map.set(key, parseMapValue.call(this, value[key]));
+  });
+  return map;
+}
+
+function toLambda() {
+  throw new IgnoreError(IgnoreError.reason.lambdaNotSupported);
+}
+
+function IgnoreError(reason) {
+  Error.call(this, reason);
+  Error.captureStackTrace(this, IgnoreError);
+}
+
+util.inherits(IgnoreError, Error);
 
-function toLambda() {}
\ No newline at end of file
+IgnoreError.reason = {
+  lambdaNotSupported: 'Lambdas are not supported on gremlin-javascript',
+};
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9339a837/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js
index 946d124..03febd1 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js
@@ -104,7 +104,7 @@ function getVertices(connection) {
 function getEdges(connection) {
   const g = new Graph().traversal().withRemote(connection);
   return g.E().group()
-    .by(__.project("o", "l", "i").by(__.outV().values("name")).by(__.inV().values("name")))
+    .by(__.project("o", "l", "i").by(__.outV().values("name")).by(__.label()).by(__.inV().values("name")))
     .by(__.tail())
     .next()
     .then(it => {