var expect = require('chai').expect;
var fs = require('fs');
var locater = require('../lib/locater');

describe("locater", function() {
  describe(".find", function() {
    it("matches array and returns locations of results", function() {
      var input = fs.readFileSync(
        './test/fixtures/sample_input.txt', {encoding: 'utf8'});

      var result = locater.find(['my', 'me'], input);

      expect(result[0].line).to.equal(1);
      expect(result[0].cursor).to.equal(4);
      expect(result[1].line).to.equal(2);
      expect(result[1].cursor).to.equal(1);
      expect(result[2].line).to.equal(2);
      expect(result[2].cursor).to.equal(16);
      expect(result[3].line).to.equal(3);
      expect(result[3].cursor).to.equal(27);
    });

    it("matches string and returns locations of results", function() {
      var input = fs.readFileSync(
        './test/fixtures/sample_input.txt', {encoding: 'utf8'});

      var result = locater.find('my', input);

      expect(result[0].line).to.equal(1);
      expect(result[0].cursor).to.equal(4);
      expect(result[1].line).to.equal(2);
      expect(result[1].cursor).to.equal(1);
      expect(result[2].line).to.equal(3);
      expect(result[2].cursor).to.equal(27);

    });

    it("matches regex and returns locations of results", function() {
      var input = fs.readFileSync(
        './test/fixtures/sample_input.txt', {encoding: 'utf8'});

      var result = locater.find(/[a-zA-Z]{7}\s/g, input);

      expect(result[0].line).to.equal(1);
      expect(result[0].cursor).to.equal(7);
      expect(result[1].line).to.equal(1);
      expect(result[1].cursor).to.equal(27);
      expect(result[2].line).to.equal(3);
      expect(result[2].cursor).to.equal(11);
    });

    it("can match more than once for the same line", function() {
      var input = "What ain't no country I've ever heard of. They speak English in What?";
      var result = locater.find('What', input);

      expect(result[0].line).to.equal(1);
      expect(result[0].cursor).to.equal(1);
      expect(result[1].line).to.equal(1);
      expect(result[1].cursor).to.equal(65);
    });

    it("returns an empty array when no match is present", function() {
      var result = locater.find('What', "Zed's dead, baby. Zed's dead.");
      expect(result).to.have.length(0);
    });

    it("matches multiple occurences of a string in a line", function() {
      var result = locater.find('my', 'my mind my soul');
      expect(result[0].line).to.equal(1);
      expect(result[0].cursor).to.equal(1);
      expect(result[1].line).to.equal(1);
      expect(result[1].cursor).to.equal(9);
    });

    it("matches multiple occurences of a regex in a line", function() {
      var result = locater.find(/[a-zA-Z]{6}/g, 'kaskade - 4AM');
      expect(result.length).to.equal(2);
    });
  });

  describe(".findOne", function() {
    it("returns the position of the first match against string", function() {
      var result = locater.findOne('world', "this is\nhello world");
      expect(result).to.be.an('object');
      expect(result.line).to.equal(2);
      expect(result.cursor).to.equal(7);
    });

    it("returns null if there is no match against string", function() {
      var result = locater.findOne('truck', "this is\nhello world");
      expect(result).to.equal(null);
    });

    it("returns the position of the first match against regex", function() {
      var result = locater.findOne(/\d{3}/, "this is\nexample 123 world");
      expect(result).to.be.an('object');
      expect(result.line).to.equal(2);
      expect(result.cursor).to.equal(9);
    });

    it("returns null if there is no match against regex", function() {
      var result = locater.findOne(/\d{3}/, "this is\nexample world");
      expect(result).to.equal(null);
    });
  });

  describe(".any", function() {
    it("returns true if there is at least one match with string", function() {
      var result = locater.any('hello', 'hello world');
      expect(result).to.equal(true);
    });

    it("returns false if there is no match with string", function() {
      var result = locater.any('foo', 'Say what again');
      expect(result).to.equal(false);
    });

    it("returns true if there is at least one match with regex", function() {
      var result = locater.any(/[a-z]{5}/g, 'hello world');
      expect(result).to.equal(true);
    });

    it("returns false if there is no match with regex", function() {
      var result = locater.any(/\d+/g, 'hello world');
      expect(result).to.equal(false);
    });
  });
});

@@ -184,16 +184,27 @@
 s array 
+of strings 
 and retu
@@ -746,32 +746,520 @@
 l(27);%0A    %7D);%0A%0A
+    it(%22matches array of regexes and returns locations of results%22, function() %7B%0A      var input = %22Bacon tastes gooood.%5CnPork chops taste gooood.%22;%0A      var result = locater.find(%5B/%5Ba-zA-Z%5D%7B6%7D%5C./g, /Pork/g%5D, input);%0A%0A      expect(result%5B0%5D.line).to.equal(1);%0A      expect(result%5B0%5D.cursor).to.equal(14);%0A      expect(result%5B1%5D.line).to.equal(2);%0A      expect(result%5B1%5D.cursor).to.equal(18);%0A      expect(result%5B2%5D.line).to.equal(2);%0A      expect(result%5B2%5D.cursor).to.equal(1);%0A    %7D);%0A%0A
     it(%22matches 

Add test for array of regexes