<commit_before>require File.join(File.dirname(__FILE__), "redirect_check")
require File.join(File.dirname(__FILE__), "resource_path")
require 'test/unit'

class HTTPRedirectTest < Test::Unit::TestCase
  # permanent can be overriden in 2 ways, with a call to self.permanent to set globally. Or via the options array for each redirect call
  @permanent=nil

  def default_test; end # placeholder to stop Test::Unit from complaining

  class <<self
    def domain=(domain)
      @domain = domain
    end

    def domain
      @domain
    end

    def permanent=(permanent)
      @permanent=permanent
    end

    def permanent?
      @permanent.nil? ? false : true
    end

    def should_not_redirect(path)
      class_eval <<-CODE
        def test_#{name_for(path)}_should_not_redirect
          check = RedirectCheck.new(self.class.domain, '#{path}')
          assert_equal false, check.redirected?, "#{path} is redirecting"
          assert_equal true, check.success?, "#{path} is not a success response"
        end
      CODE
    end

    def name_for(path)
      name = path.gsub(/\W+/, '_')
      name.gsub!(/^_+/, '')
      name.gsub!(/_+$/, '')

      name = 'root' if name == ''

      name
    end

    def should_redirect(source, options)<commit_msg>Use core metaprogramming to make this more succinct.<commit_after>require File.join(File.dirname(__FILE__), "redirect_check")
require File.join(File.dirname(__FILE__), "resource_path")
require 'test/unit'

class HTTPRedirectTest < Test::Unit::TestCase
  # permanent can be overriden in 2 ways, with a call to self.permanent to set globally. Or via the options array for each redirect call
  @permanent=nil

  def default_test; end # placeholder to stop Test::Unit from complaining

  class <<self
    attr_accessor :domain
    attr_writer :permanent

    def permanent?
      @permanent.nil? ? false : true
    end

    def should_not_redirect(path)
      class_eval <<-CODE
        def test_#{name_for(path)}_should_not_redirect
          check = RedirectCheck.new(self.class.domain, '#{path}')
          assert_equal false, check.redirected?, "#{path} is redirecting"
          assert_equal true, check.success?, "#{path} is not a success response"
        end
      CODE
    end

    def name_for(path)
      name = path.gsub(/\W+/, '_')
      name.gsub!(/^_+/, '')
      name.gsub!(/_+$/, '')

      name = 'root' if name == ''

      name
    end

    def should_redirect(source, options)
{'fraction_non_alphanumeric': 0.11333061557276804, 'fraction_numerical': 0.0008153281695882593, 'mean_word_length': 2.964458804523425, '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': '1551421', 'n_tokens_mistral': 773, 'n_tokens_neox': 746, 'n_words': 213}