<commit_before>require 'rspec'
require 'awesome_print'
require 'pp'
require 'pry'
require 'pretty_backtrace'
require 'ruby-prof'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))

# PrettyBacktrace.enable

require 'rubex'

def dir_str test_case
  "#{Dir.pwd}/spec/fixtures/#{test_case}"
end

def path_str test_case, example=nil
  example = test_case if example.nil?
  "#{Dir.pwd}/spec/fixtures/#{test_case}/#{example}"
end

def generate_shared_object test_case, example=nil
  path = path_str test_case, example
  dir = dir_str test_case

  Rubex::Compiler.compile(path + '.rubex', directory: dir)
  Dir.chdir(dir) do
    `ruby extconf.rb`
    `make`
  end
end

def delete_generated_files test_case, example=nil
  dir = dir_str test_case
  test_case = example if example
  Dir.chdir(dir) do
    [
      "#{test_case}.c", "#{test_case}.so", "Makefile",
      "extconf.rb"    , "#{test_case}.o"
    ].each do |f|
      FileUtils.rm f
    end
  end
end

def setup_and_teardown_compiled_files test_case, example=nil, &block
  generate_shared_object test_case, example
  dir = dir_str test_case
  begin
    block.call(dir)
  ensure
    delete_generated_files test_case, example
  end
end

def expect_compiled_code code, path
  expect(code.to_s).to eq(File.read(path))<commit_msg>allow support for .bundle files and .dll files teardown in specs<commit_after>require 'rspec'
require 'awesome_print'
require 'pp'
require 'pry'
require 'pretty_backtrace'
require 'ruby-prof'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))

# PrettyBacktrace.enable

require 'rubex'

def dir_str test_case
  "#{Dir.pwd}/spec/fixtures/#{test_case}"
end

def path_str test_case, example=nil
  example = test_case if example.nil?
  "#{Dir.pwd}/spec/fixtures/#{test_case}/#{example}"
end

def generate_shared_object test_case, example=nil
  path = path_str test_case, example
  dir = dir_str test_case

  Rubex::Compiler.compile(path + '.rubex', directory: dir)
  Dir.chdir(dir) do
    `ruby extconf.rb`
    `make`
  end
end

def delete_generated_files test_case, example=nil
  dir = dir_str test_case
  test_case = example if example
  Dir.chdir(dir) do
    [
      "#{test_case}.c", "#{test_case}.so", "Makefile",
      "extconf.rb"    , "#{test_case}.o", "#{test_case}.bundle",
      "#{test_case}.dll"

    ].each do |f|
      FileUtils.rm(f) if File.exist?(f)
    end
  end
end

def setup_and_teardown_compiled_files test_case, example=nil, &block
  generate_shared_object test_case, example
  dir = dir_str test_case
  begin
    block.call(dir)
  ensure
    delete_generated_files test_case, example
  end
end

def expect_compiled_code code, path
  expect(code.to_s).to eq(File.read(path))
{'fraction_non_alphanumeric': 0.12410329985652797, 'fraction_numerical': 0.0, 'mean_word_length': 4.405038759689923, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2054512', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1023, 'n_words': 224}