/* jshint undef: false, unused: false */

var marktable  = process.env.COVERAGE ? require('../lib-cov/marktable') : require('../lib/marktable')
var expect     = require('expect.js')
var fixtures   = require('./fixtures/index')
var lpad       = require('underscore.string').lpad
var debug      = require('debug')('marktable:test')
var chokidar   = require('chokidar')
var clc        = require('cli-color')

var Document   = marktable.Document
var Table      = marktable.Table

// Use a watcher to kill test on fixture change
var watcher    = new chokidar.FSWatcher();
watcher.on('change', function(file) {
  console.log('Change on ', file)
  process.exit(0)
})

function debugMatchingInfo(infos) {
  debug('TABLE range:[%s-%s] (%s %s %s %s)',
    infos.offset,
    infos.offsetEnd,
    clc.red.inverse('caption'),
    clc.blue.inverse('headers'),
    clc.green.inverse('columns'),
    clc.yellow.inverse('rows'),
    '\n'+clc.red.inverse(infos.caption || '')
    + clc.blue.inverse(infos.headers || '')
    + clc.green.inverse(infos.columns || '')
    + clc.yellow.inverse(infos.rows || '')
  )
}

describe('marktable', function(){




  describe('Table', function() {
    describe('#parse()', function() {
      it('should parse one table in a source', function() {
        var table  = new Table();
        var src    = fixtures.get(101).read().source;
        var result = table.parse(src);
        debugMatchingInfo(result)
        // console.log(table.toMarkdown())
      })
    })
  })


  describe('Automatic tests', function() {
    fixtures.where({auto:true})
      .forEach(function(test) {
        watcher.add(test.file)
        it(lpad(test.id,3,'0') + '. ' + test.spec,function() {
          var fixture = test.read();
          var result  = marktable(fixture.source);
          debug(result);
          expect(result.trim().split('\n'))
            .to.eql(fixture.expected.trim().split('\n'))
        })
      })
  })

})

@@ -137,16 +137,55 @@
 table')%0A
+var _          = require('underscore')%0A
 var expe
@@ -370,1606 +370,202 @@
 var 
-chokidar   = require('chokidar')%0Avar clc        = require('cli-color')%0A%0Avar Document   = marktable.Document%0Avar Table      = marktable.Table%0A%0A// Use a watcher to kill test on fixture change%0Avar watcher    = new chokidar.FSWatcher();%0Awatcher.on('change', function(file) %7B%0A  console.log('Change on ', file)%0A  process.exit(0)%0A%7D)%0A%0Afunction debugMatchingInfo(infos) %7B%0A  debug('TABLE range:%5B%25s-%25s%5D (%25s %25s %25s %25s)',%0A    infos.offset,%0A    infos.offsetEnd,%0A    clc.red.inverse('caption'),%0A    clc.blue.inverse('headers'),%0A    clc.green.inverse('columns'),%0A    clc.yellow.inverse('rows'),%0A    '%5Cn'+clc.red.inverse(infos.caption %7C%7C '')%0A    + clc.blue.inverse(infos.headers %7C%7C '')%0A    + clc.green.inverse(infos.columns %7C%7C '')%0A    + clc.yellow.inverse(infos.rows %7C%7C '')%0A  )%0A%7D%0A%0Adescribe('marktable', function()%7B%0A%0A%0A%0A%0A  describe('Table', function() %7B%0A    describe('#parse()', function() %7B%0A      it('should parse one table in a source', function() %7B%0A        var 
+viewTable  = require('./tools/visualTableParseResult')%0Avar Document   = marktable.Document%0Avar Table      = mark
 table
-  = new Table();%0A        var src    = fixtures.get(101).read().source;%0A        var result = table.parse(src);%0A        debugMatchingInfo(result)%0A        // console.log(table.toMarkdown())%0A      %7D)%0A    %7D)%0A  %7D)%0A%0A%0A  describe('Automatic tests', function() %7B%0A    fixtures.where(%7Bauto:true%7D)%0A      .forEach(function(test) %7B%0A        watcher.add(test.file)%0A        it(lpad(test.id,3,'0') + '. ' + test.spec,function() %7B%0A          var fixture = test.read();%0A          var result  = marktable(fixture.source);%0A          debug(result);%0A          expect(result.trim().split('%5Cn'))%0A            .to.eql(fixture.expected.trim().split('%5Cn'))%0A        %7D)%0A      %7D)%0A  %7D)
+.Table%0Avar Column     = marktable.Column%0A%0A%0Adescribe('marktable', function() %7B
 %0A%0A%7D)

refactor test