<commit_before>///<reference path="../typings/tsd.d.ts"/>
import assert = require('assert');
import util = require('../util');
import fs = require('fs');

describe('writeFile', function() {
    before(function() {
        util.tryDelete('build/test/foo/bar/baz.txt');
        util.tryDelete('build/test/foo/bar');
        util.tryDelete('build/test/foo');
    });
    it('should work', function(done) {
        util.writeFile('build/test/foo/bar/baz.txt', 'hello world').
            then(function () {
                assert.equal(fs.readFileSync('build/test/foo/bar/baz.txt'), 'hello world');
            }).
            then(done).
            catch(done);
    }) ;
});

describe('chunk', function() {
    it('should return [] for (3, [])', function () {
        assert.deepEqual(util.chunk(3, []), []);
    });
    it('should return [[1,2,3],[4,5]] for (3, [1,2,3,4,5])', function () {
        assert.deepEqual(util.chunk(3, [1,2,3,4,5]), [[1,2,3],[4,5]]);
    })
});

describe('getLinks', function() {
    it('works on no links', function() {
        assert.deepEqual(util.getLinks('<b>hello</b>'), []);
    });
    it('works on single link', function() {
        assert.deepEqual(util.getLinks('<a href="foo/bar">hi</a>'), ['foo/bar']);
    });
    it('works on multiple links', function() {
        assert.deepEqual(util.getLinks('<div><a href="foo/bar">hi</a></div><a href="baz">there</a>'),
            ['foo/bar', 'baz']);
    });
});<commit_msg>add mutex test<commit_after>///<reference path="../typings/tsd.d.ts"/>
import assert = require('assert');
import util = require('../util');
import fs = require('fs');

describe('util', function() {
    describe('writeFile', function() {
        before(function() {
            util.tryDelete('build/test/foo/bar/baz.txt');
            util.tryDelete('build/test/foo/bar');
            util.tryDelete('build/test/foo');
        });
        it('should work', function(done) {
            util.writeFile('build/test/foo/bar/baz.txt', 'hello world').
                then(function () {
                    assert.equal(fs.readFileSync('build/test/foo/bar/baz.txt'), 'hello world');
                }).
                then(done).
                catch(done);
        }) ;
    });

    describe('chunk', function() {
        it('should return [] for (3, [])', function () {
            assert.deepEqual(util.chunk(3, []), []);
        });
        it('should return [[1,2,3],[4,5]] for (3, [1,2,3,4,5])', function () {
            assert.deepEqual(util.chunk(3, [1,2,3,4,5]), [[1,2,3],[4,5]]);
        })
    });

    describe('getLinks', function() {
        it('works on no links', function() {
            assert.deepEqual(util.getLinks('<b>hello</b>'), []);
        });
        it('works on single link', function() {
            assert.deepEqual(util.getLinks('<a href="foo/bar">hi</a>'), ['foo/bar']);
        });
        it('works on multiple links', function() {
            assert.deepEqual(util.getLinks('<div><a href="foo/bar">hi</a></div><a href="baz">there</a>'),
                ['foo/bar', 'baz']);
        });
    });

    describe('mutex', function() {
        it('tasks do not overlap', function(done) {
            var m = new util.Mutex();
            var task1running = false;
            var task2running = false;
            m.lock(release => {
                task1running = true;
                setTimeout(() => {
                    assert(!task2running);
                    task1running = false;
                    release();
                }, 10);
            });
            m.lock(release => {
                assert(!task1running);
                task2running = true;
                setTimeout(() => {
                    task2running = false;
                    release();
                }, 50);
            });
            m.lock(release => {
                assert(!task1running);
                assert(!task2running);
                done();
            });
            assert(!task1running);
            assert(!task2running);
        });
    });
});
{'fraction_non_alphanumeric': 0.2046971569839308, 'fraction_numerical': 0.015822002472187888, 'mean_word_length': 1.9255242227042662, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 30, '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': '4757306', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1191, 'n_words': 191}