Sha256: 74fdcaa05ddf831f2ae62faff82348132e563a0e408d334ec167659621642880

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require 'coveralls'

Coveralls.wear!

require 'minitest/autorun'
require 'bencoder'

class TestBencoder < Minitest::Test

  def setup
    @be = BEncoder
  end

  #encoding

  def test_string_encoding
    assert_equal '7:Someday', @be.encode('Someday')
  end

  def test_int_encoding
    assert_equal 'i123e', @be.encode(123)
  end

  def test_array_encoding
    assert_equal 'l3:hey5:theree', @be.encode(['hey', 'there'])
  end

  def test_hash_encoding
    assert_equal 'd4:what2:is2:up4:dawge', @be.encode({what: 'is', up: 'dawg'})
  end

  def test_nested_encoding
    assert_equal 'ld4:somel5:times3:youe5:gotta3:let2:go1:!ei2e5:wooooli1e1:21:3ee', @be.encode([{'some' => ['times', 'you'], gotta: 'let', go: '!'}, 2, "woooo", [1, '2', "3"]])
  end

  #decoding

  def test_string_decoding
    assert_equal "I'm free!", @be.decode("9:I'm free!")
  end

  def test_int_decoding
    assert_equal 321, @be.decode('i321e')
  end

  def test_array_decoding
    assert_equal ['1', 2, 3], @be.decode('l1:1i2ei3ee')
  end

  def test_hash_decoding
    assert_equal({'abc' => 'def', 'ghi' => 32}, @be.decode("d3:abc3:def3:ghii32ee"))
  end

  def test_nested_decoding
    assert_equal [{'some' => ['times', 'you'], 'gotta' => 'let', 'go' => '!'}, 2, "woooo", [1, '2', "3"]], @be.decode('ld4:somel5:times3:youe5:gotta3:let2:go1:!ei2e5:wooooli1e1:21:3ee')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bencoder-0.0.4 test/test_bencoder.rb