<commit_before>var fs = require('fs'),
    path = require('path'),
    mock = require('mock-fs'),
    MockNode = require('mock-enb/lib/mock-node'),
    Tech = require('../../techs/bemhtml'),
    loadDirSync = require('mock-enb/utils/dir-utils').loadDirSync,
    FileList = require('enb/lib/file-list'),
    bundlePath = path.resolve('lib/bundle.js');

describe('bemhtml', function () {
    afterEach(function () {
        mock.restore();
    });

    it('must generate mock if there is no templates', function () {
        var templates = [];

        return build(templates)
            .spread(function (res) {
                var bemjson = { block: 'block' };

                res.BEMHTML.apply(bemjson).must.be('');
            });
    });

    it('must keep base templates if there is no templates and forceBaseTemplates option is true', function () {
        var templates = [];

        return build(templates, { forceBaseTemplates: true })
            .spread(function (res) {
                var bemjson = { block: 'block' },
                    html = '<div class="block"></div>';

                res.BEMHTML.apply(bemjson).must.be(html);
            });
    });

    it('must use `bemhtml.js` suffix', function () {
        var blocks = {
            'block.bemhtml.js': 'block("block").tag()("a")',
            'block.bemhtml': 'block("block").tag()("span")'
        };

        return build(blocks)
            .spread(function (res) {
                var bemjson = { block: 'block' },
                    html = '<a class="block"></a>';

                res.BEMHTML.apply(bemjson).must.be(html);
            });
    });

    describe('base templates', function () {
        it('must ignore templates in `i-bem`', function () {
            var blocks = {
                'i-bem.bemhtml.js': 'block("block").tag()("a")'
            };

            return build(blocks)
                .spread(function (res) {
                    var bemjson = { block: 'block' },
                        html = '<div class="block"></div>';

                    res.BEMHTML.apply(bemjson).must.be(html);
                });
        });

        it('must ignore templates in `i-bem__html`', function () {
            var blocks = {
                'i-bem__html.bemhtml': 'block("block").tag()("a")'
            };

            return build(blocks, { sourceSuffixes: ['bemhtml.js', 'bemhtml'] })
                .spread(function (res) {
                    var bemjson = { block: 'block' },
                        html = '<div class="block"></div>';

                    res.BEMHTML.apply(bemjson).must.be(html);
                });
        });
    });

    describe('naming', function () {
        it('must use origin naming', function () {
            var blocks = {
                'block.bemhtml.js': 'block("block").tag()("div")'
            };

            return build(blocks)
                .spread(function (res) {
                    var bemjson = { block: 'block', elem: 'elem', mods: { mod: true } },
                        html = '<div class="block__elem block__elem_mod"></div>';

                    res.BEMHTML.apply(bemjson).must.be(html);
                });
        });

        it('must support custom naming', function () {
            var blocks = {
                'block.bemhtml.js': 'block("block").tag()("div")'
            };

            return build(blocks, { naming: { elem: '__', mod: '--' } })
                .spread(function (res) {
                    var bemjson = { block: 'block', elem: 'elem', mods: { mod: true } },
                        html = '<div class="block__elem block__elem--mod"></div>';

                    res.BEMHTML.apply(bemjson).must.be(html);
                });
        });
    });

    describe('compat', function () {
        it('must throw error if old syntax', function () {
            var templates = ['block bla, tag: "a"'];

            return build(templates)
                .fail(function (err) {
                    err.must.a(Error);
                });
        });

        it('must not support old syntax for files with `.js` extension', function () {
            var blocks = {
                    'block.bemhtml.js': 'block bla, tag: "a"'
                },
                options = { compat: true };

            return build(blocks, options)<commit_msg>Fixed bemhtml tests<commit_after>var fs = require('fs'),
    path = require('path'),
    mock = require('mock-fs'),
    MockNode = require('mock-enb/lib/mock-node'),
    Tech = require('../../techs/bemhtml'),
    loadDirSync = require('mock-enb/utils/dir-utils').loadDirSync,
    FileList = require('enb/lib/file-list'),
    bundlePath = path.resolve('lib/bundle.js');

describe('bemhtml', function () {
    afterEach(function () {
        mock.restore();
    });

    it('must generate mock if there is no templates', function () {
        var templates = [];

        return build(templates)
            .spread(function (res) {
                var bemjson = { block: 'block' };

                res.BEMHTML.apply(bemjson).must.be('');
            });
    });

    it('must keep base templates if there is no templates and forceBaseTemplates option is true', function () {
        var templates = [];

        return build(templates, { forceBaseTemplates: true })
            .spread(function (res) {
                var bemjson = { block: 'block' },
                    html = '<div class="block"></div>';

                res.BEMHTML.apply(bemjson).must.be(html);
            });
    });

    it('must use `bemhtml.js` suffix', function () {
        var blocks = {
            'block.bemhtml.js': 'block("block").tag()("a")',
            'block.bemhtml': 'block("block").tag()("span")'
        };

        return build(blocks)
            .spread(function (res) {
                var bemjson = { block: 'block' },
                    html = '<a class="block"></a>';

                res.BEMHTML.apply(bemjson).must.be(html);
            });
    });

    describe('base templates', function () {
        it('must ignore templates in `i-bem`', function () {
            var blocks = {
                'i-bem.bemhtml.js': 'block("block").tag()("a")'
            };

            return build(blocks)
                .spread(function (res) {
                    var bemjson = { block: 'block' },
                        html = '<div class="block"></div>';

                    res.BEMHTML.apply(bemjson).must.be(html);
                });
        });

        it('must ignore templates in `i-bem__html`', function () {
            var blocks = {
                'i-bem__html.bemhtml': 'block("block").tag()("a")'
            };

            return build(blocks, { sourceSuffixes: ['bemhtml.js', 'bemhtml'] })
                .spread(function (res) {
                    var bemjson = { block: 'block' },
                        html = '<div class="block"></div>';

                    res.BEMHTML.apply(bemjson).must.be(html);
                });
        });
    });

    describe('naming', function () {
        it('must use origin naming', function () {
            var blocks = {
                'block.bemhtml.js': 'block("block").tag()("div")'
            };

            return build(blocks)
                .spread(function (res) {
                    var bemjson = { block: 'block', elem: 'elem', elemMods: { mod: true } },
                        html = '<div class="block__elem block__elem_mod"></div>';

                    res.BEMHTML.apply(bemjson).must.be(html);
                });
        });

        it('must support custom naming', function () {
            var blocks = {
                'block.bemhtml.js': 'block("block").tag()("div")'
            };

            return build(blocks, { naming: { elem: '__', mod: '--' } })
                .spread(function (res) {
                    var bemjson = { block: 'block', elem: 'elem', elemMods: { mod: true } },
                        html = '<div class="block__elem block__elem--mod"></div>';

                    res.BEMHTML.apply(bemjson).must.be(html);
                });
        });
    });

    describe('compat', function () {
        it('must throw error if old syntax', function () {
            var templates = ['block bla, tag: "a"'];

            return build(templates)
                .fail(function (err) {
                    err.must.a(Error);
                });
        });

        it('must not support old syntax for files with `.js` extension', function () {
            var blocks = {
                    'block.bemhtml.js': 'block bla, tag: "a"'
                },
                options = { compat: true };

            return build(blocks, options)
{'fraction_non_alphanumeric': 0.16370763200368918, 'fraction_numerical': 0.0, 'mean_word_length': 1.5372916057326704, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, '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': '5972153', 'n_tokens_mistral': 2504, 'n_tokens_neox': 2352, 'n_words': 497}