<commit_before>import { EventEmitter } from 'events';
import { expect } from 'chai';

import Parser from '../lib/parser';

describe('Parser', function() {

  describe('The class itself', function() {
    it('can be constructed', function () {
      expect(Parser).to.be.a('function');
    });

    it('is called Parser', function() {
      expect(Parser.name).to.equal('Parser');
    });

    it('extends EventEmitter', function() {
      expect(Parser.EventEmitter).to.be.a('function');
      expect(Parser.EventEmitter.name).to.equal('EventEmitter');
    });
  });

  describe('Object instantiation', function () {
    it('accepts a filename to parse', function() {
      let parser = new Parser('/path/to/a/dbf/file');

      expect(parser).to.be.an.instanceof(Parser);
      expect(parser.filename).to.equal('/path/to/a/dbf/file');
    });

    it('does not check if filename exists', function() {
      let parser = new Parser('/path/to/a/file/that/does/not/exist');

      expect(parser).to.be.an.instanceof(Parser);
      expect(parser.filename).to.equal('/path/to/a/file/that/does/not/exist');
    });

    it('does not require a filename', function() {
      let parser = new Parser();

      expect(parser).to.be.an.instanceof(Parser);
      expect(parser.filename).to.equal(undefined);
    });

    it('allows the filename to be modified after instantiation', function() {
      let parser = new Parser('/path/to/file/1');

      expect(parser).to.be.an.instanceof(Parser);
      expect(parser.filename).to.equal('/path/to/file/1');

      parser.filename = '/path/to/file/2';
      expect(parser.filename).to.equal('/path/to/file/2');
    });
  });

  describe('The methods', function() {
    let parser = new Parser('/path/to/a/dbf/file');

    it('has a parse() method', function() {
      expect(parser).to.respondTo('parse');
    });

    it('has an on() method', function() {
      expect(parser).to.respondTo('on');
    });

    it('has a pause() method', function() {
      expect(parser).to.respondTo('resume');
    });

    it('has a resume() method', function() {
      expect(parser).to.respondTo('resume');
    });
  });

  describe('Parsing the SF zip codes', function() {
    let parser = new Parser(__dirname + '/fixtures/bayarea_zipcodes.dbf');
    let header, records = [], events;

    before(function(done) {
      events = {start: undefined, header: undefined, record: undefined, end: undefined};

      parser.on('start', function() {
        events.start = process.hrtime()[1];
      });

      parser.on('header', function(h) {
        header = h;
        events.header = process.hrtime()[1];
      });

      parser.on('record', function(record) {
        records.push(record);
        events.record = process.hrtime()[1];<commit_msg>Fix typo in tests<commit_after>import { EventEmitter } from 'events';
import { expect } from 'chai';

import Parser from '../lib/parser';

describe('Parser', function() {

  describe('The class itself', function() {
    it('can be constructed', function () {
      expect(Parser).to.be.a('function');
    });

    it('is called Parser', function() {
      expect(Parser.name).to.equal('Parser');
    });

    it('extends EventEmitter', function() {
      expect(Parser.EventEmitter).to.be.a('function');
      expect(Parser.EventEmitter.name).to.equal('EventEmitter');
    });
  });

  describe('Object instantiation', function () {
    it('accepts a filename to parse', function() {
      let parser = new Parser('/path/to/a/dbf/file');

      expect(parser).to.be.an.instanceof(Parser);
      expect(parser.filename).to.equal('/path/to/a/dbf/file');
    });

    it('does not check if filename exists', function() {
      let parser = new Parser('/path/to/a/file/that/does/not/exist');

      expect(parser).to.be.an.instanceof(Parser);
      expect(parser.filename).to.equal('/path/to/a/file/that/does/not/exist');
    });

    it('does not require a filename', function() {
      let parser = new Parser();

      expect(parser).to.be.an.instanceof(Parser);
      expect(parser.filename).to.equal(undefined);
    });

    it('allows the filename to be modified after instantiation', function() {
      let parser = new Parser('/path/to/file/1');

      expect(parser).to.be.an.instanceof(Parser);
      expect(parser.filename).to.equal('/path/to/file/1');

      parser.filename = '/path/to/file/2';
      expect(parser.filename).to.equal('/path/to/file/2');
    });
  });

  describe('The methods', function() {
    let parser = new Parser('/path/to/a/dbf/file');

    it('has a parse() method', function() {
      expect(parser).to.respondTo('parse');
    });

    it('has an on() method', function() {
      expect(parser).to.respondTo('on');
    });

    it('has a pause() method', function() {
      expect(parser).to.respondTo('pause');
    });

    it('has a resume() method', function() {
      expect(parser).to.respondTo('resume');
    });
  });

  describe('Parsing the SF zip codes', function() {
    let parser = new Parser(__dirname + '/fixtures/bayarea_zipcodes.dbf');
    let header, records = [], events;

    before(function(done) {
      events = {start: undefined, header: undefined, record: undefined, end: undefined};

      parser.on('start', function() {
        events.start = process.hrtime()[1];
      });

      parser.on('header', function(h) {
        header = h;
        events.header = process.hrtime()[1];
      });

      parser.on('record', function(record) {
        records.push(record);
        events.record = process.hrtime()[1];
{'fraction_non_alphanumeric': 0.18581995309399243, 'fraction_numerical': 0.0025257081003066933, 'mean_word_length': 3.0290697674418605, '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': '4461836', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1691, 'n_words': 326}