regextest 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b51a91bb714731ac6c008e71cc768024e7125ae0
4
- data.tar.gz: e6f0cf1de571dc253c9097313c067763e4b09b14
3
+ metadata.gz: 1ebc162f43002fb402e523b7d9a504a9593cce57
4
+ data.tar.gz: ef3b47e4e0b53e2d8a0c2eac831688fe805fe6c2
5
5
  SHA512:
6
- metadata.gz: 7e2cafea68bc1bde41e965fd3348c4bc8e4ad4160f96acb506081faa5b0db0d440461a879e5b6400bfa0dc8e04f4df3bc1276df26b7dc00e257c5bed72e5ef6e
7
- data.tar.gz: 8848c862ab67d58fc053798d71139c84e84c5be3ccb6fb8651bb22dc9cb51ce70c728a613e6168773fc523b9d240913b53706e4914068496a54a3a6cf84374bf
6
+ metadata.gz: 642b88f4089090dad4b15a4b7b9486987d5d6ffd9a8c7ff7e76e6a95c6d6e51852718adc76e09e9a7589f66815d302dfa7c4ef44af70c7672667cd93b73cc545
7
+ data.tar.gz: 04c4b88d7f133428f2594fc6a7d623030702d01444f3846ca3d34839b2bd46b3d30e4c5a0a7da718bed5468c8e515aeebee16d5aca8f928235f2ee1af65fad22
data/Rakefile CHANGED
@@ -20,21 +20,21 @@ file 'lib/regextest/front/bracket-parser.rb' => 'lib/regextest/front/bracket-par
20
20
  end
21
21
 
22
22
  # Generating Unicode parser
23
- file 'lib/regextest/front/unicode.rb' => 'lib/pre-unicode.rb' do
24
- puts "making regextest/front/unicode.rb"
25
- sh 'ruby lib/pre-unicode.rb'
23
+ file 'lib/regextest/unicode.rb' => 'lib/pre/unicode.rb' do
24
+ puts "making regextest/unicode.rb"
25
+ sh 'ruby lib/pre/unicode.rb'
26
26
  end
27
27
 
28
28
  # Generating case-folding mapping
29
- file 'lib/regextest/front/case-folding.rb' => 'lib/pre-case-folding.rb' do
29
+ file 'lib/regextest/front/case-folding.rb' => 'lib/pre/case-folding.rb' do
30
30
  puts "making regextest/front/case-folding.rb"
31
- sh 'ruby lib/pre-case-folding.rb'
31
+ sh 'ruby lib/pre/case-folding.rb'
32
32
  end
33
33
 
34
34
  # Generating regression test suite
35
- file 'spec/regression_spec.rb' => 'lib/pre-generate-spec.rb' do
35
+ file 'spec/regression_spec.rb' => 'lib/pre/generate-spec.rb' do
36
36
  puts "making spec/regression_spec.rb"
37
- sh 'ruby lib/pre-generate-spec.rb'
37
+ sh 'ruby lib/pre/generate-spec.rb'
38
38
  end
39
39
 
40
40
  # Generating documents
@@ -46,8 +46,8 @@ end
46
46
  task :make =>
47
47
  ['lib/regextest/front/parser.rb',
48
48
  'lib/regextest/front/bracket-parser.rb',
49
- 'lib/regextest/front/unicode.rb',
50
49
  'lib/regextest/front/case-folding.rb',
50
+ 'lib/regextest/unicode.rb',
51
51
  'spec/regression_spec.rb',
52
52
  'doc/index.html',
53
53
  ] do
@@ -13,7 +13,7 @@ class RegextestPreUnicode
13
13
  # Get valid properties of Ruby
14
14
  onig_properties = read_onig_properties("./contrib/Onigmo/UnicodeProps.txt")
15
15
  ranges = get_ranges_of_properties(onig_properties)
16
- puts_unicode_ranges('lib/regextest/front/unicode.rb', ranges)
16
+ puts_unicode_ranges('lib/regextest/unicode.rb', ranges)
17
17
  end
18
18
 
19
19
  # Get list of Unicode classes from Onigmo manual
@@ -85,13 +85,14 @@ class RegextestPreUnicode
85
85
  # DO NOT Modify This File Since Automatically Generated
86
86
 
87
87
  # Range of Unicode
88
- class Regextest::Front::Unicode
88
+ class Regextest::Unicode
89
89
  # Generate hash of properties
90
90
  def self.property(class_name)
91
91
  case class_name.downcase
92
92
  #{ranges_source}
93
93
  else
94
- raise "Internal error. Class name (#\{class_name\}) not found"
94
+ warn "Class name (#\{class_name\}) not found. Ignored."
95
+ []
95
96
  end
96
97
  end
97
98
 
@@ -46,11 +46,8 @@ class Regextest
46
46
  # Parse string
47
47
  @front_end = Regextest::Front.new(@reg_string, @@parse_options)
48
48
 
49
- # To json (use json format for backend)
50
- @json_obj = @front_end.get_json_obj
51
-
52
49
  # Prepare back-end process. (use generate method for generating string)
53
- @back_end = Regextest::Back.new(@json_obj)
50
+ @back_end = Regextest::Back.new(@front_end)
54
51
 
55
52
  @result = nil
56
53
  @reason = nil
@@ -75,11 +72,11 @@ class Regextest
75
72
  # @raise [RuntimeError] if something wrong...
76
73
  # @raise [Regextest::RegextestTimeout] if detected timeout while verification. Option 'verification: false' may be workaround.
77
74
  def generate
78
- TstConstRetryMax.times do
75
+ TstConstRetryMax.times do | retry_count |
79
76
 
80
77
  # generate string
81
78
  reset_random_called
82
- @result = @back_end.generate
79
+ @result = @back_end.generate(retry_count)
83
80
  if !@result
84
81
  TstLog "NG: Failed to generate"
85
82
  @reason = :failed_to_generate
@@ -143,14 +140,14 @@ class Regextest
143
140
  @reg_string = new_param
144
141
  @reg_exp = /#{@reg_string}/
145
142
  end
146
- @@parse_options[:reg_source] = @reg_string
147
143
  when Regexp
148
144
  @reg_exp = param
149
145
  @@parse_options[:reg_options].set(@reg_exp.options) # inner regex options have priorty
150
- @reg_string = @reg_exp.source
146
+ @reg_string = "#{@reg_exp}" # this generates string with options
151
147
  else
152
148
  raise "Error: string or regular expression required"
153
149
  end
150
+ @@parse_options[:reg_source] = @reg_string
154
151
  end
155
152
 
156
153
  # add built-in functions if any
@@ -213,20 +210,22 @@ if __FILE__ == $0
213
210
  begin
214
211
 
215
212
  regex = ARGV[0] || $<
213
+
216
214
  if(regex == "reg")
217
- regex = /ab # comment
215
+ regex = /(?ix:ab # comment
218
216
  [a-z]{5,10}
219
- cd /ix
217
+ cd )/
220
218
  end
219
+
221
220
  if(regex == "reg2")
222
- regex = %r(
221
+ regex = %r((?x:
223
222
  (?<name> [a-zA-Z_:]+ ){0}
224
223
  (?<stag> < \g<name> > ){0}
225
- (?<content> ||\w+|\w+|\w+ (\g<element> | \w+)* ){0}
224
+ (?<content> \w+ (\g<element> | \w+)* ){0}
226
225
  (?<etag> </ \k<name+1> >){0}
227
226
  (?<element> \g<stag> \g<content>* \g<etag> ){0}
228
227
  \g<element>
229
- )x
228
+ ))x
230
229
  end
231
230
 
232
231
  begin
@@ -11,23 +11,25 @@ class Regextest::Back
11
11
  include Regextest::Common
12
12
 
13
13
  # Constructor
14
- def initialize(json_obj)
15
- @reg_source = @@parse_options[:reg_source]
16
- @json_obj = json_obj
14
+ def initialize(front_end)
15
+ # To json (use json format for backend)
16
+ @parsed_object = front_end.get_object
17
+ @parse_result = @parsed_object["regex"]
18
+ @reg_source = @parsed_object["source"]
17
19
 
18
20
  # COMMENTED OUT at present
19
21
  # make a hash to manage names and corresponding objects
20
- # @name_hash = make_name_hash(@json_obj, {})
22
+ # @name_hash = make_name_hash(@parse_result, {})
21
23
  # get test cases (commented at present)
22
- # @test_info = Regextest::Back::TestCase.new(@json_obj, @name_hash)
24
+ # @test_info = Regextest::Back::TestCase.new(@parse_result, @name_hash)
23
25
 
24
26
  # default max recursion is 8.
25
27
  @max_nest = TstConstRecursionMax
26
28
  end
27
29
 
28
30
  # A public method that generates string to match the regexp
29
- def generate
30
- generate_obj = Regextest::Back::Main.new(@json_obj, @max_nest)
31
+ def generate(retry_count = 0)
32
+ generate_obj = Regextest::Back::Main.new(@parse_result, @max_nest, retry_count)
31
33
  generate_obj.generate
32
34
  end
33
35
 
@@ -9,9 +9,10 @@ require 'regextest/back/result'
9
9
  # Main class of back-end. Construct candidates array and narrow down
10
10
  class Regextest::Back::Main
11
11
  include Regextest::Common
12
- def initialize(json_obj, max_nest)
12
+ def initialize(json_obj, max_nest, retry_count = 0)
13
13
  @json_obj = json_obj
14
14
  @max_nest = max_nest
15
+ @retry_count = retry_count
15
16
  @parens_hash = {} # hash to keep string generated by parentheses
16
17
  @nest = 0 # current nest of back-reference
17
18
  @quit_mode = false # flag for preventing from increase of nest
@@ -228,12 +229,19 @@ class Regextest::Back::Main
228
229
  # repeat
229
230
  def generate_candidates_repeat(param)
230
231
  target = param[:json]
232
+ max_repeat = target["max_repeat"]
233
+ min_repeat = target["min_repeat"]
234
+
235
+ if @retry_count > 0
236
+ @retry_count.times{ max_repeat = (max_repeat + 1)/2 }
237
+ end
238
+
231
239
  if(@quit_mode)
232
- repeat = target["min_repeat"]
233
- elsif(target["max_repeat"] > target["min_repeat"])
234
- repeat = target["min_repeat"]+TstRand(target["max_repeat"]-target["min_repeat"]+1)
240
+ repeat = min_repeat
241
+ elsif(max_repeat > min_repeat)
242
+ repeat = min_repeat + TstRand(max_repeat - min_repeat + 1)
235
243
  else
236
- repeat = target["min_repeat"]
244
+ repeat = min_repeat
237
245
  end
238
246
  result = []
239
247
  if target["repeat_option"].index("reluctant")
@@ -273,7 +281,13 @@ class Regextest::Back::Main
273
281
  def generate_candidates_back_refer(param)
274
282
  target = param[:json]
275
283
  if @parens_hash[target["refer_name"]][:generated]
276
- relative_num = (target["relative_num"]=="")?(-1):(@nest + target["relative_num"].to_i)
284
+ relative_num = -1 # default value
285
+ if target["relative_num"] != ""
286
+ work = @nest + target["relative_num"].to_i
287
+ return nil if(work < 0 || !@parens_hash[target["refer_name"]][:generated][work])
288
+ relative_num = work
289
+ end
290
+ # puts "relative: #{relative_num}, nest=#{@nest}, :#{target}"
277
291
  result = @parens_hash[target["refer_name"]][:generated][relative_num]
278
292
  else
279
293
  result = nil
@@ -16,6 +16,9 @@ class Regextest::Front
16
16
  def initialize(reg_string, options)
17
17
  @options = options
18
18
 
19
+ # Json option as a workaround for ruby 1.9.*
20
+ @json_option = { max_nesting: 999 }
21
+
19
22
  # scanning the string
20
23
  scanner = Regextest::Front::Scanner.new
21
24
  lex_words = scanner.scan(reg_string)
@@ -27,30 +30,31 @@ class Regextest::Front
27
30
  @parser = RegextestFrontParser.new
28
31
 
29
32
  # Do parse
30
- @obj = @parser.parse(lex_words, @options)
33
+ @parse_result = @parser.parse(lex_words, @options)
31
34
 
32
35
  # process options
33
- @obj.set_options(options)
36
+ @parse_result.set_options(options)
34
37
 
35
38
  # sort parentheses, since number of parenthesis is by offset-order (not by parsing-order)
36
39
  @options[:parens].sort
37
40
 
38
- @obj
41
+ @parse_result
39
42
  end
40
43
 
41
44
  # Output JSON format parse result of the regex
42
- def get_json_obj(result = @obj)
43
- option = { max_nesting: 999} # work around for ruby 1.9.*
44
- json_obj = JSON.parse(result.json, option)
45
- TstLog("JSON param:\n" + JSON.pretty_generate(json_obj, option))
46
- json_obj
45
+ def get_object
46
+ json_obj = JSON.parse(@parse_result.json, @json_option)
47
+ parsed_object = {
48
+ "regex" => json_obj,
49
+ "source" => @options[:reg_source]
50
+ }
51
+ TstLog("JSON param:\n" + JSON.pretty_generate(parsed_object, @json_option))
52
+ parsed_object
47
53
  end
48
54
 
49
55
  # Return JSON string
50
- def get_json_string(result = @obj)
51
- json_obj = get_json_obj(result)
52
- option = { max_nesting: 999} # work around for ruby 1.9.*
53
- JSON.pretty_generate(json_obj, option)
56
+ def get_json_string
57
+ JSON.pretty_generate(get_object, @json_option)
54
58
  end
55
59
 
56
60
  end
@@ -45,7 +45,7 @@ module Regextest::Front::BackRefer
45
45
  raise "internal error: unexpected refer #{value}"
46
46
  end
47
47
  if md[5]
48
- @relative_num = md[3].to_i
48
+ @relative_num = md[5].to_i
49
49
  end
50
50
  else
51
51
  raise "Error: Internal error, invalid named reference"
@@ -40,8 +40,8 @@ class Regextest::Front::BracketScanner
40
40
  /-(?!\]|\z)/ ], # a letter must succeeds to minus
41
41
  [:LEX_AND_AND,
42
42
  %r!\&\&! ],
43
- [:LEX_SPECIAL_LETTER,
44
- %r!\\[RX]! ],
43
+ # [:LEX_SPECIAL_LETTER, # special letters are not valid in bracket
44
+ # %r!\\[RX]! ],
45
45
  [:LEX_ESCAPED_LETTER,
46
46
  %r!\\.! ], # \b is valid within character class
47
47
  [:LEX_SPACE,
@@ -6,7 +6,7 @@ require 'regextest/common'
6
6
  require 'regextest/front/range' # Range of character
7
7
  require 'regextest/front/case-folding' # case folding class
8
8
  require 'regextest/regex-option' # Options of regex
9
- require 'regextest/front/unicode'
9
+ require 'regextest/unicode'
10
10
 
11
11
  # character class elements
12
12
  module Regextest::Front::CharClass
@@ -40,7 +40,7 @@ module Regextest::Front::CharClass
40
40
  class_names = value
41
41
  @candidates = []
42
42
  class_names.split("|").each do | class_name |
43
- work = Regextest::Front::Unicode.property(class_name) ||
43
+ work = Regextest::Unicode.property(class_name) ||
44
44
  raise("Invalid Unicode class #{class_name}")
45
45
  # construct char class
46
46
  @candidates += work.map{|elem| TRange.new(elem[0], elem[1])}
@@ -153,19 +153,16 @@ module Regextest::Front::CharClass
153
153
 
154
154
  # Get whole code set of ascii
155
155
  def get_ascii_whole_set
156
- # require 'regextest/front/unicode'
157
- # same as [ TRange.new("\x20", "\x7e") ]
158
- ascii_set = Regextest::Front::Unicode.enumerate("ascii")
159
- print_set = Regextest::Front::Unicode.enumerate("print")
156
+ ascii_set = Regextest::Unicode.enumerate("ascii")
157
+ print_set = Regextest::Unicode.enumerate("print")
160
158
  ascii_set & print_set
161
159
  end
162
160
 
163
161
  # Get whole code set of unicode
164
162
  def get_unicode_whole_set
165
- # require 'regextest/front/unicode'
166
163
  char_set = []
167
164
  TstConstUnicodeCharSet.split("|").each do | elem |
168
- char_set |= Regextest::Front::Unicode.enumerate(elem)
165
+ char_set |= Regextest::Unicode.enumerate(elem)
169
166
  end
170
167
  char_set
171
168
  end
@@ -6,7 +6,6 @@ require 'regextest/common'
6
6
  require 'regextest/front/char-class' # character class element
7
7
  require 'regextest/front/range' # range of character point
8
8
  require 'regextest/regex-option'
9
- require 'regextest/front/unicode'
10
9
 
11
10
  # A letter
12
11
  module Regextest::Front::Letter
@@ -179,37 +178,23 @@ module Regextest::Front::Letter
179
178
 
180
179
  # generate Unicode class (ie. \p{...} | \P{...})
181
180
  def generate_unicode_char(val)
182
- # Dynamic loading of Unicode regarding modules (for better performance).
183
- # commented out since this code not executed at ruby 2.0.0
184
- # require 'regextest/front/unicode'
185
-
186
181
  if(md = val.match(/(p|P)\{(\^?)(\w+)\}/))
187
182
  class_name = md[3].downcase
188
183
  reverse = (md[2] && md[2]=="^")?true:false
189
184
 
190
- # if not found at cache
191
- if !@@unicode_ranges[class_name]
192
- #work = Regextest::Front::Unicode.property(class_name) ||
193
- # raise("Invalid Unicode class #{class_name} in #{val}")
194
- # construct char class
195
- #work = work.map{|elem| TRange.new(elem[0], elem[1])}
196
- @@unicode_ranges[class_name] = CharClass.new(class_name)
197
- end
185
+ obj = CharClass.new(class_name)
198
186
  else
199
187
  raise "Internal error, inconsistent Unicode class #{val}"
200
188
  end
201
189
 
202
190
  # ¥P{^...} is equivalent to \p{...}
203
191
  if((md[1] == "p" && !reverse) || (md[1] == "P" && reverse))
204
- @@unicode_ranges[class_name]
192
+ obj
205
193
  else # \P{} or \p{^}
206
- @@unicode_ranges[class_name].set_reverse(@options)
194
+ obj.set_reverse(@options)
207
195
  end
208
196
  end
209
197
 
210
- def classname_to_ranges(arrays)
211
- end
212
-
213
198
  # generate POSIX character class (ie. [[:alpha:]], etc.)
214
199
  def generate_char_class(val)
215
200
  if(md = val.match(/^\[\:(\^)?(\w+)\:\]$/))
@@ -2,7 +2,7 @@
2
2
  # DO NOT Modify This File Since Automatically Generated
3
3
 
4
4
  # Range of Unicode
5
- class Regextest::Front::Unicode
5
+ class Regextest::Unicode
6
6
  # Generate hash of properties
7
7
  def self.property(class_name)
8
8
  case class_name.downcase
@@ -1257,7 +1257,8 @@ class Regextest::Front::Unicode
1257
1257
  when "in_no_block"
1258
1258
  ([[2144, 2207], [6832, 6911], [7296, 7359], [12256, 12271], [43488, 43519], [43824, 43967], [66048, 66175], [66272, 66303], [66384, 66431], [66528, 66559], [66736, 67583], [67680, 67839], [67904, 67967], [68224, 68351], [68480, 68607], [68688, 69215], [69248, 69631], [69968, 70015], [70112, 71295], [71376, 73727], [74880, 77823], [78896, 92159], [92736, 93951], [94112, 110591], [110848, 118783], [119376, 119551], [119680, 119807], [120832, 126463], [126720, 126975], [128592, 128639], [128896, 131071], [173792, 173823], [178208, 194559], [195104, 917503], [917632, 917759], [918000, 983039]])
1259
1259
  else
1260
- raise "Internal error. Class name (#{class_name}) not found"
1260
+ warn "Class name (#{class_name}) not found. Ignored."
1261
+ []
1261
1262
  end
1262
1263
  end
1263
1264
 
@@ -1,5 +1,5 @@
1
1
  # Copyright (C) 2016 Mikio Ikoma
2
2
 
3
3
  class Regextest
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regextest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - IKOMA, Mikio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-31 00:00:00.000000000 Z
11
+ date: 2016-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby
@@ -128,10 +128,10 @@ files:
128
128
  - contrib/unicode/README.txt
129
129
  - contrib/unicode/Scripts.txt
130
130
  - contrib/unicode/UnicodeData.txt
131
- - lib/pre-case-folding.rb
132
- - lib/pre-generate-spec.rb
133
- - lib/pre-posix-char-class.rb
134
- - lib/pre-unicode.rb
131
+ - lib/pre/case-folding.rb
132
+ - lib/pre/generate-spec.rb
133
+ - lib/pre/posix-char-class.rb
134
+ - lib/pre/unicode.rb
135
135
  - lib/regextest.rb
136
136
  - lib/regextest/back.rb
137
137
  - lib/regextest/back/element.rb
@@ -162,9 +162,9 @@ files:
162
162
  - lib/regextest/front/scanner.rb
163
163
  - lib/regextest/front/selectable.rb
164
164
  - lib/regextest/front/sequence.rb
165
- - lib/regextest/front/unicode.rb
166
165
  - lib/regextest/regex-option.rb
167
166
  - lib/regextest/regexp.rb
167
+ - lib/regextest/unicode.rb
168
168
  - lib/regextest/version.rb
169
169
  - lib/tst-reg-test.rb
170
170
  - regextest.gemspec