<commit_before>require 'spec_helper'

describe Validator do

  let(:definition) do
    Definition.new([ { position: [0,0], key: 'name' } ], Definition::MAPPING).tap do |definition|
      definition.validate!
      definition.default!
    end
  end

  subject do
    Csv2hash.new(definition, 'file_path').tap do |csv2hash|
      csv2hash.data_source = data_source
    end
  end

  describe '#message' do
    subject { Csv2hash.new double('definition', type: Definition::COLLECTION), nil }

    context 'string value' do
      let(:rule) { { foo: 'bar', message: ':foo are value of foo key' } }

      it 'substitue value of key' do
        subject.send(:message, rule, nil, nil).should eql 'bar are value of foo key'
      end
    end

    context 'array value' do
      let(:rule) { { foo: ['bar', 'zone'], message: ':foo are values of foo key' } }

      it 'substitue value of key' do
        subject.send(:message, rule, nil, nil).should eql '["bar", "zone"] are values of foo key'
      end
    end
  end

end<commit_msg>add test for message position<commit_after>require 'spec_helper'

describe Validator do

  let(:definition) do
    Definition.new([ { position: [0,0], key: 'name' } ], Definition::MAPPING).tap do |definition|
      definition.validate!
      definition.default!
    end
  end

  subject do
    Csv2hash.new(definition, 'file_path').tap do |csv2hash|
      csv2hash.data_source = data_source
    end
  end

  describe '#message' do
    subject { Csv2hash.new double('definition', type: Definition::COLLECTION), nil }

    context 'string value' do
      let(:rule) { { foo: 'bar', message: ':foo are value of foo key' } }

      it 'substitue value of key' do
        subject.send(:message, rule, nil, nil).should eql 'bar are value of foo key'
      end
    end

    context 'array value' do
      let(:rule) { { foo: ['bar', 'zone'], message: ':foo are values of foo key' } }

      it 'substitue value of key' do
        subject.send(:message, rule, nil, nil).should eql '["bar", "zone"] are values of foo key'
      end
    end

    context 'with position' do
      let(:rule) { { message: 'value not found on :position' } }

      it 'substitue value of key' do
        subject.send(:message, rule, 0, 2).should eql 'value not found on [0, 2]'
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.12429378531073447, 'fraction_numerical': 0.006953498478922208, 'mean_word_length': 2.8559463986599667, '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': '4417163', 'n_tokens_mistral': 755, 'n_tokens_neox': 715, 'n_words': 249}