<commit_before>{assert} = require('chai')
{StringToJson} = require('../src/string-to-json')
{sampleText} = require '../test/fixtures'

getLines = (text) ->
  return text.split('\n')

describe 'StringToJson', ->
  stj = new StringToJson sampleText

  describe '#constructor', ->

    it 'should assign @text', ->
      assert.strictEqual stj.text, sampleText

    it 'should assign @json', ->
      assert.isDefined stj.json
  
  describe '#generate', ->
    it 'should return hash', ->
      assert.typeOf stj.generate(), 'object' 
    
    describe 'returned hash', ->
      it 'should be same size as input text line count', ->
        assert.equal Object.keys(stj.generate()).length,
        getLines(sampleText).length

      it 'should contain all input text lines', ->
        lines = getLines(sampleText)

        for k,v of stj.generate()
          index = lines.indexOf v
          if index > -1
            lines.splice index, 1

        assert.equal lines.length, 0

      describe 'each entry\'s key', ->
        it 'should match prefix of hash with line number in original text', ->
          lines = getLines(sampleText)

          for k,v of stj.generate()
            lineNumber = parseInt(k.split('-')[0])
            assert.equal lines[lineNumber], v<commit_msg>empty string test<commit_after>{assert} = require('chai')
{StringToJson} = require('../src/string-to-json')
{sampleText} = require '../test/fixtures'

getLines = (text) ->
  return text.split('\n')

describe 'StringToJson', ->
  stj = undefined
  before ->
    stj = new StringToJson sampleText

  describe '#constructor', ->

    it 'should assign @text', ->
      assert.strictEqual stj.text, sampleText

    it 'should assign @json', ->
      assert.isDefined stj.json
  
  describe '#generate', ->
    it 'should return hash', ->
      assert.typeOf stj.generate(), 'object' 
    
    describe 'returned hash', ->
      it 'should be same size as input text line count', ->
        assert.equal Object.keys(stj.generate()).length,
        getLines(sampleText).length

      it 'should contain all input text lines', ->
        lines = getLines(sampleText)

        for k,v of stj.generate()
          index = lines.indexOf v
          if index > -1
            lines.splice index, 1

        assert.equal lines.length, 0

      describe 'each entry\'s key', ->
        it 'should match prefix of hash with line number in original text', ->
          lines = getLines(sampleText)

          for k,v of stj.generate()
            lineNumber = parseInt(k.split('-')[0])
            assert.equal lines[lineNumber], v

    describe 'in case when empty string is provided to constructor', ->
      before ->
        stj = new StringToJson ''

      it 'should generate empty hash', ->
        assert.isTrue Object.keys(stj.generate()).length == 0



{'fraction_non_alphanumeric': 0.1280509373894588, 'fraction_numerical': 0.0031835868411743897, 'mean_word_length': 2.3467455621301774, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '5606468', 'n_tokens_mistral': 828, 'n_tokens_neox': 802, 'n_words': 244}