<commit_before>require 'spec_helper'

describe 'default coercions' do
  def test_coercion(key, value, expected)
    coercion = Parametric.registry.coercions[key]
    expect(coercion.new.coerce(value, nil, nil)).to eq expected
  end

  describe ':datetime' do
    it {
      coercion = Parametric.registry.coercions[:datetime]
      coercion.new.coerce("2016-11-05T14:23:34Z", nil, nil).tap do |d|
        expect(d).to be_a Date
        expect(d.year).to eq 2016
        expect(d.month).to eq 11
        expect(d.day).to eq 5
        expect(d.hour).to eq 14
        expect(d.minute).to eq 23
        expect(d.second).to eq 34
        expect(d.zone).to eq "+00:00"
      end
    }
  end

  describe ':integer' do
    it {
      test_coercion(:integer, '10', 10)
      test_coercion(:integer, '10.20', 10)
      test_coercion(:integer, 10.20, 10)
      test_coercion(:integer, 10, 10)
    }
  end
<commit_msg>not using that method anymore, should deprecate soon<commit_after>require 'spec_helper'

describe 'default coercions' do
  def test_coercion(key, value, expected)
    coercion = Parametric.registry.policies[key]
    expect(coercion.new.coerce(value, nil, nil)).to eq expected
  end

  describe ':datetime' do
    it {
      coercion = Parametric.registry.coercions[:datetime]
      coercion.new.coerce("2016-11-05T14:23:34Z", nil, nil).tap do |d|
        expect(d).to be_a Date
        expect(d.year).to eq 2016
        expect(d.month).to eq 11
        expect(d.day).to eq 5
        expect(d.hour).to eq 14
        expect(d.minute).to eq 23
        expect(d.second).to eq 34
        expect(d.zone).to eq "+00:00"
      end
    }
  end

  describe ':integer' do
    it {
      test_coercion(:integer, '10', 10)
      test_coercion(:integer, '10.20', 10)
      test_coercion(:integer, 10.20, 10)
      test_coercion(:integer, 10, 10)
    }
  end

{'fraction_non_alphanumeric': 0.12702702702702703, 'fraction_numerical': 0.055135135135135134, 'mean_word_length': 2.615234375, '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': '7111195', 'n_tokens_mistral': 750, 'n_tokens_neox': 657, 'n_words': 151}