<commit_before>require "spec_helper"

module CC::Analyzer
  describe EngineOutputFilter do
    it "does not filter arbitrary output" do
      filter = EngineOutputFilter.new

      filter.filter?("abritrary output").must_equal false
    end

    it "does not filter arbitrary json" do
      filter = EngineOutputFilter.new

      filter.filter?(%{{"arbitrary":"json"}}).must_equal false
    end

    it "does not filter issues missing or enabled in the config" do
      foo_issue = build_issue("foo")
      bar_issue = build_issue("bar")

      filter = EngineOutputFilter.new(
        "checks" => {
          "foo" => { "enabled" => true },
        }
      )

      filter.filter?(foo_issue.to_json).must_equal false
      filter.filter?(bar_issue.to_json).must_equal false
    end

    it "filters issues ignored in the config" do
      issue = build_issue("foo")

      filter = EngineOutputFilter.new(
        "checks" => {
          "foo" => { "enabled" => false },
        }
      )

      filter.filter?(issue.to_json).must_equal true
    end

    def build_issue(check_name)
      {
        "type" => EngineOutputFilter::ISSUE_TYPE,
        "check" => check_name,
      }
    end<commit_msg>Update spec to ensure a CC::Yaml object works<commit_after>require "spec_helper"

module CC::Analyzer
  describe EngineOutputFilter do
    it "does not filter arbitrary output" do
      filter = EngineOutputFilter.new

      filter.filter?("abritrary output").must_equal false
    end

    it "does not filter arbitrary json" do
      filter = EngineOutputFilter.new

      filter.filter?(%{{"arbitrary":"json"}}).must_equal false
    end

    it "does not filter issues missing or enabled in the config" do
      foo_issue = build_issue("foo")
      bar_issue = build_issue("bar")

      filter = EngineOutputFilter.new(
        engine_config(
          "checks" => {
            "foo" => { "enabled" => true },
          }
        )
      )

      filter.filter?(foo_issue.to_json).must_equal false
      filter.filter?(bar_issue.to_json).must_equal false
    end

    it "filters issues ignored in the config" do
      issue = build_issue("foo")

      filter = EngineOutputFilter.new(
        engine_config(
          "checks" => {
            "foo" => { "enabled" => false },
          }
        )
      )

      filter.filter?(issue.to_json).must_equal true
    end

    def build_issue(check_name)
      {
        "type" => EngineOutputFilter::ISSUE_TYPE,
        "check" => check_name,
      }
    end

    def engine_config(hash)
      codeclimate_yaml = {
        "engines" => {
          "rubocop" => hash.merge("enabled" => true)
        }
      }.to_yaml

      CC::Yaml.parse(codeclimate_yaml).engines["rubocop"]
    end
{'fraction_non_alphanumeric': 0.11086717892425905, 'fraction_numerical': 0.0, 'mean_word_length': 2.3300852618757615, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 22, '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': '6879467', 'n_tokens_mistral': 833, 'n_tokens_neox': 805, 'n_words': 188}