<commit_before>'use strict';

var MarkdownColor = require('../../../lib/utilities/markdown-color');
var expect        = require('chai').expect;
var path          = require('path');

describe('MarkdownColor', function() {
  var mc;

  beforeEach(function() {
    mc = new MarkdownColor();
  });

  it('parses default markdown', function() {

  });

  it('parses color tokens', function() {
    expect(mc.render('^r^red^r^')).to.equal('\u001b[0m\u001b[31mred\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^g^green^g^')).to.equal('\u001b[0m\u001b[32mgreen\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^b^blue^b^')).to.equal('\u001b[0m\u001b[34mblue\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^c^cyan^c^')).to.equal('\u001b[0m\u001b[36mcyan\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^m^magenta^m^')).to.equal('\u001b[0m\u001b[35mmagenta\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^y^yellow^y^')).to.equal('\u001b[0m\u001b[33myellow\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^k^black^k^')).to.equal('\u001b[0m\u001b[30mblack\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^gr^grey^gr^')).to.equal('\u001b[0m\u001b[90mgrey\u001b[39m\u001b[0m\n\n');

    expect(mc.render('^br^bgRed^br^')).to.equal('\u001b[0m\u001b[41mbgRed\u001b[49m\u001b[0m\n\n');
    expect(mc.render('^bg^bgGreen^bg^')).to.equal('\u001b[0m\u001b[42mbgGreen\u001b[49m\u001b[0m\n\n');
    expect(mc.render('^bb^bgBlue^bb^')).to.equal('\u001b[0m\u001b[44mbgBlue\u001b[49m\u001b[0m\n\n');
    expect(mc.render('^bc^bgCyan^bc^')).to.equal('\u001b[0m\u001b[46mbgCyan\u001b[49m\u001b[0m\n\n');
    expect(mc.render('^bm^bgMagenta^bm^')).to.equal('\u001b[0m\u001b[45mbgMagenta\u001b[49m\u001b[0m\n\n');
    expect(mc.render('^by^bgYellow^by^')).to.equal('\u001b[0m\u001b[43mbgYellow\u001b[49m\u001b[0m\n\n');
    expect(mc.render('^bk^bgBlack^bk^')).to.equal('\u001b[0m\u001b[40mbgBlack\u001b[49m\u001b[0m\n\n');
  });

  it('parses custom tokens', function() {
    expect(mc.render('--option')).to.equal('\u001b[0m\u001b[36m--option\u001b[39m\u001b[0m\n\n');
    expect(mc.render('(Default: value)')).to.equal('\u001b[0m\u001b[36m(Default: value)\u001b[39m\u001b[0m\n\n');
    expect(mc.render('(Required)')).to.equal('\u001b[0m\u001b[36m(Required)\u001b[39m\u001b[0m\n\n');
    expect(mc.render('<args>')).to.equal('\u001b[90m\u001b[33m<args>\u001b[39m\u001b[39m');
  });

  it('accepts tokens on instantiation', function() {
    var mctemp = new MarkdownColor({
      tokens: {
        foo: {
          token: '^foo^',
          pattern: /(?:\^foo\^)(.*?)(?:\^foo\^)/g,
          render: MarkdownColor.prototype.renderStylesFactory(['blue','bgWhite'])
        }
      }
    });
    expect(mctemp.render('^foo^foo^foo^')).to.equal('\u001b[0m\u001b[34m\u001b[47mfoo\u001b[49m\u001b[39m\u001b[0m\n\n');
  });

  it('parses markdown files', function() {
    console.log('\u001b[0m  \u001b[36mtacos are \u001b[33mdelicious\u001b[36m \u001b[34mand I\u001b[39m enjoy eating them \u001b[39m\u001b[0m\n\n');
    expect(mc.renderFile(path.join(__dirname,'../../../tests/fixtures/markdown/foo.md'))).to
      .equal('\u001b[0m  \u001b[36mtacos are \u001b[33mdelicious\u001b[36m \u001b[34mand I\u001b[39m enjoy eating them \u001b[39m\u001b[0m\n\n');
  });

  it('allows tokens inside other token bounds', function() {
    expect(mc.render('^c^tacos are ^y^delicious^y^ and I enjoy eating them ^c^')).to.equal('\u001b[0m\u001b[36mtacos are \u001b[33mdelicious\u001b[36m and I enjoy eating them \u001b[39m\u001b[0m\n\n');
  });
});
/* Chalk supported styles -
styles:
   { reset: { open: '\u001b[0m', close: '\u001b[0m', closeRe: /[0m/g },
     bold: { open: '\u001b[1m', close: '\u001b[22m', closeRe: /[22m/g },
     dim: { open: '\u001b[2m', close: '\u001b[22m', closeRe: /[22m/g },
     italic: { open: '\u001b[3m', close: '\u001b[23m', closeRe: /[23m/g },
     underline: { open: '\u001b[4m', close: '\u001b[24m', closeRe: /[24m/g },
     inverse: { open: '\u001b[7m', close: '\u001b[27m', closeRe: /[27m/g },
     hidden: { open: '\u001b[8m', close: '\u001b[28m', closeRe: /[28m/g },
     strikethrough: { open: '\u001b[9m', close: '\u001b[29m', closeRe: /[29m/g },
     black: { open: '\u001b[30m', close: '\u001b[39m', closeRe: /[39m/g },
     red: { open: '\u001b[31m', close: '\u001b[39m', closeRe: /[39m/g },<commit_msg>Added skip() for markdown-color tests when ansi isn't supported<commit_after>'use strict';

var MarkdownColor = require('../../../lib/utilities/markdown-color');
var expect        = require('chai').expect;
var path          = require('path');
var chalk         = require('chalk');

function isAnsiSupported() {
  // when ansi is supported this should be
  return chalk.red('a') !== 'a';
}

(isAnsiSupported() ? describe : describe.skip)('MarkdownColor', function() {
  var mc;

  beforeEach(function() {
    /*
    // check to make sure ansi is supported
    // can use this.skip() after Mocha 2.1.1
    // see https://github.com/mochajs/mocha/pull/946
    if (isAnsiSupported()) {
      this.skip();
    }
    */
    mc = new MarkdownColor();
  });

  it('parses default markdown', function() {
    expect(mc.render('# foo\n__bold__ words\n* un\n* ordered\n* list')).to.equal(
      '\u001b[1m\u001b[4m\u001b[35m# foo\u001b[39m\u001b[24m\u001b[22m\n\u001b[0m\u001b[1m' +
      'bold\u001b[22m words\u001b[0m\n\n   \u001b[0m* un\u001b[0m\n   \u001b[0m* ordered\u001b[0m\n   \u001b[0m* list\u001b[0m\n\n');
  });

  it('parses color tokens', function() {
    expect(mc.render('^r^red^r^')).to.equal('\u001b[0m\u001b[31mred\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^g^green^g^')).to.equal('\u001b[0m\u001b[32mgreen\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^b^blue^b^')).to.equal('\u001b[0m\u001b[34mblue\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^c^cyan^c^')).to.equal('\u001b[0m\u001b[36mcyan\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^m^magenta^m^')).to.equal('\u001b[0m\u001b[35mmagenta\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^y^yellow^y^')).to.equal('\u001b[0m\u001b[33myellow\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^k^black^k^')).to.equal('\u001b[0m\u001b[30mblack\u001b[39m\u001b[0m\n\n');
    expect(mc.render('^gr^grey^gr^')).to.equal('\u001b[0m\u001b[90mgrey\u001b[39m\u001b[0m\n\n');

    expect(mc.render('^br^bgRed^br^')).to.equal('\u001b[0m\u001b[41mbgRed\u001b[49m\u001b[0m\n\n');
    expect(mc.render('^bg^bgGreen^bg^')).to.equal('\u001b[0m\u001b[42mbgGreen\u001b[49m\u001b[0m\n\n');
    expect(mc.render('^bb^bgBlue^bb^')).to.equal('\u001b[0m\u001b[44mbgBlue\u001b[49m\u001b[0m\n\n');
    expect(mc.render('^bc^bgCyan^bc^')).to.equal('\u001b[0m\u001b[46mbgCyan\u001b[49m\u001b[0m\n\n');
    expect(mc.render('^bm^bgMagenta^bm^')).to.equal('\u001b[0m\u001b[45mbgMagenta\u001b[49m\u001b[0m\n\n');
    expect(mc.render('^by^bgYellow^by^')).to.equal('\u001b[0m\u001b[43mbgYellow\u001b[49m\u001b[0m\n\n');
    expect(mc.render('^bk^bgBlack^bk^')).to.equal('\u001b[0m\u001b[40mbgBlack\u001b[49m\u001b[0m\n\n');
  });

  it('parses custom tokens', function() {
    expect(mc.render('--option')).to.equal('\u001b[0m\u001b[36m--option\u001b[39m\u001b[0m\n\n');
    expect(mc.render('(Default: value)')).to.equal('\u001b[0m\u001b[36m(Default: value)\u001b[39m\u001b[0m\n\n');
    expect(mc.render('(Required)')).to.equal('\u001b[0m\u001b[36m(Required)\u001b[39m\u001b[0m\n\n');
    expect(mc.render('<args>')).to.equal('\u001b[90m\u001b[33m<args>\u001b[39m\u001b[39m');
  });

  it('accepts tokens on instantiation', function() {
    var mctemp = new MarkdownColor({
      tokens: {
        foo: {
          token: '^foo^',
          pattern: /(?:\^foo\^)(.*?)(?:\^foo\^)/g,
          render: MarkdownColor.prototype.renderStylesFactory(['blue','bgWhite'])
        }
      }
    });
    expect(mctemp.render('^foo^foo^foo^')).to.equal('\u001b[0m\u001b[34m\u001b[47mfoo\u001b[49m\u001b[39m\u001b[0m\n\n');
  });

  it('parses markdown files', function() {
    // console.log('\u001b[0m  \u001b[36mtacos are \u001b[33mdelicious\u001b[36m \u001b[34mand I\u001b[39m enjoy eating them \u001b[39m\u001b[0m\n\n');
    expect(mc.renderFile(path.join(__dirname,'../../../tests/fixtures/markdown/foo.md'))).to
      .equal('\u001b[0m  \u001b[36mtacos are \u001b[33mdelicious\u001b[36m \u001b[34mand I\u001b[39m enjoy eating them \u001b[39m\u001b[0m\n\n');
  });

  it('allows tokens inside other token bounds', function() {
    expect(mc.render('^c^tacos are ^y^delicious^y^ and I enjoy eating them ^c^')).to.equal('\u001b[0m\u001b[36mtacos are \u001b[33mdelicious\u001b[36m and I enjoy eating them \u001b[39m\u001b[0m\n\n');
  });
});
/* Chalk supported styles -
styles:
   { reset: { open: '\u001b[0m', close: '\u001b[0m', closeRe: /[0m/g },
     bold: { open: '\u001b[1m', close: '\u001b[22m', closeRe: /[22m/g },
     dim: { open: '\u001b[2m', close: '\u001b[22m', closeRe: /[22m/g },
     italic: { open: '\u001b[3m', close: '\u001b[23m', closeRe: /[23m/g },
     underline: { open: '\u001b[4m', close: '\u001b[24m', closeRe: /[24m/g },
     inverse: { open: '\u001b[7m', close: '\u001b[27m', closeRe: /[27m/g },
     hidden: { open: '\u001b[8m', close: '\u001b[28m', closeRe: /[28m/g },
     strikethrough: { open: '\u001b[9m', close: '\u001b[29m', closeRe: /[29m/g },
     black: { open: '\u001b[30m', close: '\u001b[39m', closeRe: /[39m/g },
     red: { open: '\u001b[31m', close: '\u001b[39m', closeRe: /[39m/g },
{'fraction_non_alphanumeric': 0.2393208030756087, 'fraction_numerical': 0.13316958564715933, 'mean_word_length': 4.128696604600219, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, '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': '1359130', 'n_tokens_mistral': 5051, 'n_tokens_neox': 4407, 'n_words': 445}