Permalink
Browse files

Raise an error if length is missing

  • Loading branch information...
1 parent 79b7a07 commit 7fdae390ad34ad54e305e0f002d356a88dc8604c @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
@@ -14,6 +14,8 @@ def self.parse(io)
if length.size > 9
raise Error, "#{length} is longer than 9 digits"
+ elsif length !~ /\d+/
+ raise Error, "Expected '#{byte}' to be a digit"
end
length = Integer(length)
@@ -60,6 +60,12 @@
OTNetstring.parse('4!true!').should == true
end
+ it "raises an error if length is missing" do
+ lambda {
+ OTNetstring.parse('#123')
+ }.should raise_error(OTNetstring::Error, "Expected '#' to be a digit")
+ end
+
it "raises an error if length is longer than 9 digits" do
lambda {
OTNetstring.parse('9' * 10 + ',')

0 comments on commit 7fdae39

Please sign in to comment.