<commit_before>'use strict';
var assert = require('assert');
var fs = require('fs-extra');
var path = require('path');
var a = require('async');
var writer = require('../lib/writer');
var ActionObservable = require('../lib/action-observable');

describe('writer', function () {

    var paths = [
        'settings.json',
        'static',
        'templates',
        'contents'
    ];

    var checkExistence = function (checkExists, ps, cb) {
        var toGo = ps.length;

        if (toGo === 0) {
            cb();
            return;
        }

        ps.forEach(function (p) {
            fs.stat(path.join('.', p), function (err) {
                if (err) {
                    if (err.code === 'ENOENT') {
                        assert(!checkExists, checkExists ? 'The file should exist' : '');
                    }
                } else {
                    assert(checkExists, !checkExists ? 'The file should not exist' : '');
                }

                if (--toGo === 0 && cb !== undefined) {
                    cb();
                }
            });
        });
    };

    var action = new ActionObservable(true);

    /*after(function (done) {
        writer.clearWorkspace(action, function () {
            done();
        });<commit_msg>Refactored checkExistence in writer test<commit_after>'use strict';
var assert = require('assert');
var fs = require('fs-extra');
var path = require('path');
var a = require('async');
var writer = require('../lib/writer');
var ActionObservable = require('../lib/action-observable');

describe('writer', function () {

    var paths = [
        'settings.json',
        'static',
        'templates',
        'contents'
    ];

    var checkExistence = function (checkExists, ps, cb) {
        /*var toGo = ps.length;

        if (toGo === 0) {
            cb();
            return;
        }*/

        a.each(ps, function (p, next) {
            fs.stat(path.join('.', p), function (err) {
                if (err) {
                    if (err.code === 'ENOENT') {
                        assert(!checkExists, checkExists ? 'The file should exist' : '');
                    }
                } else {
                    assert(checkExists, !checkExists ? 'The file should not exist' : '');
                }

                next();
            });
        }, function () {
            cb();
        });

        /*ps.forEach(function (p) {
            fs.stat(path.join('.', p), function (err) {
                if (err) {
                    if (err.code === 'ENOENT') {
                        assert(!checkExists, checkExists ? 'The file should exist' : '');
                    }
                } else {
                    assert(checkExists, !checkExists ? 'The file should not exist' : '');
                }

                if (--toGo === 0 && cb !== undefined) {
                    cb();
                }
            });
        });*/
    };

    var action = new ActionObservable(true);

    /*after(function (done) {
        writer.clearWorkspace(action, function () {
            done();
        });
{'fraction_non_alphanumeric': 0.15496603041087026, 'fraction_numerical': 0.0012940795858945326, 'mean_word_length': 1.3858024691358024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7341237', 'n_tokens_mistral': 851, 'n_tokens_neox': 806, 'n_words': 198}