Skip to content

Commit

Permalink
Merge pull request #12 from moroshko/master
Browse files Browse the repository at this point in the history
Fail if number has more than one decomail point
  • Loading branch information
Arlen Christian Mart Cuss committed Oct 28, 2012
2 parents d0a6666 + a44a8c5 commit 65d8d32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rouge/reader.rb
Expand Up @@ -370,6 +370,10 @@ def reader_raise ex, m
end

def read_number s
if s.count('.') > 1
reader_raise UnexpectedCharacterError, "#{s} in #read_number"
end

neg = 1

if s[0] == ?-
Expand Down
5 changes: 5 additions & 0 deletions spec/reader_spec.rb
Expand Up @@ -21,6 +21,11 @@
it { @ns.read("-23.1").should eq(-23.1) }
it { @ns.read("+17.04").should eq(17.04) }
end

it "should fail on invalid numbers" do
lambda { @ns.read("1.2.3") }.should raise_exception(Rouge::Reader::UnexpectedCharacterError)
lambda { @ns.read("12..") }.should raise_exception(Rouge::Reader::UnexpectedCharacterError)
end
end

it "should read symbols" do
Expand Down

0 comments on commit 65d8d32

Please sign in to comment.