Sha256: dc57dab8a968222c115eb0a19cc828c45a3485104eda0e11e6e9871ca5bc2dfd

Contents?: true

Size: 831 Bytes

Versions: 2

Compression:

Stored size: 831 Bytes

Contents

require 'test/unit'
require 'bencode'

class BdecodeTest < Test::Unit::TestCase
  def test_string
    assert_equal "foo", "3:foo".bdecode
  end

  def test_integer
    assert_equal 42, "i42e".bdecode
    assert_raise BdecodeError do
      "i01e".bdecode
    end
    assert_raise BdecodeError do
      "i-01e".bdecode
    end
  end

  def test_array
    assert_equal [1, 2, 3], "li1ei2ei3ee".bdecode
  end

  def test_hash
    hsh = {"a" => "monkey", "h" => "elephant", "z" => "zebra"}
    assert_equal hsh, "d1:a6:monkey1:h8:elephant1:z5:zebrae".bdecode
  end

  def test_invalid
    assert_raises BdecodeError do
      "foobar".bdecode
      "i1ei2e".bdecode
    end
  end

  def test_valid
    assert  "3:foo".bencoded?
    assert !"3:foo3:bar".bencoded?
    assert  "i42e".bencoded?
    assert !"i42ei101e".bencoded?
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bencode-0.0.1 test/tc_bdecode.rb
bencode-0.1.0 test/tc_bdecode.rb