Sha256: 779113f778fc080bc6b780c7d3dd531f6f9472776a05c79c8fc14b03dee4407a

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'test/unit'

require 'bit_struct/text'

include BitStruct



class TestTextField < Test::Unit::TestCase

  # Note: The TextField doesn't check the length. It is part of the
  # contract between the field and the slicer that only the expected
  # number of bytes (or less) are passed to the field :)

  def test_initialize
    TextField.new 'dummy', 8
    TextField.new 'dummy', 16
    TextField.new 'dummy', 24
    assert_raise( RuntimeError ) { TextField.new 'dummy', 5 }
  end

  def test_read
    slicer = FakeSlicer.new 'toast'.bytes
    field = TextField.new 'dummy', 24
    assert_equal 'tsaot', field.read( slicer )
  end

  def test_write
    slicer = FakeSlicer.new
    field = TextField.new 'dummy', 24
    field.write slicer, 'toast'
    assert_equal 'tsaot', slicer.get_bytes.stringify
  end

end



class FakeSlicer

  def initialize( data = '' )
    @data = data
  end

  def get_bytes
    @data
  end

  def set_bytes( data )
    @data = data
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
BitStructEx-0.0.64 test/ruby/bit_struct/test_text.rb