<commit_before>require 'spec_helper'

describe 'Hash mapping with Transproc' do
  describe 'symbolize_keys' do
    it 'returns a new hash with symbolized keys' do
      symbolize_keys = Transproc(:symbolize_keys)

      input = { 'foo' => 'bar' }
      output = { foo: 'bar' }

      expect(symbolize_keys[input]).to eql(output)
      expect(input).to eql('foo' => 'bar')
    end
  end

  describe 'symbolize_keys!' do
    it 'returns updated hash with symbolized keys' do
      symbolize_keys = Transproc(:symbolize_keys!)

      input = { 'foo' => 'bar' }
      output = { foo: 'bar' }

      symbolize_keys[input]

      expect(input).to eql(output)
    end
  end

  describe 'nest' do
    it 'returns new hash with keys nested under a new key' do
      nest = Transproc(:nest, :baz, ['foo'])

      input = { 'foo' => 'bar' }
      output = { baz: { 'foo' => 'bar' } }

      expect(nest[input]).to eql(output)
      expect(input).to eql('foo' => 'bar')
    end
  end

  describe 'nest!' do
    it 'returns new hash with keys nested under a new key' do
      nest = Transproc(:nest!, :baz, ['foo'])

      input = { 'foo' => 'bar' }
      output = { baz: { 'foo' => 'bar' } }

      nest[input]

      expect(input).to eql(output)
    end

    it 'returns new hash with nil nested under a new key when nest-keys are missing' do
      nest = Transproc(:nest!, :baz, ['foo'])

      input = { 'bar' => 'foo' }
      output = { 'bar' => 'foo', baz: nil }

      nest[input]

      expect(input).to eql(output)
    end
  end

  describe 'map_hash' do
    it 'returns a new hash with applied functions' do
      map = Transproc(:map_hash, 'foo' => :foo)<commit_msg>Add a spec for hash.nest<commit_after>require 'spec_helper'

describe 'Hash mapping with Transproc' do
  describe 'symbolize_keys' do
    it 'returns a new hash with symbolized keys' do
      symbolize_keys = Transproc(:symbolize_keys)

      input = { 'foo' => 'bar' }
      output = { foo: 'bar' }

      expect(symbolize_keys[input]).to eql(output)
      expect(input).to eql('foo' => 'bar')
    end
  end

  describe 'symbolize_keys!' do
    it 'returns updated hash with symbolized keys' do
      symbolize_keys = Transproc(:symbolize_keys!)

      input = { 'foo' => 'bar' }
      output = { foo: 'bar' }

      symbolize_keys[input]

      expect(input).to eql(output)
    end
  end

  describe 'nest' do
    it 'returns new hash with keys nested under a new key' do
      nest = Transproc(:nest, :baz, ['foo'])

      input = { 'foo' => 'bar' }
      output = { baz: { 'foo' => 'bar' } }

      expect(nest[input]).to eql(output)
      expect(input).to eql('foo' => 'bar')
    end
  end

  describe 'nest!' do
    it 'returns new hash with keys nested under a new key' do
      nest = Transproc(:nest!, :baz, ['one', 'two'])

      input = { 'foo' => 'bar', 'one' => nil, 'two' => false }
      output = { 'foo' => 'bar', baz: { 'one' => nil, 'two' => false } }

      nest[input]

      expect(input).to eql(output)
    end

    it 'returns new hash with nil nested under a new key when nest-keys are missing' do
      nest = Transproc(:nest!, :baz, ['foo'])

      input = { 'bar' => 'foo' }
      output = { 'bar' => 'foo', baz: nil }

      nest[input]

      expect(input).to eql(output)
    end
  end

  describe 'map_hash' do
    it 'returns a new hash with applied functions' do
      map = Transproc(:map_hash, 'foo' => :foo)
{'fraction_non_alphanumeric': 0.1450381679389313, 'fraction_numerical': 0.0, 'mean_word_length': 2.5825446898002102, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '3686997', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1114, 'n_words': 354}