<commit_before>require "ruby_parser"
require "ruby2ruby"
require_relative "processor"
require_relative "errors"

module MinitestToRspec
  class Converter
    def initialize(options)
      @options = options
      @processor = Processor.new(@options[:rails_helper])
    end

    def convert(input)
      render process parse input
    end

    private

    # Parses an input string using the `ruby_parser` gem, and
    # returns an Abstract Syntax Tree (AST) in the form of
    # S-expressions.
    #
    # Example of AST
    # --------------
    #
    # s(:block,
    #   s(:call, nil, :require, s(:str, "test_helper")),
    #   s(:class,
    #     :BananaTest,
    #     s(:colon2, s(:const, :ActiveSupport), :TestCase),
    #     s(:iter,
    #       s(:call, nil, :test, s(:str, "is delicious")),
    #       s(:args),
    #       s(:call, nil, :assert,
    #         s(:call, s(:call, s(:const, :Banana), :new), :delicious?)
    #       )
    #     )
    #   )
    # )
    #
    def parse(input)
      RubyParser.new.parse(input)
    end

    # Processes an AST (S-expressions) representing a minitest
    # file, and returns an AST (still S-expressions) representing
    # an rspec file.
    def process(exp)
      @processor.process(exp)
    end

    # Given an AST representing an rspec file, returns a string
    # of ruby code.
    def render(exp)
      ruby2ruby.process(exp)
    end

    def ruby2ruby
      Ruby2Ruby.new(hash_syntax: :ruby19)
    rescue ArgumentError
      Ruby2Ruby.new
    end
  end
end
<commit_msg>Comment re: ruby2ruby hash_syntax option<commit_after>require "ruby_parser"
require "ruby2ruby"
require_relative "processor"
require_relative "errors"

module MinitestToRspec
  class Converter
    def initialize(options)
      @options = options
      @processor = Processor.new(@options[:rails_helper])
    end

    def convert(input)
      render process parse input
    end

    private

    # Parses an input string using the `ruby_parser` gem, and
    # returns an Abstract Syntax Tree (AST) in the form of
    # S-expressions.
    #
    # Example of AST
    # --------------
    #
    # s(:block,
    #   s(:call, nil, :require, s(:str, "test_helper")),
    #   s(:class,
    #     :BananaTest,
    #     s(:colon2, s(:const, :ActiveSupport), :TestCase),
    #     s(:iter,
    #       s(:call, nil, :test, s(:str, "is delicious")),
    #       s(:args),
    #       s(:call, nil, :assert,
    #         s(:call, s(:call, s(:const, :Banana), :new), :delicious?)
    #       )
    #     )
    #   )
    # )
    #
    def parse(input)
      RubyParser.new.parse(input)
    end

    # Processes an AST (S-expressions) representing a minitest
    # file, and returns an AST (still S-expressions) representing
    # an rspec file.
    def process(exp)
      @processor.process(exp)
    end

    # Given an AST representing an rspec file, returns a string
    # of ruby code.
    def render(exp)
      ruby2ruby.process(exp)
    end

    # Try to specify ruby 1.9 hash_syntax if ruby2ruby supports it.
    # https://github.com/seattlerb/ruby2ruby/pull/37
    def ruby2ruby
      Ruby2Ruby.new(hash_syntax: :ruby19)
    rescue ArgumentError
      Ruby2Ruby.new
    end
  end
end

{'fraction_non_alphanumeric': 0.12250623441396509, 'fraction_numerical': 0.007169576059850374, 'mean_word_length': 2.2912820512820513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '4534557', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1038, 'n_words': 279}