<commit_before>'use strict';

const util = require('../lib/test-utils.js');
const expect = require('chai').expect;

describe('fs.readlink', function() {
  beforeEach(util.setup);
  afterEach(util.cleanup);

  it('should be a function', function() {
    const fs = util.fs();
    expect(fs.readlink).to.be.a('function');
  });

  it('should return an error if part of the parent destination path does not exist', function(done) {
    const fs = util.fs();

    fs.readlink('/tmp/mydir', function(error) {
      expect(error).to.exist;
      expect(error.code).to.equal('ENOENT');
      done();
    });
  });

  it('should return an error if the path is not a symbolic link', function(done) {
    const fs = util.fs();

    fs.readlink('/', function(error) {
      expect(error).to.exist;
      expect(error.code).to.equal('ENOENT');
      done();
    });
  });

  it('should return the contents of a symbolic link', function(done) {
    const fs = util.fs();

    fs.symlink('/', '/myfile', function(error) {
      if(error) throw error;

      fs.readlink('/myfile', function(error, result) {
        expect(error).not.to.exist;
        expect(result).to.equal('/');
        done();
      });
    });
  });

  it('should allow relative paths, but resolve to the dstpath', function(done) {
    const fs = util.fs();
    const contents = 'contents';

    fs.mkdir('/dir', function(error) {
      if(error) throw error;

      fs.writeFile('/file', contents, function(error) {
        if(error) throw error;

        fs.symlink('../file', '/dir/symlink', function(error) {
          if(error) throw error;

          fs.readlink('/dir/symlink', function(error, result) {
            expect(error).not.to.exist;
            expect(result).to.equal('../file');

            fs.readFile('/dir/symlink', 'utf8', function(error, data) {
              expect(error).not.to.exist;
              expect(data).to.equal(contents);
              done();
            });
          });
        });
      });
    });
  });
});<commit_msg>added test to fs.readlink.spec.js<commit_after>'use strict';

const util = require('../lib/test-utils.js');
const expect = require('chai').expect;

describe('fs.readlink', function () {
  beforeEach(util.setup);
  afterEach(util.cleanup);

  it('should be a function', function () {
    const fs = util.fs();
    expect(fs.readlink).to.be.a('function');
  });

  it('should return an error if part of the parent destination path does not exist', function (done) {
    const fs = util.fs();

    fs.readlink('/tmp/mydir', function (error) {
      expect(error).to.exist;
      expect(error.code).to.equal('ENOENT');
      done();
    });
  });

  it('should return an error if the path is not a symbolic link', function (done) {
    const fs = util.fs();

    fs.readlink('/', function (error) {
      expect(error).to.exist;
      expect(error.code).to.equal('ENOENT');
      done();
    });
  });

  it('should return an error if the path is not a symbolic link', function (done) {
    const fs = util.fs();

    fs.mkdir('/tmp', function (error) {
      if (error) throw error;

      fs.readlink('/tmp', function (error) {
        expect(error).to.exist;
        expect(error.code).to.equal('EINVAL');
        done();
      });

    });
  });

  it('should return the contents of a symbolic link', function (done) {
    const fs = util.fs();

    fs.symlink('/', '/myfile', function (error) {
      if (error) throw error;

      fs.readlink('/myfile', function (error, result) {
        expect(error).not.to.exist;
        expect(result).to.equal('/');
        done();
      });
    });
  });

  it('should allow relative paths, but resolve to the dstpath', function (done) {
    const fs = util.fs();
    const contents = 'contents';

    fs.mkdir('/dir', function (error) {
      if (error) throw error;

      fs.writeFile('/file', contents, function (error) {
        if (error) throw error;

        fs.symlink('../file', '/dir/symlink', function (error) {
          if (error) throw error;

          fs.readlink('/dir/symlink', function (error, result) {
            expect(error).not.to.exist;
            expect(result).to.equal('../file');

            fs.readFile('/dir/symlink', 'utf8', function (error, data) {
              expect(error).not.to.exist;
              expect(data).to.equal(contents);
              done();
            });
          });
        });
      });
    });
  });
});
{'fraction_non_alphanumeric': 0.17904718898171146, 'fraction_numerical': 0.0004515692029803567, 'mean_word_length': 2.3946360153256707, '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': '4868038', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1332, 'n_words': 318}