test/test_bencoder.rb in bencoder-0.0.4 vs test/test_bencoder.rb in bencoder-0.1.0
- old
+ new
@@ -11,10 +11,14 @@
@be = BEncoder
end
#encoding
+ def test_symbol_encoding
+ assert_equal '6:hellou', @be.encode(:hellou)
+ end
+
def test_string_encoding
assert_equal '7:Someday', @be.encode('Someday')
end
def test_int_encoding
@@ -31,10 +35,16 @@
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
+ def test_should_not_encode_strange_types
+ assert_raises UnencodableTypeError do
+ @be.encode 5.6
+ end
+ end
+
#decoding
def test_string_decoding
assert_equal "I'm free!", @be.decode("9:I'm free!")
end
@@ -51,7 +61,37 @@
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
+
+ def test_throws_error_on_wrong_list_encoding
+ assert_raises InvalidEncodingError do
+ @be.decode 'li4ed'
+ end
+ end
+
+ def test_throws_error_on_wrong_dict_encoding
+ assert_raises InvalidEncodingError do
+ @be.decode 'd3:abc'
+ end
+ end
+
+ def test_throws_error_on_wrong_int_encoding
+ assert_raises InvalidEncodingError do
+ @be.decode 'i14'
+ end
+ end
+
+ def test_throws_error_on_wrong_string_encoding
+ assert_raises InvalidEncodingError do
+ @be.decode '4:cat'
+ end
+ end
+
+ def test_throws_error_on_unknown_encoding_identifier
+ assert_raises InvalidEncodingError do
+ @be.decode 'li3ej5e'
+ end
end
end