randexp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/LICENSE +20 -0
- data/README +83 -0
- data/Rakefile +111 -0
- data/TODO +5 -0
- data/lib/core_ext/array.rb +5 -0
- data/lib/core_ext/integer.rb +5 -0
- data/lib/core_ext/range.rb +5 -0
- data/lib/core_ext/regexp.rb +7 -0
- data/lib/core_ext.rb +4 -0
- data/lib/dictionary.rb +24 -0
- data/lib/randexp/parser.rb +72 -0
- data/lib/randexp/reducer.rb +102 -0
- data/lib/randexp.rb +17 -0
- data/lib/randgen.rb +52 -0
- data/spec/regression/regexp_spec.rb +139 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/unit/core_ext/regexp_spec.rb +9 -0
- data/spec/unit/randexp/parser_spec.rb +77 -0
- data/spec/unit/randexp/reducer_spec.rb +224 -0
- data/spec/unit/randexp_spec.rb +158 -0
- data/spec/unit/randgen_spec.rb +110 -0
- metadata +82 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Randexp::Parser do
|
4
|
+
describe ".parse" do
|
5
|
+
it "should return a sexp for a non-empty string" do
|
6
|
+
Randexp::Parser.parse("abc").should be_instance_of(Array)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return nil for an empty string" do
|
10
|
+
Randexp::Parser.parse("").should be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should alias :[] to :parse" do
|
14
|
+
Randexp::Parser[""].should be_nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".quantify" do
|
19
|
+
it "should return a :quantify sexp" do
|
20
|
+
Randexp::Parser.quantify([:literal, 'a'], :*)[0].should == :quantify
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should push the quantify symbol on the end of the sexp" do
|
24
|
+
Randexp::Parser.quantify([:literal, 'a'], :*).last.should == :*
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should push the argument sexp to the first entry of the :quantify sexp" do
|
28
|
+
Randexp::Parser.quantify([:literal, 'a'], :*)[1].should == [:literal, 'a']
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe ".union" do
|
33
|
+
it "should return the union of the right-hand side if the left-hand side is nil" do
|
34
|
+
Randexp::Parser.union(nil, [:literal, 'a']).should == Randexp::Parser.union([:literal, 'a'])
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return the left-hand side if the right hand side is not present" do
|
38
|
+
Randexp::Parser.union([:literal, 'a']).should == [:literal, 'a']
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should append the right-hand side(s) to the left-hand side if the left-hand side is a union sexp" do
|
42
|
+
Randexp::Parser.union([:union, [:literal, 'a'], [:literal, 'b']], [:literal, 'c']).should == [:union, [:literal, 'a'], [:literal, 'b'], [:literal, 'c']]
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return a :union sexp between the left-hand and right-hand sexp's" do
|
46
|
+
Randexp::Parser.union([:literal, 'a'], [:literal, 'b']).should == [:union, [:literal, 'a'], [:literal, 'b']]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe ".intersection" do
|
51
|
+
it "should prepend the left-hand side onto the right-hand side :intersection sexp if the right-hand side is an :intersection sexp" do
|
52
|
+
Randexp::Parser.intersection([:literal, 'a'], [:intersection, [:literal, 'b'], [:literal, 'c']]).should == [:intersection, [:literal, 'a'], [:literal, 'b'], [:literal, 'c']]
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should create an :intersection sexp between the left-hand and right-hand sexp's" do
|
56
|
+
Randexp::Parser.intersection([:literal, 'a'], [:literal, 'b']).should == [:intersection, [:literal, 'a'], [:literal, 'b']]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ".random" do
|
61
|
+
it "should return a :random sexp" do
|
62
|
+
Randexp::Parser.random('w').should be_instance_of(Array)
|
63
|
+
Randexp::Parser.random('w').first.should == :random
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should convert the char parameter to a symbol" do
|
67
|
+
Randexp::Parser.random('w').last.should == :w
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe ".literal" do
|
72
|
+
it "should return a literal sexp" do
|
73
|
+
Randexp::Parser.literal('a').should be_instance_of(Array)
|
74
|
+
Randexp::Parser.literal('a').first.should == :literal
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Randexp::Reducer do
|
4
|
+
describe ".reduce" do
|
5
|
+
it "should expect a sexp, and return a string" do
|
6
|
+
Randexp::Reducer.reduce([:literal, 'a']).should be_instance_of(String)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be an alias for :[]" do
|
10
|
+
Randexp::Reducer[[:literal, 'a']].should == Randexp::Reducer.reduce([:literal, 'a'])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe ".quantify" do
|
15
|
+
it "should call reduce with the sexp and quantity arguments as the :quantify sexp's head and tail" do
|
16
|
+
Randexp::Reducer.should_receive(:reduce).with([:literal, 'a'], :*)
|
17
|
+
Randexp::Reducer.quantify([[:literal, 'a'], :*], :'?') # :'?' is ignored
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ".random" do
|
22
|
+
it "should call :char with the quantity argument if the sexp's value is :w" do
|
23
|
+
Randexp::Reducer.should_receive(:char).with(:*)
|
24
|
+
Randexp::Reducer.random([:w], :*)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should call :digit with the quantity argument if the sexp's value is :d" do
|
28
|
+
Randexp::Reducer.should_receive(:digit).with(:*)
|
29
|
+
Randexp::Reducer.random([:d], :*)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should call :whitespace with the quantity argument if the sexp's value is :w" do
|
33
|
+
Randexp::Reducer.should_receive(:whitespace).with(:*)
|
34
|
+
Randexp::Reducer.random([:s], :*)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should call :randgen with the quantity argument if the sexp's value for all other cases" do
|
38
|
+
Randexp::Reducer.should_receive(:randgen).with(:alpha_numeric, :*)
|
39
|
+
Randexp::Reducer.random([:alpha_numeric], :*)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ".literal" do
|
44
|
+
it "should raise an exception if the quantity argument is :+ or :'+?'" do
|
45
|
+
lambda { Randexp::Reducer.literal(['a'], :+) }.should raise_error("Sorry, \"a+\" is too vague, try setting a range: \"a{1,3}\"")
|
46
|
+
lambda { Randexp::Reducer.literal(['b'], :'+?') }.should raise_error("Sorry, \"b+\" is too vague, try setting a range: \"b{1,3}\"")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should raise an exception if the quantity argument is :* or :'*?'" do
|
50
|
+
lambda { Randexp::Reducer.literal(['a'], :*) }.should raise_error("Sorry, \"a*\" is too vague, try setting a range: \"a{0,3}\"")
|
51
|
+
lambda { Randexp::Reducer.literal(['b'], :'*?') }.should raise_error("Sorry, \"b*\" is too vague, try setting a range: \"b{0,3}\"")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe ".intersection" do
|
56
|
+
it "should raise an exception if the quantity arguement is :+ or :'+?'" do
|
57
|
+
lambda { Randexp::Reducer.intersection([[:literal, 'a'], [:literal, 'b']], :+) }.should raise_error("Sorry, \"((...)|(...))+\" is too vague, try setting a range: \"((...)|(...)){1, 3}\"")
|
58
|
+
lambda { Randexp::Reducer.intersection([[:literal, 'b'], [:literal, 'a']], :'+?') }.should raise_error("Sorry, \"((...)|(...))+\" is too vague, try setting a range: \"((...)|(...)){1, 3}\"")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should raise an exception if the quantity argument is :* or :'*?'" do
|
62
|
+
lambda { Randexp::Reducer.intersection([[:literal, 'a'], [:literal, 'b']], :*) }.should raise_error("Sorry, \"((...)|(...))*\" is too vague, try setting a range: \"((...)|(...)){0, 3}\"")
|
63
|
+
lambda { Randexp::Reducer.intersection([[:literal, 'b'], [:literal, 'a']], :'*?') }.should raise_error("Sorry, \"((...)|(...))*\" is too vague, try setting a range: \"((...)|(...)){0, 3}\"")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe ".union" do
|
68
|
+
it "should raise an exception if the quantity arguement is :+ or :'+?'" do
|
69
|
+
lambda { Randexp::Reducer.union([[:literal, 'a'], [:literal, 'b']], :+) }.should raise_error("Sorry, \"(...)+\" is too vague, try setting a range: \"(...){1, 3}\"")
|
70
|
+
lambda { Randexp::Reducer.union([[:literal, 'b'], [:literal, 'a']], :'+?') }.should raise_error("Sorry, \"(...)+\" is too vague, try setting a range: \"(...){1, 3}\"")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise an exception if the quantity argument is :* or :'*?'" do
|
74
|
+
lambda { Randexp::Reducer.union([[:literal, 'a'], [:literal, 'b']], :*) }.should raise_error("Sorry, \"(...)*\" is too vague, try setting a range: \"(...){0, 3}\"")
|
75
|
+
lambda { Randexp::Reducer.union([[:literal, 'b'], [:literal, 'a']], :'*?') }.should raise_error("Sorry, \"(...)*\" is too vague, try setting a range: \"(...){0, 3}\"")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe ".char" do
|
80
|
+
it "should call Randgen.char if the quantity argument is :'?'" do
|
81
|
+
Randgen.should_receive(:char)
|
82
|
+
Randexp::Reducer.char(:'?')
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should call Randgen.char if the quantity argument is 1" do
|
86
|
+
Randgen.should_receive(:char)
|
87
|
+
Randexp::Reducer.char(1)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should call Randgen.char if the quantity argument is nil" do
|
91
|
+
Randgen.should_receive(:char)
|
92
|
+
Randexp::Reducer.char(nil)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should call Randgen.word if the quantity argument is :+" do
|
96
|
+
Randgen.should_receive(:word)
|
97
|
+
Randexp::Reducer.char(:+)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should call Randgen.word if the quantity argument is :'+?'" do
|
101
|
+
Randgen.should_receive(:word)
|
102
|
+
Randexp::Reducer.char(:'+?')
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should call Randgen.word with the :length option if the quantity argument is an Integer" do
|
106
|
+
Randgen.should_receive(:word).with(:length => 5)
|
107
|
+
Randexp::Reducer.char(5)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should call Randgen.word with the :length option if the quantity argument is a Range" do
|
111
|
+
range = 1..10
|
112
|
+
range.should_receive(:pick).and_return 7
|
113
|
+
Randgen.should_receive(:word).with(:length => 7)
|
114
|
+
Randexp::Reducer.char(range)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe ".whitespace" do
|
119
|
+
it "should call Randgen.whitespace if the quantity is :'?'" do
|
120
|
+
Randgen.should_receive(:whitespace)
|
121
|
+
Randexp::Reducer.whitespace(:'?')
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should call Randgen.whitespace if the quantity is nil" do
|
125
|
+
Randgen.should_receive(:whitespace)
|
126
|
+
Randexp::Reducer.whitespace(nil)
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should call Randgen.whitespace quantity times if the quantity is an Integer" do
|
130
|
+
Randgen.should_receive(:whitespace).exactly(5).times
|
131
|
+
Randexp::Reducer.whitespace(5)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should call Randgen.whitespace quantity times if the quantity is a Range" do
|
135
|
+
range = 1..10
|
136
|
+
range.should_receive(:pick).and_return 7
|
137
|
+
Randgen.should_receive(:whitespace).exactly(7).times
|
138
|
+
Randexp::Reducer.whitespace(range)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should raise an exception if the quantity arguement is :+ or :'+?'" do
|
142
|
+
lambda { Randexp::Reducer.whitespace(:+) }.should raise_error("Sorry, \"\\s+\" is too vague, try setting a range: \"\\s{1, 5}\"")
|
143
|
+
lambda { Randexp::Reducer.whitespace(:'+?') }.should raise_error("Sorry, \"\\s+\" is too vague, try setting a range: \"\\s{1, 5}\"")
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should raise an exception if the quantity argument is :* or :'*?'" do
|
147
|
+
lambda { Randexp::Reducer.whitespace(:*) }.should raise_error("Sorry, \"\\s*\" is too vague, try setting a range: \"\\s{0, 5}\"")
|
148
|
+
lambda { Randexp::Reducer.whitespace(:'*?') }.should raise_error("Sorry, \"\\s*\" is too vague, try setting a range: \"\\s{0, 5}\"")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe ".digit" do
|
153
|
+
it "should call Randgen.digit if the quantity is :'?'" do
|
154
|
+
Randgen.should_receive(:digit)
|
155
|
+
Randexp::Reducer.digit(:'?')
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should call Randgen.digit if the quantity is nil" do
|
159
|
+
Randgen.should_receive(:digit)
|
160
|
+
Randexp::Reducer.digit(nil)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should call Randgen.digit quantity times if the quantity is an Integer" do
|
164
|
+
Randgen.should_receive(:digit).exactly(5).times
|
165
|
+
Randexp::Reducer.digit(5)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should call Randgen.digit quantity times if the quantity is a Range" do
|
169
|
+
range = 1..10
|
170
|
+
range.should_receive(:pick).and_return 7
|
171
|
+
Randgen.should_receive(:digit).exactly(7).times
|
172
|
+
Randexp::Reducer.digit(range)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should raise an exception if the quantity arguement is :+ or :'+?'" do
|
176
|
+
lambda { Randexp::Reducer.digit(:+) }.should raise_error("Sorry, \"\\d+\" is too vague, try setting a range: \"\\d{1, 5}\"")
|
177
|
+
lambda { Randexp::Reducer.digit(:'+?') }.should raise_error("Sorry, \"\\d+\" is too vague, try setting a range: \"\\d{1, 5}\"")
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should raise an exception if the quantity argument is :* or :'*?'" do
|
181
|
+
lambda { Randexp::Reducer.digit(:*) }.should raise_error("Sorry, \"\\d*\" is too vague, try setting a range: \"\\d{0, 5}\"")
|
182
|
+
lambda { Randexp::Reducer.digit(:'*?') }.should raise_error("Sorry, \"\\d*\" is too vague, try setting a range: \"\\d{0, 5}\"")
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe ".randgen" do
|
187
|
+
it "should send Randgen the method name argument with a :length => 1 option if the quantity is :'?'" do
|
188
|
+
Randgen.should_receive(:send).with(:foo, :length => 1)
|
189
|
+
Randexp::Reducer.randgen([:foo], :'?')
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should send Randgen the method name argument if the quantity is nil" do
|
193
|
+
Randgen.should_receive(:send).with(:bar)
|
194
|
+
Randexp::Reducer.randgen([:bar], nil)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should send Rangen the method name argument if the quantity is 1" do
|
198
|
+
Randgen.should_receive(:send).with(:baz)
|
199
|
+
Randexp::Reducer.randgen([:baz], 1)
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should send Randgen the method name argument if the quantity is :+" do
|
203
|
+
Randgen.should_receive(:send).with(:foo)
|
204
|
+
Randexp::Reducer.randgen([:foo], :+)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should send Randgen the method name argument if the quantity is :*" do
|
208
|
+
Randgen.should_receive(:send).with(:bar)
|
209
|
+
Randexp::Reducer.randgen([:bar], :*)
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should send Randgen the method name argument with a length option if the quantity is a Range" do
|
213
|
+
range = 1..10
|
214
|
+
range.should_receive(:pick).and_return 7
|
215
|
+
Randgen.should_receive(:send).with(:baz, :length => 7)
|
216
|
+
Randexp::Reducer.randgen([:baz], range)
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should send Randgen the method name argument with a length option if the quantity is a Integer" do
|
220
|
+
Randgen.should_receive(:send).with(:baz, :length => 7)
|
221
|
+
Randexp::Reducer.randgen([:baz], 7)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Randexp do
|
4
|
+
describe "#initialize" do
|
5
|
+
it "should set the sexp attribute" do
|
6
|
+
Randexp.new("abcd").sexp.should_not be_nil
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".reduce" do
|
11
|
+
it "should not change the original sexp in any way" do
|
12
|
+
@randexp = Randexp.new("def")
|
13
|
+
@sexp = @randexp.sexp
|
14
|
+
|
15
|
+
@randexp.reduce
|
16
|
+
|
17
|
+
@sexp.should == @randexp.sexp
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
#describe Randexp do
|
23
|
+
# describe "#parse" do
|
24
|
+
#
|
25
|
+
# describe '("\\w")' do
|
26
|
+
# it "should be a random sexp" do
|
27
|
+
# Randexp.parse("\\w").first.should == :random
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# it "should hold a word symbol" do
|
31
|
+
# Randexp.parse("\\w").last.should == :w
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# describe '("\\s")' do
|
36
|
+
# it "should be a literal sexp" do
|
37
|
+
# Randexp.parse("\\s").first.should == :random
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# it "should hold a whitespace symbol " do
|
41
|
+
# Randexp.parse("\\s").last.should == :s
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# describe '("\\d")' do
|
46
|
+
# it "should be a literal sexp" do
|
47
|
+
# Randexp.parse("\\d").first.should == :random
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# it "should hold a digit character " do
|
51
|
+
# Randexp.parse("\\d").last.should == :d
|
52
|
+
# end
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# describe '("\\c")' do
|
56
|
+
# it "should be a literal sexp" do
|
57
|
+
# Randexp.parse("\\c").first.should == :random
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# it "should hold a digit character " do
|
61
|
+
# Randexp.parse("\\c").last.should == :c
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# describe '("(\\w)")' do
|
66
|
+
# it "should be a random sexp" do
|
67
|
+
# Randexp.parse("(\\w)").first.should == :random
|
68
|
+
# Randexp.parse("(\\w)").last.should == :w
|
69
|
+
# end
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# describe '("(\\w)(\\d)")' do
|
73
|
+
# it "should be a union between random sexp's" do
|
74
|
+
# Randexp.parse("(\\w)(\\d)").first.should == :union
|
75
|
+
# Randexp.parse("(\\w)(\\d)")[1].first.should == :random
|
76
|
+
# Randexp.parse("(\\w)(\\d)")[2].first.should == :random
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# describe '("(\\w)(\\s)(\\d)")' do
|
81
|
+
# it "should be a union between 3 sexp's" do
|
82
|
+
# Randexp.parse("(\\w)(\\s)(\\d)").first.should == :union
|
83
|
+
# Randexp.parse("(\\w)(\\s)(\\d)").size.should == 4
|
84
|
+
# end
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
# describe '("\\w*")' do
|
88
|
+
# it "should be a quantify sexp and hold a random sexp" do
|
89
|
+
# Randexp.parse("\\w*").first.should == :quantify
|
90
|
+
# Randexp.parse("\\w*")[1].first.should == :random
|
91
|
+
# Randexp.parse("\\w*")[2].should == :*
|
92
|
+
# end
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# it "should blah" do
|
96
|
+
# Randexp.parse("(\\w)|(\\d)").should == [:intersection, [:random, :w], [:random, :d]]
|
97
|
+
# end
|
98
|
+
#
|
99
|
+
# describe '("[:sentence:]")' do
|
100
|
+
# it "should be a random sexp" do
|
101
|
+
# Randexp.parse("[:sentence:]").first.should == :random
|
102
|
+
# Randexp.parse("[:sentence:]").last.should == :sentence
|
103
|
+
# end
|
104
|
+
# end
|
105
|
+
# end
|
106
|
+
#
|
107
|
+
# describe "#generate" do
|
108
|
+
# it "should return a character" do
|
109
|
+
# Randexp.new("\\w").generate.should =~ /\w/
|
110
|
+
# end
|
111
|
+
#
|
112
|
+
# it "should return a word" do
|
113
|
+
# Randexp.new("\\w+").generate.should =~ /\w+/
|
114
|
+
# end
|
115
|
+
#
|
116
|
+
# it "should return a word or an empty string" do
|
117
|
+
# Randexp.new("\\w*").generate.should =~ /\w*/
|
118
|
+
# end
|
119
|
+
#
|
120
|
+
# it "should return a word with 4 to 5 characters" do
|
121
|
+
# Randexp.new("\\w{4,5}").generate.should =~ /\w{4,5}/
|
122
|
+
# end
|
123
|
+
#
|
124
|
+
# it "should return a digit" do
|
125
|
+
# Randexp.new("\\d").generate.should =~ /\d/
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# it "should return a 2 to 10 digit number" do
|
129
|
+
# Randexp.new("\\d{2,10}").generate.should =~ /\d{2,10}/
|
130
|
+
# end
|
131
|
+
#
|
132
|
+
# it "should return a digit or empty string" do
|
133
|
+
# Randexp.new("\\d?").generate.should =~ /\d?/
|
134
|
+
# end
|
135
|
+
#
|
136
|
+
# it "should return a digit or a character" do
|
137
|
+
# Randexp.new("\\d|\\w").generate.should =~ /\w|\d/
|
138
|
+
# end
|
139
|
+
#
|
140
|
+
# it "should return a word or a 3 digit number" do
|
141
|
+
# Randexp.new("\\d{3}|\\w+").generate.should =~ /\w+|d{3}/
|
142
|
+
# end
|
143
|
+
#
|
144
|
+
# it "should return a word or number" do
|
145
|
+
# Randexp.new("\\w+|\\d{3}").generate.should =~ /\w+|d{3}/
|
146
|
+
# end
|
147
|
+
#
|
148
|
+
# it "should return a sentence" do
|
149
|
+
# Randexp.new("[:sentence:]").generate.should =~ /(\w+\s)*\w+/
|
150
|
+
# end
|
151
|
+
#
|
152
|
+
# it "should handle a telephone number" do
|
153
|
+
# 100.times do
|
154
|
+
# Randexp.new("(\\d{3}-)?\\d{3}-\\d{4}").generate.should =~ /(\d{3}-)?\d{3}-\d{4}/
|
155
|
+
# end
|
156
|
+
# end
|
157
|
+
# end
|
158
|
+
#end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Randgen do
|
4
|
+
describe ".bool" do
|
5
|
+
it "should return 'true' or 'false'" do
|
6
|
+
100.times do
|
7
|
+
['true', 'false'].should include(Randgen.bool)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".lchar" do
|
13
|
+
it "should return 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', or 'z'" do
|
14
|
+
100.times do
|
15
|
+
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'].should include(Randgen.lchar)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".uchar" do
|
21
|
+
it "should return 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', or 'Z'" do
|
22
|
+
100.times do
|
23
|
+
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'].should include(Randgen.uchar)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".char" do
|
29
|
+
it "should return 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', or 'z'" do
|
30
|
+
100.times do
|
31
|
+
['A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z'].should include(Randgen.char)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".whitespace" do
|
37
|
+
it "should return '\\t', '\\n', '\\r', or '\\f'" do
|
38
|
+
100.times do
|
39
|
+
["\t", "\n", "\r", "\f"].should include(Randgen.whitespace)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe ".digit" do
|
45
|
+
it "should return '0', '1', '2', '3', '4', '5', '6', '7', '8', or '9'" do
|
46
|
+
100.times do
|
47
|
+
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].should include(Randgen.digit)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe ".alpha_numeric" do
|
53
|
+
it "should return 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', or '9'" do
|
54
|
+
100.times do
|
55
|
+
['A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].should include(Randgen.alpha_numeric)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ".word" do
|
61
|
+
it "should pick an entry from Dictionary" do
|
62
|
+
10.times do
|
63
|
+
Dictionary.words.should include(Randgen.word)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should pick a word with a length if the length option is supplied" do
|
68
|
+
10.times do
|
69
|
+
length = (3..10).pick
|
70
|
+
Randgen.word(:length => length).length.should == length
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe ".sentence" do
|
76
|
+
it "should be capitalized" do
|
77
|
+
10.times do
|
78
|
+
Randgen.sentence.should =~ /^[A-Z]/
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe ".paragraph" do
|
84
|
+
it "should end in a period" do
|
85
|
+
10.times do
|
86
|
+
Randgen.paragraph.should =~ /\.$/
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe ".phone_number" do
|
92
|
+
it "should match /(\\d{3}-)?\\d{3}-\\d{4}/ when no length is given" do
|
93
|
+
100.times do
|
94
|
+
Randgen.phone_number =~ /(\d{3}-)?\d{3}-\d{4}/
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should match /\\d{3}-\\d{4}/ when the length is 7" do
|
99
|
+
100.times do
|
100
|
+
Randgen.phone_number(:length => 7) =~ /\d{3}-\d{4}/
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should match /\\d{3}-\\d{3}-\\d{4}/ when the length is 10" do
|
105
|
+
100.times do
|
106
|
+
Randgen.phone_number(:length => 10) =~ /\d{3}-\d{3}-\d{4}/
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: randexp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Burkert
|
8
|
+
autorequire: randexp
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-07-18 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Library for generating random strings.
|
17
|
+
email: ben@benburkert.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
- LICENSE
|
25
|
+
- TODO
|
26
|
+
files:
|
27
|
+
- LICENSE
|
28
|
+
- README
|
29
|
+
- Rakefile
|
30
|
+
- TODO
|
31
|
+
- CHANGELOG
|
32
|
+
- lib/core_ext
|
33
|
+
- lib/core_ext/array.rb
|
34
|
+
- lib/core_ext/integer.rb
|
35
|
+
- lib/core_ext/range.rb
|
36
|
+
- lib/core_ext/regexp.rb
|
37
|
+
- lib/core_ext.rb
|
38
|
+
- lib/dictionary.rb
|
39
|
+
- lib/randexp
|
40
|
+
- lib/randexp/parser.rb
|
41
|
+
- lib/randexp/reducer.rb
|
42
|
+
- lib/randexp.rb
|
43
|
+
- lib/randgen.rb
|
44
|
+
- spec/regression
|
45
|
+
- spec/regression/regexp_spec.rb
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
- spec/unit
|
48
|
+
- spec/unit/core_ext
|
49
|
+
- spec/unit/core_ext/regexp_spec.rb
|
50
|
+
- spec/unit/randexp
|
51
|
+
- spec/unit/randexp/parser_spec.rb
|
52
|
+
- spec/unit/randexp/reducer_spec.rb
|
53
|
+
- spec/unit/randexp_spec.rb
|
54
|
+
- spec/unit/randgen_spec.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/benburkert/randexp
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.2.0
|
78
|
+
signing_key:
|
79
|
+
specification_version: 2
|
80
|
+
summary: Library for generating random strings.
|
81
|
+
test_files: []
|
82
|
+
|