Sha256: 0f56aca935a3da6be6ee29759d4688165ce296993d8df71e905ca307c70a23a3

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

require 'spec_helper'


describe XDR::String, "#read" do
  subject{ XDR::String.new(3) }

  it "decodes values correctly" do
    expect(read("\x00\x00\x00\x00")).to eq("")
    expect(read("\x00\x00\x00\x01h\x00\x00\x00")).to eq("h")
    expect(read("\x00\x00\x00\x02hi\x00\x00")).to eq("hi")
  end

  it "raises a ReadError when the encoded length is greater than the allowed max" do
    expect{ read "\x00\x00\x00\x04hiya" }.to raise_error(XDR::ReadError)
  end

  def read(str)
    io = StringIO.new(str)
    subject.read(io)
  end
end

describe XDR::String, "#write" do
  subject{ XDR::String[2] }

  it "encodes values correctly" do
    expect(write("")).to eq("\x00\x00\x00\x00")
    expect(write("h")).to eq("\x00\x00\x00\x01h\x00\x00\x00")
    expect(write("hi")).to eq("\x00\x00\x00\x02hi\x00\x00")
  end

  it "raises a WriteError when the provided string is too long" do
    expect{ write "123" }.to raise_error(XDR::WriteError)
  end

  def write(val)
    io = StringIO.new()
    subject.write(val, io)
    io.string
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
payshares-xdr-0.0.2 spec/lib/xdr/string_spec.rb
xdr-2.0.0 spec/lib/xdr/string_spec.rb
xdr-1.0.0 spec/lib/xdr/string_spec.rb
xdr-0.1.0 spec/lib/xdr/string_spec.rb
xdr-0.0.4 spec/lib/xdr/string_spec.rb
xdr-0.0.3 spec/lib/xdr/string_spec.rb
xdr-0.0.2 spec/lib/xdr/string_spec.rb
xdr-0.0.1 spec/lib/xdr/string_spec.rb