<commit_before>var file = require('../');

var tape = require('tape');
var resolve = require('path').resolve;
var writeFileSync = require('fs').writeFileSync;

var filepath1 = resolve(__dirname, './data/link.txt');
var filepath2 = resolve(__dirname, './data/link/link.txt');
var filepath3 = resolve(__dirname, './data/link/link2.txt');


tape('setup link', function(t){
    writeFileSync(filepath1, 'link test\n');
    t.end();
});


tape('link', function(t){
    file.link(filepath1, filepath2)
    .then(function(){
        t.pass('file linked');
        return file.readFile(filepath2, {encoding: 'utf8'});
    })
    .then(function(content){
        t.equal(content, 'link test\n', 'link2 has content of file1');
        t.end();
    })
    .catch(function(error){
        t.error(error);
        t.end();
    });
});


tape('link link', function(t){
    file.link(filepath2, filepath3)
    .then(function(){
        t.pass('file linked');
        return file.write(filepath1, 'changed\n');
    })
    .then(function(){
        return file.readFile(filepath3, {encoding: 'utf8'});
    })
    .then(function(content){
        t.equal(content, 'changed\n', 'link3 has content of file1');
        t.end();
    })
    .catch(function(error){
        t.error(error);
        t.end();
    });
});


tape('link without src', function(t){
    var src = resolve(__dirname, './data/not/here.txt');
    file.link(src, filepath2)
    .then(function(){
        t.fail('should not link');
        t.end();
    })
    .catch(function(error){
        t.ok(error, error);
        t.ok(error instanceof Error, 'is Error');
        t.equal(error.code, 'ENOENT', 'error.code is ENOENT');
        t.equal(error.syscall, 'access', 'error.syscal is access');
        t.end();
    });
});


tape('link dest error', function(t){
    var dest = resolve(__dirname, './data/link/link.txt/sub/not/work.txt');
    file.link(filepath1, dest)
    .then(function(){
        t.fail('should not link');
        t.end();
    })
    .catch(function(error){
        t.ok(error, error);
        t.ok(error instanceof Error, 'is Error');
        t.equal(error.code, 'ENOTDIR', 'error.code is ENOTDIR');
        t.equal(error.syscall, 'mkdir', 'error.syscal is mkdir');
        t.end();
    });
});
<commit_msg>fs.link test for ENOENT or EEIST on windows (#20)<commit_after>var file = require('../');

var tape = require('tape');
var resolve = require('path').resolve;
var writeFileSync = require('fs').writeFileSync;

var filepath1 = resolve(__dirname, './data/link.txt');
var filepath2 = resolve(__dirname, './data/link/link.txt');
var filepath3 = resolve(__dirname, './data/link/link2.txt');


tape('setup link', function(t){
    writeFileSync(filepath1, 'link test\n');
    t.end();
});


tape('link', function(t){
    file.link(filepath1, filepath2)
    .then(function(){
        t.pass('file linked');
        return file.readFile(filepath2, {encoding: 'utf8'});
    })
    .then(function(content){
        t.equal(content, 'link test\n', 'link2 has content of file1');
        t.end();
    })
    .catch(function(error){
        t.error(error);
        t.end();
    });
});


tape('link link', function(t){
    file.link(filepath2, filepath3)
    .then(function(){
        t.pass('file linked');
        return file.write(filepath1, 'changed\n');
    })
    .then(function(){
        return file.readFile(filepath3, {encoding: 'utf8'});
    })
    .then(function(content){
        t.equal(content, 'changed\n', 'link3 has content of file1');
        t.end();
    })
    .catch(function(error){
        t.error(error);
        t.end();
    });
});


tape('link without src', function(t){
    var src = resolve(__dirname, './data/not/here.txt');
    file.link(src, filepath2)
    .then(function(){
        t.fail('should not link');
        t.end();
    })
    .catch(function(error){
        t.ok(error, error);
        t.ok(error instanceof Error, 'is Error');
        t.equal(error.code, 'ENOENT', 'error.code is ENOENT');
        t.equal(error.syscall, 'access', 'error.syscal is access');
        t.end();
    });
});


tape('link dest error', function(t){
    var dest = resolve(__dirname, './data/link/link.txt/sub/not/work.txt');
    file.link(filepath1, dest)
    .then(function(){
        t.fail('should not link');
        t.end();
    })
    .catch(function(error){
        t.ok(error, error);
        t.ok(error instanceof Error, 'is Error');
        t.ok(/^(ENOTDIR|EEXIST)$/.test(error.code), 'error.code is ENOENT (or EEXIST on Windows)');
        t.equal(error.syscall, 'mkdir', 'error.syscal is mkdir');
        t.end();
    });
});

{'fraction_non_alphanumeric': 0.19289889586490583, 'fraction_numerical': 0.009092877246157177, 'mean_word_length': 2.725806451612903, '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': '5857215', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1547, 'n_words': 313}