<commit_before>require File.expand_path('../../test_helper', __FILE__)

class TestRuby < Minitest::Test
  def setup
    @db = {}
    StarScope::Lang::Ruby.extract(RUBY_SAMPLE) do |tbl, name, args|
      @db[tbl] ||= []
      @db[tbl] << StarScope::Record.build(RUBY_SAMPLE, name, args)
    end
  end

  def test_recognition
    assert StarScope::Lang::Ruby.match_file(RUBY_SAMPLE)
    assert StarScope::Lang::Ruby.match_file('bin/starscope')
    refute StarScope::Lang::Ruby.match_file(GOLANG_SAMPLE)
    refute StarScope::Lang::Ruby.match_file(EMPTY_FILE)
  end

  def test_function_defs
    assert @db.keys.include? :defs
    defs = @db[:defs].map {|x| x[:name][-1]}
    assert defs.include? :DB
    assert defs.include? :NoTableError
    assert defs.include? :load
    assert defs.include? :update
    assert defs.include? :files_from_path
  end

  def test_ends
    assert @db.keys.include? :end
    assert @db[:end].count == 13<commit_msg>Test ruby constants are registered as defined<commit_after>require File.expand_path('../../test_helper', __FILE__)

class TestRuby < Minitest::Test
  def setup
    @db = {}
    StarScope::Lang::Ruby.extract(RUBY_SAMPLE) do |tbl, name, args|
      @db[tbl] ||= []
      @db[tbl] << StarScope::Record.build(RUBY_SAMPLE, name, args)
    end
  end

  def test_recognition
    assert StarScope::Lang::Ruby.match_file(RUBY_SAMPLE)
    assert StarScope::Lang::Ruby.match_file('bin/starscope')
    refute StarScope::Lang::Ruby.match_file(GOLANG_SAMPLE)
    refute StarScope::Lang::Ruby.match_file(EMPTY_FILE)
  end

  def test_function_defs
    assert @db.keys.include? :defs
    defs = @db[:defs].map {|x| x[:name][-1]}
    assert defs.include? :DB
    assert defs.include? :NoTableError
    assert defs.include? :load
    assert defs.include? :update
    assert defs.include? :files_from_path
  end

  def test_constant_defs
    assert @db[:defs].map {|x| x[:name][-1]}.include? :PBAR_FORMAT
  end

  def test_ends
    assert @db.keys.include? :end
    assert @db[:end].count == 13
{'fraction_non_alphanumeric': 0.13967310549777118, 'fraction_numerical': 0.003467062902426944, 'mean_word_length': 3.9148418491484187, 'pattern_counts': {'":': 0, '<': 9, '<?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': '3180569', 'n_tokens_mistral': 756, 'n_tokens_neox': 715, 'n_words': 143}