<commit_before>require "helper"
require "colorator"

class TestConfiguration < JekyllUnitTest
  test_config = {
    "source"      => new(nil).source_dir,
    "destination" => dest_dir,
  }

  context ".from" do
    should "create a Configuration object" do
      assert_instance_of Configuration, Configuration.from({})
    end

    should "merge input over defaults" do
      result = Configuration.from({ "source" => "blah" })
      refute_equal result["source"], Configuration::DEFAULTS["source"]
      assert_equal result["source"], "blah"
    end

    should "fix common mistakes" do
      result = Configuration.from({ "paginate" => 0 })
      assert_nil(
        result["paginate"],
        "Expected 'paginate' to be corrected to 'nil', " \
        "but was #{result["paginate"].inspect}"
      )
    end

    should "add default collections" do
      result = Configuration.from({})
      assert_equal(
        result["collections"],
        {
          "posts" => {
            "output"    => true,
            "permalink" => "/:categories/:year/:month/:day/:title:output_ext",
          },
        }
      )
    end

    should "NOT backwards-compatibilize" do
      assert(
        Configuration.from("watch" => true)["watch"],
        "Expected the 'watch' key to not be removed."
      )
    end
  end

  context "the defaults" do
    should "exclude node_modules" do
      assert_includes Configuration.from({})["exclude"], "node_modules"
    end

    should "exclude ruby vendor directories" do
      exclude = Configuration.from({})["exclude"]
      assert_includes exclude, "vendor/bundle/"
      assert_includes exclude, "vendor/cache/"
      assert_includes exclude, "vendor/gems/"
      assert_includes exclude, "vendor/ruby/"
    end
  end

  context "#add_default_collections" do
    should "no-op if collections is nil" do
      result = Configuration[{ "collections" => nil }].add_default_collections
      assert_nil result["collections"]
    end

    should "turn an array into a hash" do<commit_msg>test exclusion of Gemfile<commit_after>require "helper"
require "colorator"

class TestConfiguration < JekyllUnitTest
  test_config = {
    "source"      => new(nil).source_dir,
    "destination" => dest_dir,
  }

  context ".from" do
    should "create a Configuration object" do
      assert_instance_of Configuration, Configuration.from({})
    end

    should "merge input over defaults" do
      result = Configuration.from({ "source" => "blah" })
      refute_equal result["source"], Configuration::DEFAULTS["source"]
      assert_equal result["source"], "blah"
    end

    should "fix common mistakes" do
      result = Configuration.from({ "paginate" => 0 })
      assert_nil(
        result["paginate"],
        "Expected 'paginate' to be corrected to 'nil', " \
        "but was #{result["paginate"].inspect}"
      )
    end

    should "add default collections" do
      result = Configuration.from({})
      assert_equal(
        result["collections"],
        {
          "posts" => {
            "output"    => true,
            "permalink" => "/:categories/:year/:month/:day/:title:output_ext",
          },
        }
      )
    end

    should "NOT backwards-compatibilize" do
      assert(
        Configuration.from("watch" => true)["watch"],
        "Expected the 'watch' key to not be removed."
      )
    end
  end

  context "the defaults" do
    should "exclude node_modules" do
      assert_includes Configuration.from({})["exclude"], "node_modules"
    end

    should "exclude ruby vendor directories" do
      exclude = Configuration.from({})["exclude"]
      assert_includes exclude, "Gemfile"
      assert_includes exclude, "Gemfile.lock"
      assert_includes exclude, "vendor/bundle/"
      assert_includes exclude, "vendor/cache/"
      assert_includes exclude, "vendor/gems/"
      assert_includes exclude, "vendor/ruby/"
    end
  end

  context "#add_default_collections" do
    should "no-op if collections is nil" do
      result = Configuration[{ "collections" => nil }].add_default_collections
      assert_nil result["collections"]
    end

    should "turn an array into a hash" do
{'fraction_non_alphanumeric': 0.11870936672285096, 'fraction_numerical': 0.0004815795810257645, 'mean_word_length': 2.712243074173369, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '6314452', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1152, 'n_words': 320}