Permalink
Browse files

Fix TypeError when using ? quantity

  • Loading branch information...
1 parent 02f3520 commit 6d5c8a1f37b22f994fbfffefd180b021103962d2 @mjackson mjackson committed Mar 1, 2012
Showing with 8 additions and 2 deletions.
  1. +1 −1 lib/randexp/reducer.rb
  2. +7 −1 spec/regression/regexp_spec.rb
View
@@ -23,7 +23,7 @@ def self.random(sexpish, quantity)
def self.literal(cell, quantity = nil)
case quantity
- when :'?' then ([''] + cell).pick * ''
+ when :'?' then ([''] + cell).pick
when :+, :'+?' then raise "Sorry, \"#{cell * ''}+\" is too vague, try setting a range: \"#{cell * ''}{1,3}\""
when :*, :'*?' then raise "Sorry, \"#{cell * ''}*\" is too vague, try setting a range: \"#{cell * ''}{0,3}\""
when Range then quantity.pick.of { cell * '' } * ''
@@ -125,6 +125,12 @@
end
end
+ it "/abc?/ => ['ab', 'abc']" do
+ 100.times do
+ ['ab', 'abc'].should include(/abc?/.gen)
+ end
+ end
+
it "/(\\d{3}-)?\\d{3}-\\d{4}/ => /(\\d{3}-)?\\d{3}-\\d{4}/" do
100.times do
/(\d{3}-)?\d{3}-\d{4}/.gen.should =~ /(\d{3}-)?\d{3}-\d{4}/
@@ -160,7 +166,7 @@
/\$\d{2,3}\.\d{2}/.gen.should =~ /\$\d{2,3}\.\d{2}/
end
end
-
+
it "/[:first_name:]/ => /\\w+/" do
100.times do
/[:first_name:]/.gen.should =~ /\w+/

0 comments on commit 6d5c8a1

Please sign in to comment.