<commit_before>/*!
 * template-toc <https://github.com/jonschlinkert/template-toc>
 *
 * Copyright (c) 2015, <NAME>.
 * Licensed under the MIT License.
 */

'use strict';

/* deps:mocha */
var should = require('should');
var Template = require('template');
var toc = require('./');
var template;

describe('toc', function () {
  beforeEach(function () {
    template = new Template();
    template.page('fixture.md', [
      '# Basic markdown',
      '',
      '> This is a block quote',
      '',
      '<!-- toc -->',
      '',
      '## AAA',
      '',
      'This is aaa.',
      '',
      '<%= partial("doc.md") %>',
    ].join('\n'));

    // load a partial
    template.partial('doc.md', [
      '### BBB',
      'This is bbb.',
      '',
      '#### CCC',
      'This is ccc.',
      '',
      '##### DDD',
      'This is ddd.',
    ].join('\n'));
  })

  it.skip('should work as an onLoad middleware:', function (done) {
    template.onLoad(/\.md$/, toc(template));

    // render `./fixtures/basic.md`
    template.render('fixture.md', function (err, content) {
      if (err) console.log(err);

      content.should.equal([
        '# Basic markdown',
        '',
        '> This is a block quote',
        '',
        '<!-- toc -->',
        '',
        '- [AAA](#aaa)',
        '',
        '<!-- tocstop -->',
        '',
        '## AAA',
        '',
        'This is aaa.',
        '',
        '### BBB',
        'This is bbb.',
        '',
        '#### CCC',
        'This is ccc.',
        '',
        '##### DDD',
        'This is ddd.'
      ].join('\n'));
      done();
    });
  });

  it('should work as a preRender middleware:', function (done) {
    template.preRender(/\.md$/, toc(template));

    // render `./fixtures/basic.md`
    template.render('fixture.md', function (err, content) {
      if (err) console.log(err);

      content.should.equal([
        '# Basic markdown',
        '',
        '> This is a block quote',
        '',
        '<!-- toc -->',
        '',
        '- [AAA](#aaa)',
        '',
        '<!-- tocstop -->',
        '',
        '## AAA',
        '',
        'This is aaa.',
        '',
        '### BBB',
        'This is bbb.',
        '',
        '#### CCC',
        'This is ccc.',
        '',
        '##### DDD',
        'This is ddd.'
      ].join('\n'));
      done();
    });
  });

  it('should work as a postRender middleware:', function (done) {
    template.postRender(/\.md$/, toc(template));

    // render `./fixtures/basic.md`
    template.render('fixture.md', function (err, content) {
      if (err) console.log(err);
      content.should.equal([
        '# Basic markdown',
        '',
        '> This is a block quote',
        '',
        '<!-- toc -->',
        '',
        '- [AAA](#aaa)',
        '  * [BBB](#bbb)',
        '    + [CCC](#ccc)',
        '      ~ [DDD](#ddd)',
        '',
        '<!-- tocstop -->',
        '',
        '## AAA',
        '',
        'This is aaa.',
        '',
        '### BBB',
        'This is bbb.',
        '',
        '#### CCC',
        'This is ccc.',
        '',
        '##### DDD',
        'This is ddd.',
      ].join('\n'));
      done();
    });
  });
});<commit_msg>fix onLoad test<commit_after>/*!
 * template-toc <https://github.com/jonschlinkert/template-toc>
 *
 * Copyright (c) 2015, <NAME>.
 * Licensed under the MIT License.
 */

'use strict';

/* deps:mocha */
var should = require('should');
var Template = require('template');
var toc = require('./');
var template;

describe('toc', function () {
  beforeEach(function () {
    template = new Template();
    template.page('fixtures/basic.md');
    template.partial('fixtures/doc.md');
  });

  it('should work as an onLoad middleware:', function (done) {
    template.onLoad(/\.md$/, toc(template));
    // with `.onLoad()`, we need to load the templates AFTER the
    // middleware is defined. other stages it doesn't matter
    template.page('fixtures/basic.md');
    template.partial('fixtures/doc.md');

    // render `./fixtures/basic.md`
    template.render('basic.md', function (err, content) {
      if (err) console.log(err);
      content.should.equal([
        '# Basic markdown',
        '',
        '> This is a block quote',
        '',
        '<!-- toc -->',
        '',
        '- [AAA](#aaa)',
        '',
        '<!-- tocstop -->',
        '',
        '## AAA',
        '',
        'This is aaa.',
        '',
        '### BBB',
        'This is bbb.',
        '',
        '#### CCC',
        'This is ccc.',
        '',
        '##### DDD',
        'This is ddd.\n'
      ].join('\n'));
      done();
    });
  });

  it('should work as a preRender middleware:', function (done) {
    template.preRender(/\.md$/, toc(template));
    template.page('fixtures/basic.md');
    template.partial('fixtures/doc.md');

    // render `./fixtures/basic.md`
    template.render('basic.md', function (err, content) {
      if (err) console.log(err);

      content.should.equal([
        '# Basic markdown',
        '',
        '> This is a block quote',
        '',
        '<!-- toc -->',
        '',
        '- [AAA](#aaa)',
        '',
        '<!-- tocstop -->',
        '',
        '## AAA',
        '',
        'This is aaa.',
        '',
        '### BBB',
        'This is bbb.',
        '',
        '#### CCC',
        'This is ccc.',
        '',
        '##### DDD',
        'This is ddd.\n'
      ].join('\n'));
      done();
    });
  });

  it('should work as a postRender middleware:', function (done) {
    template.postRender(/\.md$/, toc(template));

    // render `./fixtures/basic.md`
    template.render('basic.md', function (err, content) {
      if (err) console.log(err);
      content.should.equal([
        '# Basic markdown',
        '',
        '> This is a block quote',
        '',
        '<!-- toc -->',
        '',
        '- [AAA](#aaa)',
        '  * [BBB](#bbb)',
        '    + [CCC](#ccc)',
        '      ~ [DDD](#ddd)',
        '',
        '<!-- tocstop -->',
        '',
        '## AAA',
        '',
        'This is aaa.',
        '',
        '### BBB',
        'This is bbb.',
        '',
        '#### CCC',
        'This is ccc.',
        '',
        '##### DDD',
        'This is ddd.',
      ].join('\n'));
      done();
    });
  });

  it('should use options from template:', function (done) {
    template.option({
      toc: {
        append: '\n\n_(Table of contents generated by [verb])_',
        ignore: ['BBB']
      }
    });

    template.page('fixtures/basic.md');
    template.partial('fixtures/doc.md');
    template.postRender(/\.md$/, toc(template));

    // render `./fixtures/basic.md`
    template.render('basic.md', function (err, content) {
      if (err) console.log(err);
      content.should.equal([
        '# Basic markdown',
        '',
        '> This is a block quote',
        '',
        '<!-- toc -->',
        '',
        '- [AAA](#aaa)',
        '    + [CCC](#ccc)',
        '      ~ [DDD](#ddd)',
        '',
        '_(Table of contents generated by [verb])_',
        '',
        '<!-- tocstop -->',
        '',
        '## AAA',
        '',
        'This is aaa.',
        '',
        '### BBB',
        'This is bbb.',
        '',
        '#### CCC',
        'This is ccc.',
        '',
        '##### DDD',
        'This is ddd.',
      ].join('\n'));
      done();
    });
  });

});
{'fraction_non_alphanumeric': 0.22650210226502102, 'fraction_numerical': 0.0010850400108504, 'mean_word_length': 1.5047554347826086, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 31, 'https://': 2, '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': '6727788', 'n_tokens_mistral': 2419, 'n_tokens_neox': 2391, 'n_words': 484}