Browse files

Raise an error if type is unknown

  • Loading branch information...
1 parent f005cc4 commit ab4ab08bd58a339390fa8b4035921f1826402aab @josh josh committed May 15, 2011
Showing with 8 additions and 0 deletions.
  1. +2 −0 lib/otnetstring.rb
  2. +6 −0 spec/otnetstring_spec.rb
View
2 lib/otnetstring.rb
@@ -29,6 +29,8 @@ def self.parse(io)
start = io.pos
array << parse(io) while io.pos - start < length
byte == "{" ? Hash[*array] : array
+ else
+ raise Error, "Unknown type '#{byte}'"
end
end
View
6 spec/otnetstring_spec.rb
@@ -71,6 +71,12 @@
OTNetstring.parse('9' * 10 + ',')
}.should raise_error(OTNetstring::Error, '9999999999 is longer than 9 digits')
end
+
+ it "raise an error if type is unknown" do
+ lambda {
+ OTNetstring.parse('3?123')
+ }.should raise_error(OTNetstring::Error, "Unknown type '?'")
+ end
end
context "encoding" do

0 comments on commit ab4ab08

Please sign in to comment.