<commit_before>require "test_helper"

class RouterFingerprintTest < Minitest::Test
  def setup
    @fingerprint = Munge::Router::Fingerprint.new(extensions: %w(gif), separator: "--")
  end

  def new_fake_itemish
    OpenStruct.new(frontmatter: {}, compiled_content: "")
  end

  def test_match_false_because_frontmatter
    item = new_fake_itemish
    item.frontmatter[:fingerprint_asset] = false

    assert_equal false, @fingerprint.match?("cool", item)
  end

  def test_match_true_because_frontmatter
    item = new_fake_itemish
    item.frontmatter[:fingerprint_asset] = true

    assert_equal true, @fingerprint.match?("cool", item)
  end

  def test_match_because_extension
    gif_item = new_fake_itemish
    gif_item.extensions = %w(gif)

    assert_equal true, @fingerprint.match?("cool", gif_item)
  end

  def test_match_false_because_extension
    txt_item = new_fake_itemish
    txt_item.extensions = %w(txt)

    assert_equal false, @fingerprint.match?("cool", txt_item)
  end

  def test_fingerprinted_route_and_filepath
    item = new_fake_itemish

    assert_equal "transparent--#{fingerprint}.gif", @fingerprint.call("transparent.gif", item)
  end

  def test_fingerprinted_route_and_filepath_with_no_extension
    item = new_fake_itemish

    assert_equal "transparent--#{fingerprint}", @fingerprint.call("transparent", item)
  end

  def test_independence_of_route_and_filepath_and_itemroute
    item = new_fake_itemish<commit_msg>rename fingerprint test methods<commit_after>require "test_helper"

class RouterFingerprintTest < Minitest::Test
  def setup
    @fingerprint = Munge::Router::Fingerprint.new(extensions: %w(gif), separator: "--")
  end

  def new_fake_itemish
    OpenStruct.new(frontmatter: {}, compiled_content: "")
  end

  def test_match_false_because_frontmatter
    item = new_fake_itemish
    item.frontmatter[:fingerprint_asset] = false

    assert_equal false, @fingerprint.match?("cool", item)
  end

  def test_match_true_because_frontmatter
    item = new_fake_itemish
    item.frontmatter[:fingerprint_asset] = true

    assert_equal true, @fingerprint.match?("cool", item)
  end

  def test_match_because_extension
    gif_item = new_fake_itemish
    gif_item.extensions = %w(gif)

    assert_equal true, @fingerprint.match?("cool", gif_item)
  end

  def test_match_false_because_extension
    txt_item = new_fake_itemish
    txt_item.extensions = %w(txt)

    assert_equal false, @fingerprint.match?("cool", txt_item)
  end

  def test_fingerprinted_with_route_with_extension
    item = new_fake_itemish

    assert_equal "transparent--#{fingerprint}.gif", @fingerprint.call("transparent.gif", item)
  end

  def test_fingerprinted_with_route_without_extension
    item = new_fake_itemish

    assert_equal "transparent--#{fingerprint}", @fingerprint.call("transparent", item)
  end

  def test_independence_of_route_and_filepath_and_itemroute
    item = new_fake_itemish
{'fraction_non_alphanumeric': 0.09031816626753336, 'fraction_numerical': 0.0, 'mean_word_length': 4.96734693877551, 'pattern_counts': {'":': 0, '<': 5, '<?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': '906866', 'n_tokens_mistral': 1023, 'n_tokens_neox': 944, 'n_words': 168}