<commit_before>require "cutest"
require_relative "../lib/fat"

scope do
  setup do
    {
      "foo" => {
        "bar" => {
          "baz" => :found
        }
      }
    }
  end

  test "find value" do |hash|
    assert_equal :found, Fat.at(hash, "foo", "bar", "baz")
  end

  test "don't find value" do |hash|
    exception = assert_raise(Fat::FatError) { Fat.at(hash, "foo", "bar", "wat") }
    assert_equal "foo.bar.wat is nil", exception.message

    exception = assert_raise(Fat::FatError) { Fat.at(hash, "foo", "wat", "baz") }
    assert_equal "foo.wat is nil", exception.message
  end

  test "return default value" do |hash|
    assert_equal "default", Fat.at(hash, "foo", "wat", "baz", default: "default")
    assert_equal "default", Fat.at(hash, "foo", "bar", "wat", default: "default")
  end

  test "include the module" do |hash|
    Hash.include(Fat)

    assert hash.respond_to?(:at)
    assert_equal :found, hash.at("foo", "bar", "baz")
  end
end

scope do
  setup do
    {
      foo: {
        "bar" => {
          baz: :found
        }
      }
    }
  end

  test "honor key type" do |hash|
    exception = assert_raise(Fat::FatError) { Fat.at(hash, :foo, :bar, :found) }
    assert_equal "foo.bar is nil", exception.message

    assert_equal :found, Fat.at(hash, :foo, "bar", :baz)
  end
end

scope do
  setup do
    Hash.include(Fat)
  end

  test "corner case" do
    assert_raise(Fat::FatError) { {}.at(:foo, :bar) }
    assert_raise(Fat::FatError) { Fat.at({}, :foo, :bar) }
  end
end
<commit_msg>Add test for issue #5.<commit_after>require "cutest"
require_relative "../lib/fat"

scope do
  setup do
    {
      "foo" => {
        "bar" => {
          "baz" => :found
        }
      }
    }
  end

  test "find value" do |hash|
    assert_equal :found, Fat.at(hash, "foo", "bar", "baz")
  end

  test "don't find value" do |hash|
    exception = assert_raise(Fat::FatError) { Fat.at(hash, "foo", "bar", "wat") }
    assert_equal "foo.bar.wat is nil", exception.message

    exception = assert_raise(Fat::FatError) { Fat.at(hash, "foo", "wat", "baz") }
    assert_equal "foo.wat is nil", exception.message
  end

  test "return default value" do |hash|
    assert_equal "default", Fat.at(hash, "foo", "wat", "baz", default: "default")
    assert_equal "default", Fat.at(hash, "foo", "bar", "wat", default: "default")
  end

  test "include the module" do |hash|
    Hash.include(Fat)

    assert hash.respond_to?(:at)
    assert_equal :found, hash.at("foo", "bar", "baz")
  end
end

scope do
  setup do
    {
      foo: {
        "bar" => {
          baz: :found
        }
      }
    }
  end

  test "honor key type" do |hash|
    exception = assert_raise(Fat::FatError) { Fat.at(hash, :foo, :bar, :found) }
    assert_equal "foo.bar is nil", exception.message

    assert_equal :found, Fat.at(hash, :foo, "bar", :baz)
  end
end

scope do
  setup do
    Hash.include(Fat)
  end

  test "corner case: empty hashes" do
    assert_raise(Fat::FatError) { {}.at(:foo, :bar) }
    assert_raise(Fat::FatError) { Fat.at({}, :foo, :bar) }
  end

  test "corner case: lookup a single key" do
    assert_equal :found, {"foo" => :found}.at("foo")
  end
end

{'fraction_non_alphanumeric': 0.16582597730138715, 'fraction_numerical': 0.00031525851197982345, 'mean_word_length': 2.7863961813842484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '2080852', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1136, 'n_words': 311}