text: 'use strict';
  
  var path        = require('path')
    , chai        = require('chai')
    , util        = require('util')
    , should      = chai.should()
    , parseSql    = require(path.join(__dirname, '..', 'lib', 'db', 'parse-sql'))
    ;
  
  describe('database query parser', function () {
    describe('SELECT DML', function () {
      it("should parse a simple query", function () {
        var ps = parseSql("Select * from dude");
        should.exist(ps);
  
        should.exist(ps.operation);
        ps.operation.should.equal('select');
  
        should.exist(ps.model);
        ps.model.should.equal('dude');
      });
  
      it("should parse another simple query", function () {
        var ps = parseSql("Select * from transaction_traces_12");
        should.exist(ps);
  
        should.exist(ps.operation);
        ps.operation.should.equal('select');
  
        should.exist(ps.model);
        ps.model.should.equal('transaction_traces_12');
      });
    });
  
    describe('DELETE DML', function () {
      it("should parse a simple command", function () {
        var ps = parseSql("DELETE\nfrom dude");
        should.exist(ps);
  
        should.exist(ps.operation);
        ps.operation.should.equal('delete');
  
        should.exist(ps.model);
        ps.model.should.equal('dude');
      });
  
      it("should parse a command with conditions", function () {
        var ps = parseSql("DELETE\nfrom dude where name = 'man'");
        should.exist(ps);
  
        should.exist(ps.operation);
        ps.operation.should.equal('delete');
  
        should.exist(ps.model);
        ps.model.should.equal('dude');
      });
    });
  
    describe('UPDATE DML', function () {
      it("should parse a command with gratuitous white space and conditions", function () {
        var ps = parseSql("  update test set value = 1 where id = 12");
        should.exist(ps);
  
        should.exist(ps.operation);
        ps.operation.should.equal('update');
  
        should.exist(ps.model);
        ps.model.should.equal('test');
      });
    });
  
    describe('INSERT DML', function () {
      it("should parse a command with a subquery", function () {
        var ps = parseSql("  insert into\ntest\nselect * from dude");
        should.exist(ps);
  
        should.exist(ps.operation);
        ps.operation.should.equal('insert');
  
        should.exist(ps.model);
        ps.model.should.equal('test');
      });
    });
  
    describe('invalid DML', function () {
      it("should return 'unknown' for operation and model when handed garbage", function () {
        var ps = parseSql("  bulge into\ndudes\nselect * from dude");
        should.exist(ps);
  
        should.exist(ps.operation);
        ps.operation.should.equal('unknown');
  
        should.exist(ps.model);
        ps.model.should.equal('unknown');
      });
    });
  });
  