lib/regextest.rb in regextest-0.1.4 vs lib/regextest.rb in regextest-0.1.5
- old
+ new
@@ -44,15 +44,12 @@
set_regex(regex)
# Parse string
@front_end = Regextest::Front.new(@reg_string, @@parse_options)
- # To json (use json format for backend)
- @json_obj = @front_end.get_json_obj
-
# Prepare back-end process. (use generate method for generating string)
- @back_end = Regextest::Back.new(@json_obj)
+ @back_end = Regextest::Back.new(@front_end)
@result = nil
@reason = nil
end
@@ -73,15 +70,15 @@
# @return [String] if matched without verification (i.e. return unverified matched string).
# @return [nil] nil if failed to generate
# @raise [RuntimeError] if something wrong...
# @raise [Regextest::RegextestTimeout] if detected timeout while verification. Option 'verification: false' may be workaround.
def generate
- TstConstRetryMax.times do
+ TstConstRetryMax.times do | retry_count |
# generate string
reset_random_called
- @result = @back_end.generate
+ @result = @back_end.generate(retry_count)
if !@result
TstLog "NG: Failed to generate"
@reason = :failed_to_generate
if !is_random?
raise(RegextestError, "It is impossible to generate sample string of #{@reg_string}.")
@@ -141,18 +138,18 @@
else
new_param = check_builtin(param)
@reg_string = new_param
@reg_exp = /#{@reg_string}/
end
- @@parse_options[:reg_source] = @reg_string
when Regexp
@reg_exp = param
@@parse_options[:reg_options].set(@reg_exp.options) # inner regex options have priorty
- @reg_string = @reg_exp.source
+ @reg_string = "#{@reg_exp}" # this generates string with options
else
raise "Error: string or regular expression required"
end
+ @@parse_options[:reg_source] = @reg_string
end
# add built-in functions if any
def check_builtin(param)
builtin_functions = {}
@@ -211,23 +208,25 @@
include Regextest::Common
begin
regex = ARGV[0] || $<
+
if(regex == "reg")
- regex = /ab # comment
+ regex = /(?ix:ab # comment
[a-z]{5,10}
- cd /ix
+ cd )/
end
+
if(regex == "reg2")
- regex = %r(
+ regex = %r((?x:
(?<name> [a-zA-Z_:]+ ){0}
(?<stag> < \g<name> > ){0}
- (?<content> ||\w+|\w+|\w+ (\g<element> | \w+)* ){0}
+ (?<content> \w+ (\g<element> | \w+)* ){0}
(?<etag> </ \k<name+1> >){0}
(?<element> \g<stag> \g<content>* \g<etag> ){0}
\g<element>
- )x
+ ))x
end
begin
if ARGV[1]
reg = eval "/#{regex}/#{ARGV[1]}"