

/*eslint-env mocha*/

let assert = require('chai').assert,
    path = require('path'),
    generate = require('markdown-it-testgen');


let fixturesPath = path.join(__dirname, 'fixtures');

describe('plugin', function () {
  describe('right workflows', function () {
    it ('default.txt', function () {
      let md = require('markdown-it')()
        .use(require('../'), fixturesPath);
      generate(path.join(__dirname, 'fixtures/default.txt'), md);
    });

    it ('including same field twice', function () {
      let md = require('markdown-it')()
        .use(require('../'), fixturesPath);

      assert.equal(md.render('!!! include( a.md ) !!!\n!!! include( a.md ) !!!'),
        '<p><em>a content</em>\n<em>a content</em></p>\n');
    });

    it ('default options', function () {
      let md = require('markdown-it')()
        .use(require('../'));

      assert.equal(md.render('!!! include( test/fixtures/a.md ) !!!\n'),
        '<p><em>a content</em></p>\n');

      md = require('markdown-it')()
        .use(require('../'), {});

      assert.equal(md.render('!!! include( test/fixtures/a.md ) !!!\n'),
        '<p><em>a content</em></p>\n');
    });

    it ('root option', function () {
      let md = require('markdown-it')()
        .use(require('../'), { root: fixturesPath });

      assert.equal(md.render('!!! include( a.md ) !!!\n'),
        '<p><em>a content</em></p>\n');
    });

    it ('includeRe option', function () {
      let md = require('markdown-it')()
        .use(require('../'), { root: fixturesPath, includeRe: /<\[include\]\((.+)\)/i });

      assert.equal(md.render('<[include]( a.md )\n'),
        '<p><em>a content</em></p>\n');
    });
  });

  describe('wrong workflows', function () {
    it ('file not found', function () {
      let md = require('markdown-it')()
        .use(require('../'), fixturesPath);

      assert.throws(function () {
        md.render('!!! include( xxx.md ) !!!');
      }, Error, /not found/i);
    });

    it ('direct circular reference', function () {
      let md = require('markdown-it')()
        .use(require('../'), fixturesPath);

      assert.throws(function () {
        md.render('!!! include( c.md ) !!!');
      }, Error, /circular reference/i);
    });

    it ('indirect circular reference', function () {
      let md = require('markdown-it')()
        .use(require('../'), fixturesPath);

      assert.throws(function () {
        md.render('!!! include( L1/L2/e2.md ) !!!');
      }, Error, /circular reference/i);
    });
  });
});

@@ -52,21 +52,21 @@
 ).assert
-,%0A   
+;%0Alet
  path = 
@@ -80,21 +80,21 @@
 ('path')
-,%0A   
+;%0Alet
  generat
@@ -129,16 +129,96 @@
 tgen');%0A
+let markdown = require('markdown-it');%0Alet markdown_it_include = require('../');
 %0A%0Alet fi
@@ -394,33 +394,24 @@
 et md = 
-require('
 markdown
 -it')()%0A
@@ -394,37 +394,32 @@
 et md = markdown
--it')
 ()%0A        .use(
@@ -414,38 +414,43 @@
        .use(
-require('../')
+markdown_it_include
 , fixturesPa
@@ -596,33 +596,24 @@
 et md = 
-require('
 markdown
 -it')()%0A
@@ -596,37 +596,32 @@
 et md = markdown
--it')
 ()%0A        .use(
@@ -616,38 +616,43 @@
        .use(
-require('../')
+markdown_it_include
 , fixturesPa
@@ -864,33 +864,24 @@
 et md = 
-require('
 markdown
 -it')()%0A
@@ -864,37 +864,32 @@
 et md = markdown
--it')
 ()%0A        .use(
@@ -888,30 +888,35 @@
    .use(
-require('../')
+markdown_it_include
 );%0A%0A    
@@ -1036,33 +1036,24 @@
    md = 
-require('
 markdown
 -it')()%0A
@@ -1036,37 +1036,32 @@
    md = markdown
--it')
 ()%0A        .use(
@@ -1060,30 +1060,35 @@
    .use(
-require('../')
+markdown_it_include
 , %7B%7D);%0A%0A
@@ -1261,33 +1261,24 @@
 et md = 
-require('
 markdown
 -it')()%0A
@@ -1261,37 +1261,32 @@
 et md = markdown
--it')
 ()%0A        .use(
@@ -1281,38 +1281,43 @@
        .use(
-require('../')
+markdown_it_include
 , %7B root: fi
@@ -1497,33 +1497,24 @@
 et md = 
-require('
 markdown
 -it')()%0A
@@ -1497,37 +1497,32 @@
 et md = markdown
--it')
 ()%0A        .use(
@@ -1521,30 +1521,35 @@
    .use(
-require('../')
+markdown_it_include
 , %7B root
@@ -1812,33 +1812,24 @@
 et md = 
-require('
 markdown
 -it')()%0A
@@ -1812,37 +1812,32 @@
 et md = markdown
--it')
 ()%0A        .use(
@@ -1832,38 +1832,43 @@
        .use(
-require('../')
+markdown_it_include
 , fixturesPa
@@ -2061,33 +2061,24 @@
 et md = 
-require('
 markdown
 -it')()%0A
@@ -2061,37 +2061,32 @@
 et md = markdown
--it')
 ()%0A        .use(
@@ -2081,38 +2081,43 @@
        .use(
-require('../')
+markdown_it_include
 , fixturesPa
@@ -2319,33 +2319,24 @@
 et md = 
-require('
 markdown
 -it')()%0A
@@ -2327,21 +2327,16 @@
 markdown
--it')
 ()%0A     
@@ -2343,30 +2343,35 @@
    .use(
-require('../')
+markdown_it_include
 , fixtur

test cleanup: move all (repeated) `require` statements to the top of the file: reduced clutter.