Sha256: bed6b23d9761c8099fe7f54f9ba9e3d9a273ab973ae7e45ed9b0d977407ec5a2
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
require 'test/unit' require "#{File.dirname(__FILE__)}/../lib/bencode" class BdecodeTest < Test::Unit::TestCase def test_string assert_equal "", "0:".bdecode assert_equal "foo", "3:foo".bdecode assert_equal "foo bar", "7:foo bar".bdecode end def test_integer assert_equal 0, "i0e".bdecode assert_equal 42, "i42e".bdecode assert_equal -7, "i-7e".bdecode end def test_invalid_integer assert_raise BdecodeError do "i01e".bdecode end assert_raise BdecodeError do "i-01e".bdecode end end def test_array assert_equal [], "le".bdecode assert_equal ["foo"], "l3:fooe".bdecode assert_equal [1, 2, 3], "li1ei2ei3ee".bdecode end def test_hash assert_equal Hash.new, "de".bdecode 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 "4:foo".bdecode "2:bar".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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bencode-0.4.0 | test/tc_bdecode.rb |