<commit_before>var should = require('chai').should(); // eslint-disable-line
var pathFn = require('path');
var Promise = require('bluebird');
var fs = require('hexo-fs');
var yaml = require('js-yaml');
var _ = require('lodash');

describe('File', () => {
  var Hexo = require('../../../lib/hexo');
  var hexo = new Hexo(__dirname);
  var Box = require('../../../lib/box');
  var box = new Box(hexo, pathFn.join(hexo.base_dir, 'file_test'));
  var File = box.File;

  var body = [
    'name:',
    '  first: John',
    '  last: Doe',
    '',
    'age: 23',
    '',
    'list:',
    '- Apple',
    '- Banana'
  ].join('\n');

  var obj = yaml.load(body);
  var path = 'test.yml';

  function makeFile(path, props) {
    return new File(_.assign({
      source: pathFn.join(box.base, path),
      path
    }, props));
  }

  var file = makeFile(path, {
    source: pathFn.join(box.base, path),
    path,
    type: 'create',
    params: {foo: 'bar'}
  });

  before(() => Promise.all([
    fs.writeFile(file.source, body),
    hexo.init()
  ]).then(() => fs.stat(file.source)));

  after(() => fs.rmdir(box.base));

  it('read()', () => file.read().should.eventually.eql(body));

  it('read() - callback', callback => {
    file.read((err, content) => {
      should.not.exist(err);
      content.should.eql(body);
      callback();
    });
  });

  it('readSync()', () => {
    file.readSync().should.eql(body);
  });

  it('stat()', () => Promise.all([
    fs.stat(file.source),
    file.stat()
  ]).then(stats => {
    stats[0].should.eql(stats[1]);
  }));

  it('stat() - callback', callback => {
    file.stat((err, fileStats) => {
      if (err) return callback(err);

      fileStats.should.eql(fs.statSync(file.source));
      callback();
    });
  });

  it('statSync()', () => {
    file.statSync().should.eql(fs.statSync(file.source));
  });

  it('render()', () => file.render().should.eventually.eql(obj));

  it('render() - callback', callback => {
    file.render((err, data) => {
      if (err) return callback(err);

      data.should.eql(obj);
      callback();
    });<commit_msg>hotfix(file): cast dev to uint32<commit_after>var should = require('chai').should(); // eslint-disable-line
var pathFn = require('path');
var Promise = require('bluebird');
var fs = require('hexo-fs');
var yaml = require('js-yaml');
var _ = require('lodash');

describe('File', () => {
  var Hexo = require('../../../lib/hexo');
  var hexo = new Hexo(__dirname);
  var Box = require('../../../lib/box');
  var box = new Box(hexo, pathFn.join(hexo.base_dir, 'file_test'));
  var File = box.File;

  var body = [
    'name:',
    '  first: John',
    '  last: Doe',
    '',
    'age: 23',
    '',
    'list:',
    '- Apple',
    '- Banana'
  ].join('\n');

  var obj = yaml.load(body);
  var path = 'test.yml';

  function makeFile(path, props) {
    return new File(_.assign({
      source: pathFn.join(box.base, path),
      path
    }, props));
  }

  var file = makeFile(path, {
    source: pathFn.join(box.base, path),
    path,
    type: 'create',
    params: {foo: 'bar'}
  });

  before(() => Promise.all([
    fs.writeFile(file.source, body),
    hexo.init()
  ]).then(() => fs.stat(file.source)));

  after(() => fs.rmdir(box.base));

  it('read()', () => file.read().should.eventually.eql(body));

  it('read() - callback', callback => {
    file.read((err, content) => {
      should.not.exist(err);
      content.should.eql(body);
      callback();
    });
  });

  it('readSync()', () => {
    file.readSync().should.eql(body);
  });

  it('stat()', () => Promise.all([
    fs.stat(file.source),
    file.stat()
  ]).then(stats => {
    stats[0].should.eql(stats[1]);
  }));

  it('stat() - callback', callback => {
    file.stat((err, fileStats) => {
      if (err) return callback(err);

      //todo: cast dev to uint32 until https://github.com/nodejs/node/issues/16496 is resolved
      fileStats.dev = (new Uint32Array([fileStats.dev]))[0]
      fileStats.should.eql(fs.statSync(file.source));
      callback();
    });
  });

  it('statSync()', () => {
    file.statSync().should.eql(fs.statSync(file.source));
  });

  it('render()', () => file.render().should.eventually.eql(obj));

  it('render() - callback', callback => {
    file.render((err, data) => {
      if (err) return callback(err);

      data.should.eql(obj);
      callback();
    });
{'fraction_non_alphanumeric': 0.23075160403299724, 'fraction_numerical': 0.00458295142071494, 'mean_word_length': 2.8255915863277825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 1, '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': '4520234', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1538, 'n_words': 282}