var assert = require('assert'),
    vows = require('vows'),
    ansiparse = require('../');

require('colors');

var dataSets = {
  simple: {
    input: 'hello world'.green,
    output: [{ text: 'hello world', foreground: 'green' }]
  },
  many: {
    input: 'hello '.green + 'world'.red,
    output: [{ text: 'hello ', foreground: 'green' }, { text: 'world', foreground: 'red' }]
  },
  'many same colors': {
    input: 'hello '.green + 'world'.green,
    output: [{ text: 'hello ', foreground: 'green' }, { text: 'world', foreground: 'green' }]
  },
  bold: {
    input: 'hello world'.bold,
    output: [{ text: 'hello world', bold: true }]
  },
  italics: {
    input: 'hello world'.italic,
    output: [{ text: 'hello world', italic: true }]
  },
  background: {
    input: '\033\[42mhello world\033\[49m',
    output: [{ text: 'hello world', background: 'green' }]
  },
  boldAndColor: {
    input: 'hello world'.red.bold,
    output: [{ text: 'hello world', bold: true, foreground: 'red' }]
  },
  'partly bolded': {
    input: 'hello '.bold + 'world'.red,
    output: [
      { text: 'hello ', bold: true },
      { text: 'world', foreground: 'red', bold: false }
    ]
  },
  noColor: {
    input: 'hello world',
    output: [{ text: 'hello world' }]
  },
  'unfinished color': {
    input: '\033\[32mhello world',
    output: [{ text: 'hello world', foreground: 'green' }]
  },
  nested: {
    input: ('hello ' + 'world'.red).green,
    output: [
      { text: 'hello ', foreground: 'green' },
      { text: 'world', foreground: 'red' }
    ]
  },
  grey: {
    input: 'hello world'.grey,
    output: [{ text: 'hello world', foreground: 'grey' }]
  }
};

function getTopics() {
  var topics = {};
  Object.keys(dataSets).forEach(function (set) {
    topics['when using ' + set + ' data set'] = {
      topic: ansiparse(dataSets[set].input),
      'should return correct output': function (result) {
        console.log('\n  Input: ' + dataSets[set].input);
        assert.isArray(result);
        assert.deepEqual(result, dataSets[set].output);
      }
    };
  });
  return topics;
}

vows.describe('ansiparse').addBatch({
  'When using ansiparse': getTopics()
}).export(module);


@@ -1649,16 +1649,163 @@
 rey' %7D%5D%0A
+  %7D,%0A  'malformed control sequence': %7B%0A    input: '%5C033A string between two ESC%5C033',%0A    output: %5B %7B text: '%5C033A string between two ESC%5C033' %7D %5D%0A
   %7D%0A%7D;%0A%0A

Add failing test for malformed inputs