<commit_before>require "spec_helper"

describe Runivedo::UStream do
  describe "sending" do
    let(:message) { Runivedo::UStream::Message.new }

    it "sends null" do
      message << nil
      message.buffer.should == "\x00"
    end

    it "sends bools" do
      message << true
      message << false
      message.buffer.should == "\x01\x01\x01\x00"
    end

    it "sends integers" do
      message << 42
      message.buffer.should == "\x0D\x2A" + "\x00" * 7
    end

    it "sends floats" do
      message << 8.0e-323
      message.buffer.should == "\x15\x10" + "\x00" * 7
    end

    it "sends strings" do
      message << "foobar"
      message.buffer.should == "\x1e\x06\x00\x00\x00foobar"
    end

    it "sends arrays" do
      message << %w(foo bar)
      message.buffer.should == "\x3c\x02\x00\x00\x00\x1e\x03\x00\x00\x00foo\x1e\x03\x00\x00\x00bar"
    end

    it "sends maps" do
      message << {"foo" => true, "bar" => false}
      message.buffer.should == "\x3d\x02\x00\x00\x00\x1e\x03\x00\x00\x00foo\x01\x01\x1e\x03\x00\x00\x00bar\x01\x00"
    end
  end

  describe "receiving" do
    let(:message) { Runivedo::UStream::Message.new }

    it "receives null" do
      message.instance_variable_set(:@buffer, "\x00")
      message.read.should == nil
    end

    it "receives bools" do
      message.instance_variable_set(:@buffer, "\x01\x00")
      message.read.should == false
      message.instance_variable_set(:@buffer, "\x01\x01")
      message.read.should == true
    end

    it "receives integers" do
      {10 => 1, 11 => 2, 12 => 4, 13 => 8, 15 => 1, 16 => 2, 17 => 4, 18 => 8}.each_pair do |i, s|
        message.instance_variable_set(:@buffer, [i].pack("C") + "\x2A" + "\x00" * (s-1))
        message.read.should == 42
      end
    end

    it "receives floats" do
      message.instance_variable_set(:@buffer, "\x14\x10" + "\x00" * 3)
      message.read.should == 2.2420775429197073e-44
      message.instance_variable_set(:@buffer, "\x15\x10" + "\x00" * 7)
      message.read.should == 8.0e-323
    end

    it "receives strings" do
      message.instance_variable_set(:@buffer, "\x1e\x06\x00\x00\x00foobar")
      message.read.should == "foobar"
      message.instance_variable_set(:@buffer, "\x1f\x06\x00\x00\x00f\x00o\x00o\x00b\x00a\x00r\x00")
      message.read.should == "foobar"
    end

    it "receives arrays" do
      message.instance_variable_set(:@buffer, "\x3c\x02\x00\x00\x00\x1e\x03\x00\x00\x00foo\x1e\x03\x00\x00\x00bar")
      message.read.should == %w(foo bar)
    end

    it "receives maps" do
      message.instance_variable_set(:@buffer, "\x3d\x02\x00\x00\x00\x1e\x03\x00\x00\x00foo\x0a\x01\x1e\x03\x00\x00\x00bar\x0a\x02")
      message.read.should == {"foo" => 1, "bar" => 2}
    end
  end

  describe "sending and receiving" do
    let(:message) { Runivedo::UStream::Message.new }

    it "works for null" do
      message << nil
      message.read.should == nil
    end

    it "works for bools" do
      message << true
      message.read.should == true
      message << false
      message.read.should == false
    end

    it "works for ints" do
      message << 42
      message.read.should == 42
    end
<commit_msg>tests<commit_after>require "spec_helper"

describe Runivedo::UStream do
  describe "sending" do
    let(:message) { Runivedo::UStream::Message.new }

    it "sends null" do
      message << nil
      message.buffer.should == "\x00"
    end

    it "sends bools" do
      message << true
      message << false
      message.buffer.should == "\x01\x01\x01\x00"
    end

    it "sends integers" do
      message << 42
      message.buffer.should == "\x0D\x2A" + "\x00" * 7
    end

    it "sends floats" do
      message << 8.0e-323
      message.buffer.should == "\x15\x10" + "\x00" * 7
    end

    it "sends strings" do
      message << "foobar"
      message.buffer.should == "\x1e\x06\x00\x00\x00foobar"
    end

    it "sends arrays" do
      message << %w(foo bar)
      message.buffer.should == "\x3c\x02\x00\x00\x00\x1e\x03\x00\x00\x00foo\x1e\x03\x00\x00\x00bar"
    end

    it "sends maps" do
      message << {"foo" => true, "bar" => false}
      message.buffer.should == "\x3d\x02\x00\x00\x00\x1e\x03\x00\x00\x00foo\x01\x01\x1e\x03\x00\x00\x00bar\x01\x00"
    end
  end

  describe "receiving" do
    let(:message) { Runivedo::UStream::Message.new }

    it "receives null" do
      message.instance_variable_set(:@buffer, "\x00")
      message.read.should == nil
    end

    it "receives bools" do
      message.instance_variable_set(:@buffer, "\x01\x00")
      message.read.should == false
      message.instance_variable_set(:@buffer, "\x01\x01")
      message.read.should == true
    end

    it "receives integers" do
      {10 => 1, 11 => 2, 12 => 4, 13 => 8, 15 => 1, 16 => 2, 17 => 4, 18 => 8}.each_pair do |i, s|
        message.instance_variable_set(:@buffer, [i].pack("C") + "\x2A" + "\x00" * (s-1))
        message.read.should == 42
      end
    end

    it "receives floats" do
      message.instance_variable_set(:@buffer, "\x14\x10" + "\x00" * 3)
      message.read.should == 2.2420775429197073e-44
      message.instance_variable_set(:@buffer, "\x15\x10" + "\x00" * 7)
      message.read.should == 8.0e-323
    end

    it "receives strings" do
      message.instance_variable_set(:@buffer, "\x1e\x06\x00\x00\x00foobar")
      message.read.should == "foobar"
      message.instance_variable_set(:@buffer, "\x1f\x06\x00\x00\x00f\x00o\x00o\x00b\x00a\x00r\x00")
      message.read.should == "foobar"
    end

    it "receives arrays" do
      message.instance_variable_set(:@buffer, "\x3c\x02\x00\x00\x00\x1e\x03\x00\x00\x00foo\x1e\x03\x00\x00\x00bar")
      message.read.should == %w(foo bar)
    end

    it "receives maps" do
      message.instance_variable_set(:@buffer, "\x3d\x02\x00\x00\x00\x1e\x03\x00\x00\x00foo\x0a\x01\x1e\x03\x00\x00\x00bar\x0a\x02")
      message.read.should == {"foo" => 1, "bar" => 2}
    end

    it "receives remote object ids" do
      message.instance_variable_set(:@buffer, "\x2d\x2a\x00\x00\x00\x1e\x03\x00\x00\x00foo")
      message.read.should == 42
    end
  end

  describe "sending and receiving" do
    let(:message) { Runivedo::UStream::Message.new }

    it "works for null" do
      message << nil
      message.read.should == nil
    end

    it "works for bools" do
      message << true
      message.read.should == true
      message << false
      message.read.should == false
    end

    it "works for ints" do
      message << 42
      message.read.should == 42
    end

{'fraction_non_alphanumeric': 0.15429358640746976, 'fraction_numerical': 0.08679014235420174, 'mean_word_length': 2.433526011560694, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 27, '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': '6774254', 'n_tokens_mistral': 2907, 'n_tokens_neox': 2540, 'n_words': 485}