<commit_before>
var levelgraph = require("../");
var levelup = require("levelup");
var tmp = require("tmp");

describe("navigator", function() {

  var db;

  beforeEach(function(done) {
    tmp.dir(function(err, dir) {
      if (err) {
        done(err);
        return;
      }

      db = levelgraph(levelup(dir));
      db.put(require("./fixture/foaf"), done);
    });
  });

  afterEach(function(done) {
    db.close(done);
  });

  it("should navigate to a single vertex", function(done) {
    db.nav("matteo").values(function(err, results) {
      expect(results).to.eql(["matteo"]);
      done();
    });
  });

  it("should follow an arch going out a vertex", function(done) {
    db.nav("matteo").archOut("friend").values(function(err, friends) {
      expect(friends).to.eql(["daniele"]);
      done();
    });
  });

  it("should follow an arch going in a vertex", function(done) {
    db.nav("davide").archIn("friend").values(function(err, friends) {
      expect(friends).to.eql(["marco"]);
      done();
    });
  });

  it("should follow multiple archs, in and out a path", 
     function(done) {
    db.nav("davide").archIn("friend").archIn("friend").archOut("friend").
      values(function(err, friends) {

      expect(friends).to.eql(["marco", "matteo"]);
      done();
    });
  });

  it("should follow multiple archs, in and out a path using a stream", 
     function(done) {
    var stream = db.nav("davide").archIn("friend").archIn("friend").archOut("friend").valuesStream();

    stream.on("data", function(data) {
      expect(["marco", "matteo"].indexOf(data) >= 0).to.be.ok;
    });

    stream.on("end", done);
  });

  it("should allow to set the name of the variables", 
     function(done) {
    db.nav("marco").archIn("friend").as("a").archOut("friend").archOut("friend").as("a").
      values(function(err, friends) {

      expect(friends).to.eql(["daniele"]);
      done();
    });
  });

  it("should allow to bind a variable", 
     function(done) {
    db.nav("matteo").archIn("friend").bind("lucio").archOut("friend").bind("marco").
      values(function(err, friends) {

      expect(friends).to.eql(["marco"]);
      done();
    });
  });

  it("should allow to start the navigation from a variable",
     function(done) {
    db.nav().archOut("friend").bind("matteo").archOut("friend").
      values(function(err, friends) {

      expect(friends).to.eql(["daniele"]);
      done();
    });
  });

  it("should return the contexts", 
     function(done) {
    db.nav("daniele").archOut("friend").as("a").
      contexts(function(err, contexts) {

      expect(contexts).to.eql([{ a: "marco" }, { a: "matteo" }]);
      done();
    });
  });

  it("should return the context as a stream", 
     function(done) {

    var contexts = [{ a: "marco" }, { a: "matteo" }];

    var stream = db.nav("daniele").archOut("friend").as("a").
      contextsStream();

    stream.on("data", function(data) {
      expect(data).to.eql(contexts.shift());
    });

    stream.on("end", done);
  });
});<commit_msg>Testing the behavior of Navigator.contexts with no conditions.<commit_after>
var levelgraph = require("../");
var levelup = require("levelup");
var tmp = require("tmp");

describe("navigator", function() {

  var db;

  beforeEach(function(done) {
    tmp.dir(function(err, dir) {
      if (err) {
        done(err);
        return;
      }

      db = levelgraph(levelup(dir));
      db.put(require("./fixture/foaf"), done);
    });
  });

  afterEach(function(done) {
    db.close(done);
  });

  it("should navigate to a single vertex", function(done) {
    db.nav("matteo").values(function(err, results) {
      expect(results).to.eql(["matteo"]);
      done();
    });
  });

  it("should follow an arch going out a vertex", function(done) {
    db.nav("matteo").archOut("friend").values(function(err, friends) {
      expect(friends).to.eql(["daniele"]);
      done();
    });
  });

  it("should follow an arch going in a vertex", function(done) {
    db.nav("davide").archIn("friend").values(function(err, friends) {
      expect(friends).to.eql(["marco"]);
      done();
    });
  });

  it("should follow multiple archs, in and out a path", 
     function(done) {
    db.nav("davide").archIn("friend").archIn("friend").archOut("friend").
      values(function(err, friends) {

      expect(friends).to.eql(["marco", "matteo"]);
      done();
    });
  });

  it("should follow multiple archs, in and out a path using a stream", 
     function(done) {
    var stream = db.nav("davide").archIn("friend").archIn("friend").archOut("friend").valuesStream();

    stream.on("data", function(data) {
      expect(["marco", "matteo"].indexOf(data) >= 0).to.be.ok;
    });

    stream.on("end", done);
  });

  it("should allow to set the name of the variables", 
     function(done) {
    db.nav("marco").archIn("friend").as("a").archOut("friend").archOut("friend").as("a").
      values(function(err, friends) {

      expect(friends).to.eql(["daniele"]);
      done();
    });
  });

  it("should allow to bind a variable", 
     function(done) {
    db.nav("matteo").archIn("friend").bind("lucio").archOut("friend").bind("marco").
      values(function(err, friends) {

      expect(friends).to.eql(["marco"]);
      done();
    });
  });

  it("should allow to start the navigation from a variable",
     function(done) {
    db.nav().archOut("friend").bind("matteo").archOut("friend").
      values(function(err, friends) {

      expect(friends).to.eql(["daniele"]);
      done();
    });
  });

  it("should return the contexts", 
     function(done) {
    db.nav("daniele").archOut("friend").as("a").
      contexts(function(err, contexts) {

      expect(contexts).to.eql([{ a: "marco" }, { a: "matteo" }]);
      done();
    });
  });

  it("should return the context as a stream", 
     function(done) {

    var contexts = [{ a: "marco" }, { a: "matteo" }];

    var stream = db.nav("daniele").archOut("friend").as("a").
      contextsStream();

    stream.on("data", function(data) {
      expect(data).to.eql(contexts.shift());
    });

    stream.on("end", done);
  });

  it("should return an empty context if no condition is specified",
     function(done) {
    db.nav("daniele").contexts(function(err, contexts) {
      expect(contexts).to.eql([{}]);
      done();
    });
  });
});
{'fraction_non_alphanumeric': 0.20901639344262296, 'fraction_numerical': 0.00031525851197982345, 'mean_word_length': 3.117456197274497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5412118', 'n_tokens_mistral': 2188, 'n_tokens_neox': 2082, 'n_words': 386}