<commit_before>import React from 'react';
import { expect } from 'chai';
import { mount, shallow } from 'enzyme';

var fs = require('fs');

import RunLengthEncodingTextarea from '../run-length-encoding-textarea.jsx';

describe('<RunLengthEncodingTextarea>', function() {

  describe('#render', function() {
    it('renders', function() {
      const wrapper = shallow(<RunLengthEncodingTextarea />);
      expect(wrapper.find(RunLengthEncodingTextarea)).to.be.ok;
    });
  });

  describe('#parse', function() {
    it("throws an error if there's no seed data", function() {
      const wrapper = shallow(<RunLengthEncodingTextarea />);
      const inst = wrapper.instance();
      wrapper.setState({
        value: ''
      });
      expect(inst.parse.bind(inst)).to.throw(Error, /No seed data/);
    });

    describe("invalid header", function() {
      it("throws an error if there's only comments in the RLE", function() {
        const wrapper = shallow(<RunLengthEncodingTextarea />);
        const inst = wrapper.instance();
        wrapper.setState({
          value: fs.readFileSync('patterns/commentsonly.rle', 'utf8')
        });
        expect(inst.parse.bind(inst)).to.throw(Error, /Invalid/);
      });

      it("throws an error if the header cannot be parsed", function() {
        const wrapper = shallow(<RunLengthEncodingTextarea />);
        const inst = wrapper.instance();
        wrapper.setState({
          value: fs.readFileSync('patterns/invalidheader.rle', 'utf8')
        });
        expect(inst.parse.bind(inst)).to.throw(Error, /Invalid/);
      });
    });
  });
});<commit_msg>added more tests<commit_after>import React from 'react';
import { assert, expect } from 'chai';
import { mount, shallow } from 'enzyme';

var fs = require('fs');

import RunLengthEncodingTextarea from '../run-length-encoding-textarea.jsx';

describe('<RunLengthEncodingTextarea>', function() {

  describe('#render', function() {
    it('renders', function() {
      const wrapper = shallow(<RunLengthEncodingTextarea />);
      expect(wrapper.find(RunLengthEncodingTextarea)).to.be.ok;
    });
  });

  describe('#parse', function() {
    it("throws an error if there's no seed data", function() {
      const wrapper = shallow(<RunLengthEncodingTextarea />);
      const inst = wrapper.instance();
      wrapper.setState({
        value: fs.readFileSync('patterns/no_seed_data.rle', 'utf8')
      });
      expect(inst.parse.bind(inst)).to.throw(Error, /No seed data/);
    });

    it('ignores comment lines', function() {
      const wrapper = shallow(<RunLengthEncodingTextarea />);
      const inst = wrapper.instance();
      wrapper.setState({
        value: fs.readFileSync('patterns/comment_data_only.rle', 'utf8')
      });
      assert.throws(inst.parse.bind(inst), Error);                  // bdd style doesn't work here for some reason
      assert.doesNotThrow(inst.parse.bind(inst), /No seed data/);
    });

    describe('invalid header', function() {
      it('throws an error if the rows or columns are invalid', function() {
        const wrapper = shallow(<RunLengthEncodingTextarea />);
        const inst = wrapper.instance();
        wrapper.setState({
          value: fs.readFileSync('patterns/bad_rows_value.rle', 'utf8')
        });
        expect(inst.parse.bind(inst)).to.throw(Error, /Invalid/);
      });

      it('assumes the default rule string if none is given', function() {
        const wrapper = shallow(<RunLengthEncodingTextarea />);
        const inst = wrapper.instance();
        wrapper.setState({
          value: fs.readFileSync('patterns/no_rule_string.rle', 'utf8')
        });

        const result = inst.parse.call(inst);
        expect(result).to.have.property('born').that.deep.equals([0, 0, 0, 1, 0, 0, 0, 0, 0]);
        expect(result).to.have.property('survives').that.deep.equals([0, 0, 1, 1, 0, 0, 0, 0, 0]);
      });
    });
  });
});
{'fraction_non_alphanumeric': 0.15967246673490276, 'fraction_numerical': 0.006141248720573183, 'mean_word_length': 3.0634095634095635, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '7475202', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1115, 'n_words': 255}