<commit_before>require "test/unit"

require "dragoman"

class TestDragoman < Test::Unit::TestCase
  def setup
    @provider = OpenStruct.new
    @provider.first_name = "Walter"
    @provider.last_name = "White"
    @d = Dragoman.new
    @d.provider = @provider
  end

  def test_produces_field
    @d.learn(/FullName.*/,
             ->(first_name, middle_name, last_name) { "#{first_name} #{middle_name} #{last_name}"},
             ->(first_name, last_name) { "#{first_name} #{last_name}"})

    assert_equal "<NAME>",  @d.field("FullName")
    assert_equal "<NAME>",  @d.field("FullName1")

    @provider.middle_name = "Hartwell"

    assert_equal "<NAME>",  @d.field("FullName")
  end

  # FIXME: Return a set, not an array.
  # FIXME: What does Dragoman do in case of no matching rule?  Raise an exception?
  def test_shows_required_items
    @d.learn(/FullName.*/, ->(first_name, middle_name, last_name) { "#{first_name} #{middle_name} #{last_name}"})
    assert_equal [:first_name, :middle_name, :last_name],  @d.required_items("FullName")
  end

  def test_shows_missing_items
    @d.learn(/FullName.*/, ->(first_name, middle_name, last_name) { "#{first_name} #{middle_name} #{last_name}"})
    assert_equal [:middle_name],  @d.missing_items("FullName")
  end
end<commit_msg>Dragoman: Test that empty-string attributes count as missing<commit_after>require "test/unit"

require "dragoman"

class TestDragoman < Test::Unit::TestCase
  def setup
    @provider = OpenStruct.new
    @provider.first_name = "Walter"
    @provider.last_name = "White"
    @d = Dragoman.new
    @d.provider = @provider
  end

  def test_produces_field
    @d.learn(/FullName.*/,
             ->(first_name, middle_name, last_name) { "#{first_name} #{middle_name} #{last_name}"},
             ->(first_name, last_name) { "#{first_name} #{last_name}"})

    assert_equal "<NAME>",  @d.field("FullName")
    assert_equal "<NAME>",  @d.field("FullName1")

    @provider.middle_name = ""
    assert_equal "<NAME>",  @d.field("FullName")

    @provider.middle_name = "Hartwell"
    assert_equal "<NAME>",  @d.field("FullName")
  end

  # FIXME: Return a set, not an array.
  # FIXME: What does Dragoman do in case of no matching rule?  Raise an exception?
  def test_shows_required_items
    @d.learn(/FullName.*/, ->(first_name, middle_name, last_name) { "#{first_name} #{middle_name} #{last_name}"})
    assert_equal [:first_name, :middle_name, :last_name],  @d.required_items("FullName")
  end

  def test_shows_missing_items
    @d.learn(/FullName.*/, ->(first_name, middle_name, last_name) { "#{first_name} #{middle_name} #{last_name}"})
    assert_equal [:middle_name],  @d.missing_items("FullName")
  end
end
{'fraction_non_alphanumeric': 0.15744522836984776, 'fraction_numerical': 0.0007426661715558856, 'mean_word_length': 4.083018867924529, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 18, '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': '2614762', 'n_tokens_mistral': 949, 'n_tokens_neox': 932, 'n_words': 200}