<commit_before>#encoding: UTF-8

require 'spec_helper'
require 'travis/worker/utils/buffer'

describe Travis::Worker::Utils::Buffer do
  let(:result) { [] }
  let(:buffer) { Travis::Worker::Utils::Buffer.new(nil) { |data| result << data } }

  it 'buffers' do
    buffer << 'foo'
    buffer << 'bar'
    buffer.send(:flush)

    buffer << 'baz'
    buffer.send(:flush)

    result.should == ['foobar', 'baz']
  end

  it 'raises a OutputLimitExceeded exception when the log gets too long' do
    buffer.expects(:bytes_limit).at_least_once.returns(10)
    buffer << '12345'
    buffer << '12345'
    lambda { buffer << '12345' }.should raise_error(Travis::Worker::Utils::Buffer::OutputLimitExceededError)
  end

  it 'limits each part to given "chunk_size", taking json conversion into account' do
    buffer = Travis::Worker::Utils::Buffer.new(nil, :limit => 20, :chunk_size => 5) { |data| result << data }

    buffer << '1ą234512345'
    buffer.send(:flush)

    result.should == ["1ą", "234", "512", "345"]
  end
end<commit_msg>Fixed Buffer spec<commit_after>#encoding: UTF-8

require 'spec_helper'
require 'travis/worker/utils/buffer'

describe Travis::Worker::Utils::Buffer do
  let(:result) { [] }
  let(:buffer) { Travis::Worker::Utils::Buffer.new(nil) { |data| result << data } }

  it 'buffers' do
    buffer << 'foo'
    buffer << 'bar'
    buffer.send(:flush)

    buffer << 'baz'
    buffer.send(:flush)

    result.should == ['foobar', 'baz']
  end

  it 'raises a OutputLimitExceeded exception when the log gets too long' do
    buffer.expects(:bytes_limit).at_least_once.returns(10)
    buffer << '12345'
    buffer << '12345'
    lambda { buffer << '12345' }.should raise_error(Travis::Worker::Utils::Buffer::OutputLimitExceededError)
  end

  it 'limits each part to given "chunk_size", taking json conversion into account' do
    buffer = Travis::Worker::Utils::Buffer.new(nil, :limit => 20, :chunk_size => 5) { |data| result << data }

    buffer << '1ą234512345'
    buffer.send(:flush)

    result.should == ["1", "ą", "234", "512", "345"]
  end
end
{'fraction_non_alphanumeric': 0.16183574879227053, 'fraction_numerical': 0.03961352657004831, 'mean_word_length': 4.026699029126213, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 7, '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': '3069356', 'n_tokens_mistral': 761, 'n_tokens_neox': 672, 'n_words': 172}