Sha256: 5fdde6eebd1409de0eec430d73101eb7a18966c46a9b228dead5b522e24e6af4

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

# encoding: UTF-8

require "spec"
require "spec_helper"

describe Integer do
  describe "#bencodr" do
    it "should encode a positive integer" do
      1.bencode.should == "i1e"
    end

    it "should encode a negative integer" do
      -1.bencode.should == "i-1e"
    end

    it "should encode a positive big integer" do
      10_000_000_000.bencode.should == "i10000000000e"
    end

    it "should encode a negative big integer" do
      -10_000_000_000.bencode.should == "i-10000000000e"
    end
  end
end

describe Numeric do
  describe "#bencodr" do
    it "should encode a positive float with precision loss" do
      1.1.bencode.should == "i1e"
    end

    it "should encode a negative float with precision loss" do
      -1.1.bencode.should == "i-1e"
    end

    it "should encode an positive exponential float" do
      1e10.bencode.should == "i10000000000e"
    end

    it "should encode an negative exponential float" do
      -1e10.bencode.should == "i-10000000000e"
    end
  end
end

describe Time do
  describe "#bencodr" do
    it "should encode to bencoding" do
      Time.at(4).bencode.should == "i4e"
    end
  end
end

describe BEncodr::Integer do
  describe "#register" do
    context "once an object has been registered as a BEncode integer" do
      before :all do
        BEncodr::Integer.register NilClass
      end

      context "an instance of that object" do
        it "should respond to bencodr" do
          nil.should respond_to :bencode
        end

        it "should encode to a bencoded integer" do
          nil.bencode.should == "i0e"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bencodr-1.2.0 spec/bencodr/integer_spec.rb
bencodr-1.1.0 spec/bencodr/integer_spec.rb
bencodr-1.0.1 spec/bencodr/integer_spec.rb