<commit_before>require "test/unit"
require 'fileutils'
require "conveyor/channel"

class TestConveyorChannel < Test::Unit::TestCase
  include Conveyor
  def test_init
    FileUtils.rm_r('/tmp/bar')
    assert_nothing_raised do
      Channel.new '/tmp/bar'
    end
  end

  def test_post
    FileUtils.rm_r('/tmp/bar')
    assert_nothing_raised do
      w = Channel.new '/tmp/bar'
      w.post 'foo'
      assert_equal 1, w.instance_variable_get(:@last_id)
    end
  end

  def test_parse_headers
    FileUtils.rm_r '/tmp/foo' rescue nil

    i = Channel.new '/tmp/foo'
    [
      ["1 jucfvs 0 3 acbd18db4cc2f85cedef654fccc4a4d8 0\n", 
       {:id => 1, :time => 1199826280, :offset => 0, :length => 3, :hash => "acbd18db4cc2f85cedef654fccc4a4d8", :file => nil, :flags => 0}
      ]
    ].each do |(str, ret)|
      assert_equal ret, i.parse_headers(str)
    end
    
    [
      ["2 jucfvs 0 3 acbd18db4cc2f85cedef654fccc4a4d8 0 1\n", 
       {:id => 2, :time => 1199826280, :offset => 0, :length => 3, :hash => "acbd18db4cc2f85cedef654fccc4a4d8", :file => 1, :flags => 0}
      ]
    ].each do |(str, ret)|
      assert_equal ret, i.parse_headers(str, true)
    end
    
    FileUtils.rm_r '/tmp/foo'
  end

  def test_init_existing
    FileUtils.rm_r('/tmp/bar') rescue nil
    c = Channel.new('/tmp/bar')
    c.post 'foo'
    c.post 'bar'
    c = nil
    GC.start
    
    d = Channel.new('/tmp/bar')
    assert_equal 'foo', d.get(1)[1]<commit_msg>whoops. forget to change second reference to that variable<commit_after>require "test/unit"
require 'fileutils'
require "conveyor/channel"

class TestConveyorChannel < Test::Unit::TestCase
  include Conveyor
  def test_init
    FileUtils.rm_r('/tmp/bar')
    assert_nothing_raised do
      Channel.new '/tmp/bar'
    end
  end

  def test_post
    FileUtils.rm_r('/tmp/bar')
    assert_nothing_raised do
      w = Channel.new '/tmp/bar'
      w.post 'foo'
      assert_equal 1, w.instance_variable_get(:@last_id)
    end
  end

  def test_parse_headers
    [
      ["1 jucfvs 0 3 acbd18db4cc2f85cedef654fccc4a4d8 0\n", 
       {:id => 1, :time => 1199826280, :offset => 0, :length => 3, :hash => "acbd18db4cc2f85cedef654fccc4a4d8", :file => nil, :flags => 0}
      ]
    ].each do |(str, ret)|
      assert_equal ret, Channel.parse_headers(str)
    end
    
    [
      ["2 jucfvs 0 3 acbd18db4cc2f85cedef654fccc4a4d8 0 1\n", 
       {:id => 2, :time => 1199826280, :offset => 0, :length => 3, :hash => "acbd18db4cc2f85cedef654fccc4a4d8", :file => 1, :flags => 0}
      ]
    ].each do |(str, ret)|
      assert_equal ret, Channel.parse_headers(str, true)
    end
  end

  def test_init_existing
    FileUtils.rm_r('/tmp/bar') rescue nil
    c = Channel.new('/tmp/bar')
    c.post 'foo'
    c.post 'bar'
    c = nil
    GC.start
    
    d = Channel.new('/tmp/bar')
    assert_equal 'foo', d.get(1)[1]
{'fraction_non_alphanumeric': 0.1377497371188223, 'fraction_numerical': 0.06239046617595514, 'mean_word_length': 2.740498034076016, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '4971058', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1107, 'n_words': 246}