var _ = require('lodash'),
    chai = require('chai'),
    expect = require('chai').expect,
    fs = require('fs'),
    path = require('path'),
    Twig = require('twig'), // Twig module
    twig = Twig.twig,       // Compile function
    Pulsar = require('../../../../')(Twig);

chai.use(require('chai-hiff'));

var fixturesPath = path.resolve(__dirname, '../../../unit/Jadu/Pulsar/Twig/Macro/Fixtures');
Pulsar.installExtensions();

function normalizeOutput(output) {
    output = output.split(/\s+/g);
    output = output.join(' ');
    output = output.replace(/>\s+/g, '>');
    output = output.replace(/\s+</g, '<');

    return output;
}

describe('Macros', function () {
    var fixtureTypes = fs.readdirSync(fixturesPath);

    _.each(fixtureTypes, function (fixtureType) {
        var fixturePath = path.resolve(fixturesPath, fixtureType);
        describe(fixtureType, function () {
            var fixtures = fs.readdirSync(fixturePath);
            _.each(fixtures, function (fixture) {
                if (fixture.indexOf('twig') >= 0) {
                    var base = path.basename(fixture, '.html.twig'),
                        htmlBase = path.basename(fixture, '.twig'),
                        htmlFixturePath = path.resolve(fixturePath, htmlBase),
                        twigFixturePath = path.resolve(fixturePath, fixture);

                    if (fs.existsSync(htmlFixturePath) && fs.existsSync(twigFixturePath)) {
                        it('should correctly render ' + base + ' template', function () {
                            var htmlFixture = fs.readFileSync(htmlFixturePath).toString();
                            var twigFixture = fs.readFileSync(twigFixturePath).toString();

                            var template = twig({
                                async: false,
                                data: twigFixture,
                                namespaces: {
                                    'pulsar': './views/',
                                    'tests': './tests/unit/Jadu/Pulsar/Twig/Macro/Fixtures/'
                                }
                            });

                            var renderedTemplate = normalizeOutput(template.render() || "");
                            var expectedValue = normalizeOutput(htmlFixture);

                            expect(renderedTemplate).to.hiffEqual(expectedValue);
                        });
                    }
                }
            });
        });
    });
});

@@ -2047,16 +2047,80 @@
 xtures/'
+,%0A                                    'cssTests': './tests/css/'
 %0A       
@@ -2402,16 +2402,53 @@
 Template
+.match(/%3Cbody%5B%5E%3E%5D*%3E(.*?)%3C%5C/body%3E/)%5B1%5D
 ).to.hif

Update TwigJS macro tests to ignore extra DOM around macro fixtures