<commit_before>$VERBOSE = true
require File.dirname(__FILE__) + '/test_helper.rb'

TEXT =<<EOD
class MyClass
  class MyException < StandardError; end

  class << self
    def method
      :end
    end
  end

  attr_reader :end

  def method
    :end
  end
end
EOD

SECTIONS = [
'class MyClass
  class MyException < StandardError; end
',
'
  class << self
    def method
      :end
    end
',
'  end
',
'
  attr_reader :end

  def method
    :end
  end
',
'end
'
]

REGEXP_SEPARATER = /\send\n?/

class TestStringEachSection < Test::Unit::TestCase
  def setup
    @string = TEXT
  end
  
  def test_each_section_with_block
    sections = []

    @string.each_section REGEXP_SEPARATER do |str|
      sections << str
    end
    
    assert_equal sections, SECTIONS
  end
  
  def test_each_section_to_enum
    enum = @string.sections REGEXP_SEPARATER
    result = enum.with_index.map{|s, i|"#{s}#{i}"}.join
    expect = SECTIONS.each.with_index.map{|s, i|"#{s}#{i}"}.join
    
    assert_equal result, expect
  end
end

class TestIOEachSection < Test::Unit::TestCase
  def setup
    @io = StringIO.new TEXT
  end

  def test_each_section_with_block
    sections = []

    @io.each_section REGEXP_SEPARATER do |str|
      sections << str
    end
    
    assert_equal sections, SECTIONS
  end
  
  def test_each_section_to_enum
    enum = @io.sections REGEXP_SEPARATER
    result = enum.with_index.map{|s, i|"#{s}#{i}"}.join
    expect = SECTIONS.each.with_index.map{|s, i|"#{s}#{i}"}.join
    
    assert_equal result, expect
  end
end
<commit_msg>Refactor test<commit_after>$VERBOSE = true
require File.dirname(__FILE__) + '/test_helper.rb'

TEXT =<<EOD
class MyClass
  class MyException < StandardError; end

  class << self
    def method
      :end
    end
  end

  attr_reader :end

  def method
    :end
  end
end
EOD

SECTIONS = [
'class MyClass
  class MyException < StandardError; end
',
'
  class << self
    def method
      :end
    end
',
'  end
',
'
  attr_reader :end

  def method
    :end
  end
',
'end
'
]

module TestableEachSection
  REGEXP_SEPARATER = /\send\n?/
  
  attr_reader :reciever
  
  def test_each_section_with_block
    sections = []

    reciever.each_section REGEXP_SEPARATER do |str|
      sections << str
    end
    
    assert_equal sections, SECTIONS
  end
  
  def test_each_section_to_enum
    enum = reciever.sections REGEXP_SEPARATER
    result = enum.with_index.map{|s, i|"#{s}#{i}"}.join
    expect = SECTIONS.each.with_index.map{|s, i|"#{s}#{i}"}.join
    
    assert_equal result, expect
  end
end

class TestStringEachSection < Test::Unit::TestCase
  include TestableEachSection
  
  def setup
    @reciever = TEXT
  end
end

class TestIOEachSection < Test::Unit::TestCase
  include TestableEachSection
  
  def setup
    @reciever = StringIO.new TEXT
  end
end
{'fraction_non_alphanumeric': 0.10042735042735043, 'fraction_numerical': 0.0, 'mean_word_length': 2.934173669467787, 'pattern_counts': {'":': 0, '<': 29, '<?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': '2068971', 'n_tokens_mistral': 1033, 'n_tokens_neox': 1006, 'n_words': 237}