<commit_before>
# frozen_string_literal: true

# Adds some nice assertions for testing if a match is found or not, and
# testing the behavior of the not_exists variant at the same time.

# TODO: make the ... be the actual arguments

module Minitest::Assertions
  [:assert_exists_with_matching,
   :assert_exists_without_matching,
   :assert_wa_count,
   :assert_wa_count_full,
   :assert_wa_count_specific,
   ].each do |shortcut|
    define_method shortcut do |*args, &block|
      send("#{shortcut}_from", S0, *args, &block)
    end
  end

  def assert_exists_with_matching_from(start_from, association_name, *args, &block)
    msgs = []
    if !start_from.where_assoc_exists(association_name, *args, &block).exists?
      msgs << "Expected a match but got none for S0.where_assoc_exists(#{association_name.inspect}, ...)"
    end

    if start_from.where_assoc_not_exists(association_name, *args, &block).exists?
      msgs << "Expected no matches but got one for S0.where_assoc_not_exists(#{association_name.inspect}, ...)"
    end
    assert msgs.empty?, msgs.map { |s| "  #{s}" }.join("\n")<commit_msg>Fix locations given by minitest when failures occur<commit_after>
# frozen_string_literal: true

# Adds some nice assertions for testing if a match is found or not, and
# testing the behavior of the not_exists variant at the same time.

# TODO: make the ... be the actual arguments

module Minitest::Assertions
  [:assert_exists_with_matching,
   :assert_exists_without_matching,
   :assert_wa_count,
   :assert_wa_count_full,
   :assert_wa_count_specific,
   ].each do |shortcut|
    # Using class eval to define a real method instead of using #define_method
    # #define_method made minitest not give the right location for where the assert
    # happened because it scans the backtrace for the first non-assert-like method,
    # and the #define_method added an extra block which wasn't filtered.
    class_eval <<-RUBY, __FILE__, __LINE__ + 1
      def #{shortcut}(*args, &block)
        #{shortcut}_from(S0, *args, &block)
      end
    RUBY
  end

  def assert_exists_with_matching_from(start_from, association_name, *args, &block)
    msgs = []
    if !start_from.where_assoc_exists(association_name, *args, &block).exists?
      msgs << "Expected a match but got none for S0.where_assoc_exists(#{association_name.inspect}, ...)"
    end

    if start_from.where_assoc_not_exists(association_name, *args, &block).exists?
      msgs << "Expected no matches but got one for S0.where_assoc_not_exists(#{association_name.inspect}, ...)"
    end
    assert msgs.empty?, msgs.map { |s| "  #{s}" }.join("\n")
{'fraction_non_alphanumeric': 0.10317157050057317, 'fraction_numerical': 0.0026748184944593045, 'mean_word_length': 4.123287671232877, 'pattern_counts': {'":': 0, '<': 13, '<?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': '1531523', 'n_tokens_mistral': 859, 'n_tokens_neox': 841, 'n_words': 246}