xdr 0.1.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +31 -0
- data/README.md +7 -2
- data/lib/xdr.rb +0 -1
- data/lib/xdr/concerns/converts_to_xdr.rb +47 -24
- data/lib/xdr/concerns/reads_bytes.rb +8 -0
- data/lib/xdr/dsl/enum.rb +1 -1
- data/lib/xdr/opaque.rb +1 -1
- data/lib/xdr/string.rb +1 -1
- data/lib/xdr/struct.rb +1 -1
- data/lib/xdr/union.rb +15 -6
- data/lib/xdr/var_opaque.rb +1 -1
- data/lib/xdr/version.rb +1 -1
- metadata +47 -133
- data/.gitignore +0 -15
- data/.travis.yml +0 -14
- data/.yardopts +0 -7
- data/Gemfile +0 -4
- data/Guardfile +0 -5
- data/Rakefile +0 -9
- data/examples/enum.rb +0 -30
- data/examples/struct.rb +0 -24
- data/examples/union.rb +0 -29
- data/spec/lib/xdr/array_spec.rb +0 -73
- data/spec/lib/xdr/bool_spec.rb +0 -43
- data/spec/lib/xdr/concerns/converts_to_xdr_spec.rb +0 -55
- data/spec/lib/xdr/concerns/reads_bytes_spec.rb +0 -31
- data/spec/lib/xdr/double_spec.rb +0 -38
- data/spec/lib/xdr/dsl/enum_spec.rb +0 -44
- data/spec/lib/xdr/dsl/struct_spec.rb +0 -29
- data/spec/lib/xdr/dsl/union_spec.rb +0 -69
- data/spec/lib/xdr/enum_spec.rb +0 -70
- data/spec/lib/xdr/float_spec.rb +0 -37
- data/spec/lib/xdr/hyper_spec.rb +0 -40
- data/spec/lib/xdr/int_spec.rb +0 -40
- data/spec/lib/xdr/opaque_spec.rb +0 -36
- data/spec/lib/xdr/option_spec.rb +0 -36
- data/spec/lib/xdr/quadruple_spec.rb +0 -14
- data/spec/lib/xdr/rpc/record_reader_spec.rb +0 -27
- data/spec/lib/xdr/string_spec.rb +0 -41
- data/spec/lib/xdr/struct_spec.rb +0 -101
- data/spec/lib/xdr/union_spec.rb +0 -248
- data/spec/lib/xdr/unsigned_hyper_spec.rb +0 -36
- data/spec/lib/xdr/unsigned_int_spec.rb +0 -36
- data/spec/lib/xdr/var_array_spec.rb +0 -71
- data/spec/lib/xdr/var_opaque_spec.rb +0 -43
- data/spec/lib/xdr/void_spec.rb +0 -46
- data/spec/spec_helper.rb +0 -15
- data/spec/support/matchers/eq_bytes.rb +0 -6
- data/xdr.gemspec +0 -29
    
        data/.gitignore
    DELETED
    
    
    
        data/.travis.yml
    DELETED
    
    | @@ -1,14 +0,0 @@ | |
| 1 | 
            -
            language: ruby
         | 
| 2 | 
            -
            rvm:
         | 
| 3 | 
            -
            - 2.2.0
         | 
| 4 | 
            -
            - 2.1.5
         | 
| 5 | 
            -
            - 2.0.0
         | 
| 6 | 
            -
            - 1.9.3
         | 
| 7 | 
            -
            - jruby-1.7.9
         | 
| 8 | 
            -
            - jruby-head
         | 
| 9 | 
            -
            notifications:
         | 
| 10 | 
            -
              slack:
         | 
| 11 | 
            -
                secure: fXYggrDRoLB/4yvyW0kWwyrV5yWa/GC0btPyGu7Hx6ZOaXDC+ejiXSfx7nRyY+uZBs5UF12O4gkUXwBbnWDT5JtQRxzZd5s0cyeGQfAakALexI+FuR2jDcV1prCCaYI4IYoUt61MlfDmuCYVm8hGZ3qsgk/GPHHPnZ8a1FBd2ls=
         | 
| 12 | 
            -
            matrix:
         | 
| 13 | 
            -
              allow_failures:
         | 
| 14 | 
            -
                - rvm: jruby-head
         | 
    
        data/.yardopts
    DELETED
    
    
    
        data/Gemfile
    DELETED
    
    
    
        data/Guardfile
    DELETED
    
    
    
        data/Rakefile
    DELETED
    
    
    
        data/examples/enum.rb
    DELETED
    
    | @@ -1,30 +0,0 @@ | |
| 1 | 
            -
            require 'xdr'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            class Color < XDR::Enum
         | 
| 4 | 
            -
              member :red, 0
         | 
| 5 | 
            -
              member :green, 1
         | 
| 6 | 
            -
              member :blue, 2
         | 
| 7 | 
            -
             | 
| 8 | 
            -
              seal
         | 
| 9 | 
            -
            end
         | 
| 10 | 
            -
             | 
| 11 | 
            -
            class ResultType < XDR::Enum
         | 
| 12 | 
            -
              member :ok, 0
         | 
| 13 | 
            -
              member :error, 1
         | 
| 14 | 
            -
              seal
         | 
| 15 | 
            -
            end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
            Color.members           # => {:red => 0, :green => 1, :blue => 2}
         | 
| 18 | 
            -
            Color.members.keys      # => [:red, :green, :blue]
         | 
| 19 | 
            -
             | 
| 20 | 
            -
            # string and symbol work
         | 
| 21 | 
            -
            # any casing that can be underscored to the correct value will work
         | 
| 22 | 
            -
            Color.from_name(:RED)   # => #<Color:... @name="red", @value=0>
         | 
| 23 | 
            -
            Color.from_name("RED")  # => #<Color:... @name="red", @value=0>
         | 
| 24 | 
            -
            Color.from_name("red")  # => #<Color:... @name="red", @value=0>
         | 
| 25 | 
            -
            Color.from_name(:red)  # => #<Color:... @name="red", @value=0>
         | 
| 26 | 
            -
             | 
| 27 | 
            -
            Color.from_xdr("\x00\x00\x00\x00") # => #<Color:... @name="red", @value=0>
         | 
| 28 | 
            -
            Color.to_xdr(Color.green) # => "\x00\x00\x00\x01"
         | 
| 29 | 
            -
             | 
| 30 | 
            -
            Color.red == ResultType.ok # => false
         | 
    
        data/examples/struct.rb
    DELETED
    
    | @@ -1,24 +0,0 @@ | |
| 1 | 
            -
            require 'xdr'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            class Signature < XDR::Struct
         | 
| 4 | 
            -
              attribute :public_key, XDR::Opaque[32]
         | 
| 5 | 
            -
              attribute :data, XDR::Opaque[32]
         | 
| 6 | 
            -
            end
         | 
| 7 | 
            -
             | 
| 8 | 
            -
            class Envelope < XDR::Struct
         | 
| 9 | 
            -
              attribute :body,      XDR::VarOpaque[]
         | 
| 10 | 
            -
              attribute :timestamp, XDR::Int
         | 
| 11 | 
            -
              attribute :signature, Signature
         | 
| 12 | 
            -
            end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
            sig            = Signature.new()
         | 
| 15 | 
            -
            sig.public_key = "\x01" * 32
         | 
| 16 | 
            -
            sig.data       = "\x00" * 32
         | 
| 17 | 
            -
             | 
| 18 | 
            -
            env = Envelope.new({
         | 
| 19 | 
            -
              signature: sig,
         | 
| 20 | 
            -
              body: "hello",
         | 
| 21 | 
            -
              timestamp: Time.now.to_i
         | 
| 22 | 
            -
            })
         | 
| 23 | 
            -
             | 
| 24 | 
            -
            env.to_xdr
         | 
    
        data/examples/union.rb
    DELETED
    
    | @@ -1,29 +0,0 @@ | |
| 1 | 
            -
            require 'xdr'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            class ResultType < XDR::Enum
         | 
| 4 | 
            -
              member :ok,       0
         | 
| 5 | 
            -
              member :error,    1
         | 
| 6 | 
            -
              member :nonsense, 2
         | 
| 7 | 
            -
              seal
         | 
| 8 | 
            -
            end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            class Result < XDR::Union
         | 
| 11 | 
            -
              switch_on ResultType, :type
         | 
| 12 | 
            -
             | 
| 13 | 
            -
              switch :ok
         | 
| 14 | 
            -
              switch :error, :message
         | 
| 15 | 
            -
              switch :default
         | 
| 16 | 
            -
             | 
| 17 | 
            -
              attribute :message, XDR::String[]
         | 
| 18 | 
            -
            end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
            r = Result.new()
         | 
| 21 | 
            -
            r.set(:error, "hello")
         | 
| 22 | 
            -
            r.message! # => "hello"
         | 
| 23 | 
            -
            r.get # => "hello"
         | 
| 24 | 
            -
             | 
| 25 | 
            -
            r.set(:ok)
         | 
| 26 | 
            -
            r.get # => nil
         | 
| 27 | 
            -
             | 
| 28 | 
            -
            r.set(:nonsense)
         | 
| 29 | 
            -
            r.get # => nil
         | 
    
        data/spec/lib/xdr/array_spec.rb
    DELETED
    
    | @@ -1,73 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            describe XDR::Array, "#read" do
         | 
| 4 | 
            -
              let(:empty) { XDR::Array[XDR::Int, 0] }
         | 
| 5 | 
            -
              let(:one)   { XDR::Array[XDR::Int, 1] }
         | 
| 6 | 
            -
              let(:many)  { XDR::Array[XDR::Int, 2] }
         | 
| 7 | 
            -
             | 
| 8 | 
            -
              it "decodes values correctly" do
         | 
| 9 | 
            -
                expect( read empty, "" ).to eq([])
         | 
| 10 | 
            -
                expect( read empty, "\x00\x00\x00\x00" ).to eq([])
         | 
| 11 | 
            -
                expect( read one, "\x00\x00\x00\x00" ).to eq([0])
         | 
| 12 | 
            -
                expect( read one, "\x00\x00\x00\x01" ).to eq([1])
         | 
| 13 | 
            -
                expect( read many, "\x00\x00\x00\x00\x00\x00\x00\x01" ).to eq([0, 1])
         | 
| 14 | 
            -
                expect( read many, "\x00\x00\x00\x01\x00\x00\x00\x01" ).to eq([1, 1])
         | 
| 15 | 
            -
              end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
              it "raises EOFError the byte stream isn't large enough" do
         | 
| 18 | 
            -
                expect{ read many, "\x00\x00\x00\x00" }.to raise_error(EOFError)
         | 
| 19 | 
            -
              end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
              def read(reader, str)
         | 
| 22 | 
            -
                io = StringIO.new(str)
         | 
| 23 | 
            -
                reader.read(io)
         | 
| 24 | 
            -
              end
         | 
| 25 | 
            -
            end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
            describe XDR::Array, "#write" do
         | 
| 28 | 
            -
              subject{ XDR::Array[XDR::Int, 2] }
         | 
| 29 | 
            -
             | 
| 30 | 
            -
              it "encodes values correctly" do
         | 
| 31 | 
            -
                expect(write [1,2]).to eq("\x00\x00\x00\x01\x00\x00\x00\x02")
         | 
| 32 | 
            -
                expect(write [1,4]).to eq("\x00\x00\x00\x01\x00\x00\x00\x04")
         | 
| 33 | 
            -
              end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
              it "raises a WriteError if the value is not the correct length" do
         | 
| 36 | 
            -
                expect{ write nil     }.to raise_error(XDR::WriteError)
         | 
| 37 | 
            -
                expect{ write []      }.to raise_error(XDR::WriteError)
         | 
| 38 | 
            -
                expect{ write [1]     }.to raise_error(XDR::WriteError)
         | 
| 39 | 
            -
                expect{ write [1,2,3] }.to raise_error(XDR::WriteError)
         | 
| 40 | 
            -
              end
         | 
| 41 | 
            -
             | 
| 42 | 
            -
              it "raises a WriteError if a child element is of the wrong type" do
         | 
| 43 | 
            -
                expect{ write [nil]      }.to raise_error(XDR::WriteError)
         | 
| 44 | 
            -
                expect{ write ["hi"]     }.to raise_error(XDR::WriteError)
         | 
| 45 | 
            -
                expect{ write [1,2,"hi"] }.to raise_error(XDR::WriteError)
         | 
| 46 | 
            -
              end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
              def write(val)
         | 
| 49 | 
            -
                io = StringIO.new()
         | 
| 50 | 
            -
                subject.write(val, io)
         | 
| 51 | 
            -
                io.string
         | 
| 52 | 
            -
              end
         | 
| 53 | 
            -
            end
         | 
| 54 | 
            -
             | 
| 55 | 
            -
            describe XDR::Array, "#valid?" do
         | 
| 56 | 
            -
              subject{ XDR::Array[XDR::Int, 2] }
         | 
| 57 | 
            -
             | 
| 58 | 
            -
              it "rejects an empty array" do
         | 
| 59 | 
            -
                expect(subject.valid?([])).to be_falsey
         | 
| 60 | 
            -
              end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
              it "accepts a filled array provided each element passes the child_type validator" do
         | 
| 63 | 
            -
                expect(subject.valid?([1,2])).to be_truthy
         | 
| 64 | 
            -
                expect(subject.valid?([2,3])).to be_truthy
         | 
| 65 | 
            -
              end
         | 
| 66 | 
            -
             | 
| 67 | 
            -
              it "rejects a filled array if any element is rejected by the child_type validator" do
         | 
| 68 | 
            -
                expect(subject.valid?(["hello", "hello"])).to be_falsey
         | 
| 69 | 
            -
                expect(subject.valid?([1, "hello"])).to be_falsey
         | 
| 70 | 
            -
                expect(subject.valid?([1, nil])).to be_falsey
         | 
| 71 | 
            -
                expect(subject.valid?([nil])).to be_falsey
         | 
| 72 | 
            -
              end
         | 
| 73 | 
            -
            end
         | 
    
        data/spec/lib/xdr/bool_spec.rb
    DELETED
    
    | @@ -1,43 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            describe XDR::Bool, ".read" do
         | 
| 4 | 
            -
              subject{ XDR::Bool }
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              let(:false_s) {  "\x00\x00\x00\x00" }
         | 
| 7 | 
            -
              let(:true_s)  {  "\x00\x00\x00\x01" }
         | 
| 8 | 
            -
              let(:two)     {  "\x00\x00\x00\x02" }
         | 
| 9 | 
            -
             | 
| 10 | 
            -
              it "decodes values correctly" do
         | 
| 11 | 
            -
                expect(read(false_s)).to eq(false)
         | 
| 12 | 
            -
                expect(read(true_s)).to eq(true)
         | 
| 13 | 
            -
              end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
              it "raises ReadError if the decoded value is not 0 or 1" do
         | 
| 16 | 
            -
                expect{ read two }.to raise_error XDR::ReadError
         | 
| 17 | 
            -
              end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
              def read(str)
         | 
| 20 | 
            -
                io = StringIO.new(str)
         | 
| 21 | 
            -
                subject.read(io)
         | 
| 22 | 
            -
              end
         | 
| 23 | 
            -
            end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
            describe XDR::Bool, ".write" do
         | 
| 26 | 
            -
              subject{ XDR::Bool }
         | 
| 27 | 
            -
             | 
| 28 | 
            -
              it "encodes values correctly" do
         | 
| 29 | 
            -
                expect(write false).to eq("\x00\x00\x00\x00")
         | 
| 30 | 
            -
                expect(write true).to eq("\x00\x00\x00\x01")
         | 
| 31 | 
            -
              end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
              it "raises WriteError if the value is boolean" do
         | 
| 34 | 
            -
                expect{ write 1 }.to raise_error XDR::WriteError
         | 
| 35 | 
            -
                expect{ write "hello" }.to raise_error XDR::WriteError
         | 
| 36 | 
            -
              end
         | 
| 37 | 
            -
             | 
| 38 | 
            -
              def write(val)
         | 
| 39 | 
            -
                io = StringIO.new()
         | 
| 40 | 
            -
                subject.write(val, io)
         | 
| 41 | 
            -
                io.string
         | 
| 42 | 
            -
              end
         | 
| 43 | 
            -
            end
         | 
| @@ -1,55 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            describe XDR::Concerns::ConvertsToXDR do
         | 
| 4 | 
            -
              subject{ UnimplementedConvertible.new }
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              it "requires an implementation of #read" do
         | 
| 7 | 
            -
                expect{ subject.read(StringIO.new) }.to raise_error(NotImplementedError)
         | 
| 8 | 
            -
              end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
              it "requires an implementation of #write" do
         | 
| 11 | 
            -
                expect{ subject.write(3, StringIO.new) }.to raise_error(NotImplementedError)
         | 
| 12 | 
            -
              end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
              it "requires an implementation of #valid?" do
         | 
| 15 | 
            -
                expect{ subject.valid?(3) }.to raise_error(NotImplementedError)
         | 
| 16 | 
            -
              end
         | 
| 17 | 
            -
            end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
            describe XDR::Concerns::ConvertsToXDR, "#to_xdr" do
         | 
| 20 | 
            -
              subject{ ImplementedConvertible.new }
         | 
| 21 | 
            -
             | 
| 22 | 
            -
              it "calls through to write" do
         | 
| 23 | 
            -
                expect(subject).to receive(:write).with("hiya", kind_of(StringIO))
         | 
| 24 | 
            -
                subject.to_xdr("hiya")
         | 
| 25 | 
            -
              end
         | 
| 26 | 
            -
            end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
            describe XDR::Concerns::ConvertsToXDR, "#from_xdr" do
         | 
| 29 | 
            -
              subject{ ImplementedConvertible.new }
         | 
| 30 | 
            -
             | 
| 31 | 
            -
              it "calls through to write" do
         | 
| 32 | 
            -
                expect(subject).to receive(:read).with(kind_of(StringIO))
         | 
| 33 | 
            -
                subject.from_xdr("hiya")
         | 
| 34 | 
            -
              end
         | 
| 35 | 
            -
            end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
            class UnimplementedConvertible
         | 
| 38 | 
            -
              include XDR::Concerns::ConvertsToXDR
         | 
| 39 | 
            -
            end
         | 
| 40 | 
            -
             | 
| 41 | 
            -
            class ImplementedConvertible
         | 
| 42 | 
            -
              include XDR::Concerns::ConvertsToXDR
         | 
| 43 | 
            -
             | 
| 44 | 
            -
              def read(io)
         | 
| 45 | 
            -
                read_bytes(4)
         | 
| 46 | 
            -
              end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
              def write(val, io)
         | 
| 49 | 
            -
                io.write(val)
         | 
| 50 | 
            -
              end
         | 
| 51 | 
            -
             | 
| 52 | 
            -
              def valid?(val)
         | 
| 53 | 
            -
                true
         | 
| 54 | 
            -
              end
         | 
| 55 | 
            -
            end
         | 
| @@ -1,31 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            class TestReader
         | 
| 4 | 
            -
              include XDR::Concerns::ReadsBytes
         | 
| 5 | 
            -
              public :read_bytes
         | 
| 6 | 
            -
            end
         | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
            describe XDR::Concerns::ReadsBytes, "#read_bytes"  do
         | 
| 10 | 
            -
              subject{ TestReader.new }
         | 
| 11 | 
            -
             | 
| 12 | 
            -
              it "raises EOFError when the requested length goes beyond the length of the stream" do
         | 
| 13 | 
            -
                expect{ read("", 1) }.to raise_error(EOFError)
         | 
| 14 | 
            -
                expect{ read("", 2) }.to raise_error(EOFError)
         | 
| 15 | 
            -
                expect{ read("", 10) }.to raise_error(EOFError)
         | 
| 16 | 
            -
                expect{ read("\x00\x01\x02", 4) }.to raise_error(EOFError)
         | 
| 17 | 
            -
                expect{ read("\x00\x01\x02", 10) }.to raise_error(EOFError)
         | 
| 18 | 
            -
              end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
              it "returns the read data" do
         | 
| 21 | 
            -
                expect(read("", 0)).to eq("")
         | 
| 22 | 
            -
                expect(read("\x00", 1)).to eq("\x00")
         | 
| 23 | 
            -
                expect(read("\x01", 1)).to eq("\x01")
         | 
| 24 | 
            -
                expect(read("\x00\x01\x02", 3)).to eq("\x00\x01\x02")
         | 
| 25 | 
            -
              end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
              def read(str, length)
         | 
| 28 | 
            -
                io = StringIO.new(str)
         | 
| 29 | 
            -
                subject.read_bytes(io, length)
         | 
| 30 | 
            -
              end
         | 
| 31 | 
            -
            end
         | 
    
        data/spec/lib/xdr/double_spec.rb
    DELETED
    
    | @@ -1,38 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 4 | 
            -
            describe XDR::Double, ".read" do
         | 
| 5 | 
            -
             | 
| 6 | 
            -
              it "decodes values correctly" do
         | 
| 7 | 
            -
                expect(read("\x00\x00\x00\x00\x00\x00\x00\x00")).to eq(0.0)
         | 
| 8 | 
            -
                expect(read("\x80\x00\x00\x00\x00\x00\x00\x00")).to eq(-0.0)
         | 
| 9 | 
            -
                expect(read("\x3F\xF0\x00\x00\x00\x00\x00\x00")).to eq(1.0)
         | 
| 10 | 
            -
                expect(read("\xBF\xF0\x00\x00\x00\x00\x00\x00")).to eq(-1.0)
         | 
| 11 | 
            -
              end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
              def read(str)
         | 
| 14 | 
            -
                io = StringIO.new(str)
         | 
| 15 | 
            -
                subject.read(io)
         | 
| 16 | 
            -
              end
         | 
| 17 | 
            -
            end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
            describe XDR::Double, ".write" do
         | 
| 20 | 
            -
              it "encodes values correctly" do
         | 
| 21 | 
            -
                expect(write 0.0).to  eq_bytes("\x00\x00\x00\x00\x00\x00\x00\x00")
         | 
| 22 | 
            -
                expect(write -0.0).to eq_bytes("\x80\x00\x00\x00\x00\x00\x00\x00")
         | 
| 23 | 
            -
                expect(write 1.0).to  eq_bytes("\x3F\xF0\x00\x00\x00\x00\x00\x00")
         | 
| 24 | 
            -
                expect(write -1.0).to eq_bytes("\xBF\xF0\x00\x00\x00\x00\x00\x00")
         | 
| 25 | 
            -
              end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
              it "raises a WriteError when the value is not Float" do
         | 
| 28 | 
            -
                expect{ write 3 }.to      raise_error(XDR::WriteError)
         | 
| 29 | 
            -
                expect{ write "hi" }.to   raise_error(XDR::WriteError)
         | 
| 30 | 
            -
                expect{ write "1.0" }.to  raise_error(XDR::WriteError)
         | 
| 31 | 
            -
              end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
              def write(val)
         | 
| 34 | 
            -
                io = StringIO.new()
         | 
| 35 | 
            -
                subject.write(val, io)
         | 
| 36 | 
            -
                io.string
         | 
| 37 | 
            -
              end
         | 
| 38 | 
            -
            end
         | 
| @@ -1,44 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 4 | 
            -
            describe XDR::DSL::Enum, "#member" do
         | 
| 5 | 
            -
              subject do
         | 
| 6 | 
            -
                Class.new(XDR::Enum) do
         | 
| 7 | 
            -
                  member :one, 1
         | 
| 8 | 
            -
                  member :two, 2
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
              end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
              it "adds to the members collection of the class" do
         | 
| 13 | 
            -
                expect(subject.members.length).to eq(2)
         | 
| 14 | 
            -
                expect(subject.members[:one]).to eq(subject.one)
         | 
| 15 | 
            -
                expect(subject.members[:two]).to eq(subject.two)
         | 
| 16 | 
            -
              end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
              it "raises ArgumentError if a non-fixnum value is used" do
         | 
| 19 | 
            -
                expect {
         | 
| 20 | 
            -
                  Class.new(XDR::Enum) do
         | 
| 21 | 
            -
                    member :one, "hi!"
         | 
| 22 | 
            -
                  end
         | 
| 23 | 
            -
                }.to raise_error(ArgumentError)
         | 
| 24 | 
            -
              end
         | 
| 25 | 
            -
            end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
            describe XDR::DSL::Enum, "#seal" do
         | 
| 28 | 
            -
              subject do
         | 
| 29 | 
            -
                Class.new(XDR::Enum) do
         | 
| 30 | 
            -
                  member :one, 1
         | 
| 31 | 
            -
                  member :two, 2
         | 
| 32 | 
            -
                  seal
         | 
| 33 | 
            -
                end
         | 
| 34 | 
            -
              end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
              it "marks the class as sealed" do
         | 
| 37 | 
            -
                expect(subject.sealed).to eq(true)
         | 
| 38 | 
            -
              end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
              it "prevents you from adding members after being sealed" do
         | 
| 41 | 
            -
                expect{ subject.member :three, 3 }.to raise_error(ArgumentError)
         | 
| 42 | 
            -
              end
         | 
| 43 | 
            -
             | 
| 44 | 
            -
            end
         | 
| @@ -1,29 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 4 | 
            -
            describe XDR::DSL::Struct, "#attribute" do
         | 
| 5 | 
            -
              subject do
         | 
| 6 | 
            -
                Class.new(XDR::Struct) do
         | 
| 7 | 
            -
                  attribute :attr1, XDR::Int
         | 
| 8 | 
            -
                  attribute :attr2, XDR::String[]
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
              end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
              it "adds to the fields collection of the class" do
         | 
| 14 | 
            -
                expect(subject.fields.length).to eq(2)
         | 
| 15 | 
            -
                expect(subject.fields[:attr1]).to eq(XDR::Int)
         | 
| 16 | 
            -
                expect(subject.fields[:attr2]).to be_a(XDR::String)
         | 
| 17 | 
            -
              end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
              it "raises ArgumentError if a non-convertible type is used" do
         | 
| 22 | 
            -
                expect do
         | 
| 23 | 
            -
                  Class.new(XDR::Struct) do
         | 
| 24 | 
            -
                    attribute :attr1, String
         | 
| 25 | 
            -
                  end
         | 
| 26 | 
            -
                end.to raise_error(ArgumentError)
         | 
| 27 | 
            -
              end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
            end
         |