list_matcher 1.1.8 → 1.3.0

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
- SHA1:
3
- metadata.gz: 7cd4faa0dd3bafd7a1933d14d325056175c28886
4
- data.tar.gz: 895da5871b03ba84b0d41bade4ed9aaa45231b0c
2
+ SHA256:
3
+ metadata.gz: 895b21759da8028bb27576efe53424aeebc24bbb7e4c502c9e0b2f26d9848cc5
4
+ data.tar.gz: 843190f593c37a11a8334eaa4e673024a5f96c074b8a8d407696488091022f1a
5
5
  SHA512:
6
- metadata.gz: 944331095b454a924a047f7c1f96bae2c8254b4e092622e185de66e35063a6f698e1e8c3a45f99cebe7c4e2077203987cb94bb53d4ffb2720eb601f7a055a032
7
- data.tar.gz: eb3ad634394d9fa378f206117e47b553e3f21c032a95cd284b5591c81893374cdc69330c2f48f9e0e1f2693e13e96b391c45eb71b470567527d636b7e25aeaa6
6
+ metadata.gz: '099e6afe3e5974a96ad2532cbfe9961daa164624aad06bac59dcd402cd589b5934b7bc2836f3f821529da6385ce541dabce53c57486b241913b4b0dbd0312769'
7
+ data.tar.gz: 1a0f02e3ae50f5be8929703b0572d3ef27bbcb3896175b1961ab783f15d4ea158df03873b4572e03c7a8f1f665d9a3fb9699f9adb139e9878050a635501f7fda
data/CHANGELOG.md ADDED
@@ -0,0 +1,68 @@
1
+ # Changelog
2
+
3
+ ## v1.3.0 *2026-11-28*
4
+ - Modernized for current Ruby:
5
+ - Require Ruby >= 3.0; added `# frozen_string_literal: true`
6
+ - Public methods now take keyword arguments (`**opts`) instead of positional option hashes
7
+ - Replaced legacy idioms with modern equivalents (`Hash[]` → `to_h`, `reduce(0, :+)` → `sum`, `chars` → `each_char`, endless ranges)
8
+ - Single-pass list cleanup in `Matcher#pattern` (compact, stringify, strip, normalize whitespace)
9
+ - Optimized pattern generation: `best_prefix`/`best_suffix` now group prefix/suffix candidates without sorting single-element groups or rebuilding discarded cross products (~15-20% faster on large word lists, output unchanged)
10
+ - Gemspec: modern development dependencies, added `spec.metadata` URIs, squiggly heredoc; dropped unused `byebug` dev dependency
11
+
12
+ ## v1.2.0 *2026-11-15*
13
+ - Port fixes from list-matcher-js v1.0.4:
14
+ - Update CharClass#cc_quote to use hex escapes for control characters 1-8 (\\x01-\\x08) for improved readability
15
+ - Add named escapes for control characters 9-13 and 27 (\\t, \\n, \\v, \\f, \\r, \\e)
16
+ - Add comprehensive Unicode tests for emoji, supplementary plane characters, zero-width characters, combined Unicode, and control characters
17
+
18
+ ## v1.1.8 *2018-05-28*
19
+ - Renamed for clarity
20
+ - Removed some whitespace
21
+ - Suppressed some error messages thrown during rake test
22
+ - Tinkered with gemspec to remove all warnings
23
+ - Fixed problem with wide characters in character classes
24
+
25
+ ## v1.1.7 *2016-01-19*
26
+ - Bumped version number
27
+ - Properly handle empty list
28
+ - Removed some unnecessary code
29
+
30
+ ## v1.0.7 *2016-01-19*
31
+ - Bumped version number (release)
32
+
33
+ ## v1.0.6 *2015-09-04*
34
+ - Bumped version number
35
+ - Improved mini grammar
36
+ - Improved doc tests to include new symbol stuff
37
+ - Better documentation
38
+ - Documentation of the symbol boundary stuff
39
+ - Fixed short bound word bug
40
+ - Made bounds work with symbols
41
+ - More refactoring to make code comprehensible
42
+ - Small simplification
43
+
44
+ ## v1.0.5 *2015-09-01*
45
+ - Bumped version number
46
+ - Improved docs
47
+ - Implemented List::Matcher::Error
48
+ - Partially implemented tests
49
+
50
+ ## v1.0.4 *2015-08-30*
51
+ - Allow bounding only at the left or right margin
52
+
53
+ ## v1.0.3 *2015-08-18*
54
+ - Bumped version number before release
55
+ - Documentation improvements
56
+ - Removed optional symbol bug
57
+
58
+ ## v1.0.2 *2015-08-16*
59
+ - Documentation improvements
60
+ - Added the not_extended option
61
+ - Added test to make sure all the documentation examples are good
62
+
63
+ ## v1.0.1 *2015-08-16*
64
+ - Bumped least version number
65
+ - Set minimum ruby version
66
+
67
+ ## v1.0.0 *2015-08-16*
68
+ - Initial release
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ListMatcher
2
- VERSION = "1.1.8"
4
+ VERSION = "1.3.0"
3
5
  end
data/lib/list_matcher.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "list_matcher/version"
2
4
 
3
5
  module List
@@ -11,12 +13,12 @@ module List
11
13
 
12
14
  # convenience method for one-off regexen where there's no point in keeping
13
15
  # around a pattern generator
14
- def self.pattern(list, opts={})
16
+ def self.pattern(list, **opts)
15
17
  self.new(**opts).pattern list
16
18
  end
17
19
 
18
20
  # like self.pattern, but returns a regex rather than a string
19
- def self.rx(list, opts={})
21
+ def self.rx(list, **opts)
20
22
  self.new(**opts).rx list
21
23
  end
22
24
 
@@ -57,6 +59,8 @@ module List
57
59
  rescue
58
60
  raise Error, "#{name} does not work as the name of a named group"
59
61
  end
62
+ else
63
+ @name = nil
60
64
  end
61
65
  case bound
62
66
  when TrueClass
@@ -87,7 +91,7 @@ module List
87
91
  @left_bound = nil
88
92
  end
89
93
  when Hash
90
- @word_test = bound[:test] || raise( Error, 'no boundary test provided' )
94
+ @word_test = bound[:test] || raise(Error, 'no boundary test provided')
91
95
  @left_bound = bound[:left]
92
96
  @right_bound = bound[:right]
93
97
  raise Error, 'neither bound provided' unless @left_bound || @right_bound
@@ -121,7 +125,7 @@ module List
121
125
  end
122
126
 
123
127
  # returns a new pattern matcher differing from the original only in the options specified
124
- def bud(opts={})
128
+ def bud(**opts)
125
129
  opts = {
126
130
  atomic: @atomic,
127
131
  backtracking: @backtracking,
@@ -138,13 +142,17 @@ module List
138
142
  self.class.new(**opts)
139
143
  end
140
144
 
141
- # converst list into a string representing a regex pattern suitable for inclusion in a larger regex
142
- def pattern( list, opts={} )
145
+ # converts list into a string representing a regex pattern suitable for inclusion in a larger regex
146
+ def pattern( list, **opts )
143
147
  return '(?!)' unless list.any?
144
- return bud(opts).pattern list unless opts.empty?
145
- list = list.compact.map(&:to_s).select{ |s| s.length > 0 }
146
- list.map!(&:strip).select!{ |s| s.length > 0 } if strip
147
- list.map!{ |s| s.gsub /\s++/, ' ' } if normalize_whitespace
148
+ return bud(**opts).pattern list unless opts.empty?
149
+ list = list.filter_map do |e|
150
+ s = e&.to_s
151
+ next if s.nil? || s.empty?
152
+ s = s.strip if strip
153
+ next if s.empty?
154
+ normalize_whitespace ? s.gsub(/\s++/, ' ') : s
155
+ end
148
156
  return nil if list.empty?
149
157
  specializer = Special.new self, @symbols, list
150
158
  list = specializer.normalize
@@ -178,8 +186,8 @@ module List
178
186
  end
179
187
 
180
188
  # like pattern but it returns a regex instead of a string
181
- def rx(list, opts={})
182
- Regexp.new pattern(list, opts)
189
+ def rx(list, **opts)
190
+ Regexp.new pattern(list, **opts)
183
191
  end
184
192
 
185
193
  def pfx
@@ -198,10 +206,10 @@ module List
198
206
  @wrap_size ||= pfx.length + 1
199
207
  end
200
208
 
201
- def tree(list, symbols)
209
+ def tree(list, specializer)
202
210
  if list.size == 1
203
- leaves = list[0].chars.map do |c|
204
- symbols[c] || Leaf.new( self, c )
211
+ leaves = list[0].each_char.map do |c|
212
+ specializer[c] || Leaf.new( self, c )
205
213
  end
206
214
  if leaves.length == 1
207
215
  leaves.first
@@ -209,38 +217,38 @@ module List
209
217
  Sequence.new self, *leaves
210
218
  end
211
219
  elsif list.all?{ |w| w.length == 1 }
212
- chars = list.select{ |w| !symbols[w] }
220
+ chars = list.select{ |w| !specializer[w] }
213
221
  if chars.size > 1
214
222
  list -= chars
215
223
  c = CharClass.new self, chars
216
224
  end
217
- a = Alternate.new self, symbols, list unless list.empty?
225
+ a = Alternate.new self, specializer, list unless list.empty?
218
226
  a.children.unshift c if a && c
219
227
  a || c
220
228
  elsif c = best_prefix(list) # found a fixed-width prefix pattern
221
229
  if optional = c[1].include?('')
222
230
  c[1].reject!{ |w| w == '' }
223
231
  end
224
- c1 = tree c[0], symbols
225
- c2 = tree c[1], symbols
232
+ c1 = tree c[0], specializer
233
+ c2 = tree c[1], specializer
226
234
  c2 = c2.optionalize optional
227
235
  Sequence.new self, c1, c2
228
236
  elsif c = best_suffix(list) # found a fixed-width suffix pattern
229
237
  if optional = c[0].include?('')
230
238
  c[0].reject!{ |w| w == '' } # TODO make this faster with index
231
239
  end
232
- c1 = tree c[0], symbols
240
+ c1 = tree c[0], specializer
233
241
  c1 = c1.optionalize optional
234
- c2 = tree c[1], symbols
242
+ c2 = tree c[1], specializer
235
243
  Sequence.new self, c1, c2
236
244
  else
237
245
  grouped = list.group_by{ |w| w[0] }
238
- chars = grouped.select{ |_, w| w.size == 1 && w[0].size == 1 && !symbols[w[0]] }.map{ |v, _| v }
246
+ chars = grouped.select{ |_, w| w.size == 1 && w[0].size == 1 && !specializer[w[0]] }.map{ |v, _| v }
239
247
  if chars.size > 1
240
248
  list -= chars
241
249
  c = CharClass.new self, chars
242
250
  end
243
- a = Alternate.new self, symbols, list
251
+ a = Alternate.new self, specializer, list
244
252
  a.children.unshift c if c
245
253
  a
246
254
  end
@@ -258,7 +266,7 @@ module List
258
266
 
259
267
  def deep_dup(o)
260
268
  if o.is_a?(Hash)
261
- Hash[o.map{ |k, v| [ deep_dup(k), deep_dup(v) ] }]
269
+ o.to_h { |k, v| [deep_dup(k), deep_dup(v)] }
262
270
  elsif o.is_a?(Array)
263
271
  o.map{ |v| deep_dup v }
264
272
  elsif o.nil? || o.is_a?(Symbol) || o.is_a?(TrueClass) || o.is_a?(FalseClass)
@@ -268,67 +276,60 @@ module List
268
276
  end
269
277
  end
270
278
 
279
+ # Finds a fixed-width prefix shared (as a cross product) by every word, if one
280
+ # yields a more compact pattern than the alternatives. Returns [prefixes, suffixes]
281
+ # or nil. Prefix/suffix groups are compared as sorted arrays; single-element groups
282
+ # skip the sort since they are already canonical.
271
283
  def best_prefix(list)
272
284
  acceptable = nil
273
285
  sizes = list.map(&:size)
274
- min = sizes.reduce 0, :+
286
+ min = sizes.sum
275
287
  sizes.uniq!
276
288
  lim = sizes.count == 1 ? list[0].size - 1 : sizes.min
277
289
  (1..lim).each do |l|
278
290
  c = {}
279
291
  list.each do |w|
280
- pfx = w[0...l]
281
- sfx = w[l..-1]
282
- ( c[pfx] ||= [] ) << sfx
283
- end
284
- c = cross_products c
285
- if c.size == 1
286
- count = count(c)
287
- if count < min
288
- min = count
289
- acceptable = c[0]
290
- end
292
+ ( c[w[0...l]] ||= [] ) << w[l..]
293
+ end
294
+ groups = c.group_by { |_, v| v.size == 1 ? v : v.sort }
295
+ next unless groups.size == 1
296
+ suffixes = groups.keys.first
297
+ prefixes = groups.values.first.map { |a| a[0] }.sort
298
+ cnt = prefixes.sum(&:size) + suffixes.sum(&:size)
299
+ if cnt < min
300
+ min = cnt
301
+ acceptable = [prefixes, suffixes]
291
302
  end
292
303
  end
293
304
  acceptable
294
305
  end
295
306
 
307
+ # Like best_prefix, but for suffixes. Returns [prefixes, suffixes] or nil.
296
308
  def best_suffix(list)
297
309
  acceptable = nil
298
310
  sizes = list.map(&:size)
299
- min = sizes.reduce 0, :+
311
+ min = sizes.sum
300
312
  sizes.uniq!
301
313
  lim = sizes.count == 1 ? list[0].size - 1 : sizes.min
302
314
  (1..lim).each do |l|
303
315
  c = {}
304
316
  list.each do |w|
305
- i = w.length - l
306
- pfx = w[0...i]
307
- sfx = w[i..-1]
308
- ( c[sfx] ||= [] ) << pfx
309
- end
310
- c = cross_products c
311
- if c.size == 1
312
- count = count(c)
313
- if count < min
314
- min = count
315
- acceptable = c[0].reverse
316
- end
317
+ i = w.length - l
318
+ ( c[w[i..]] ||= [] ) << w[0...i]
319
+ end
320
+ groups = c.group_by { |_, v| v.size == 1 ? v : v.sort }
321
+ next unless groups.size == 1
322
+ prefixes = groups.keys.first
323
+ suffixes = groups.values.first.map { |a| a[0] }.sort
324
+ cnt = prefixes.sum(&:size) + suffixes.sum(&:size)
325
+ if cnt < min
326
+ min = cnt
327
+ acceptable = [prefixes, suffixes]
317
328
  end
318
329
  end
319
330
  acceptable
320
331
  end
321
332
 
322
- # discover cross products -- e.g., {this, that} X {cat, dog}
323
- def cross_products(c)
324
- c.to_a.group_by{ |_, v| v.sort }.map{ |k,v| [ v.map{ |a| a[0] }.sort, k ] }
325
- end
326
-
327
- def count(c)
328
- c = c[0]
329
- c[0].map(&:size).reduce( 0, :+ ) + c[1].map(&:size).reduce( 0, :+ )
330
- end
331
-
332
333
  class Special
333
334
  attr_reader :engine, :special_map
334
335
  attr_accessor :specials, :list, :left, :right
@@ -338,7 +339,7 @@ module List
338
339
  @list = list
339
340
  max = 0
340
341
  list.each do |w|
341
- w.chars.each{ |c| i = c.ord; max = i if i > max }
342
+ w.each_char { |c| i = c.ord; max = i if i > max }
342
343
  end
343
344
  @specials = [].tap do |ar|
344
345
  specials.sort do |a, b|
@@ -385,7 +386,7 @@ module List
385
386
  @specials << @right
386
387
  end
387
388
  end
388
- @special_map = Hash[@specials.map{ |s| [ s.char, s ] }]
389
+ @special_map = @specials.to_h { |s| [s.char, s] }
389
390
  end
390
391
 
391
392
  # confirm that all special patterns are legitimate regexen
@@ -412,7 +413,7 @@ module List
412
413
  Regexp.new '(' + specials.map(&:var).map(&:to_s).join('|') + ')'
413
414
  end
414
415
  list = self.list.uniq.map do |w|
415
- parts = w.split(rx).select{ |p| p.length > 0 }
416
+ parts = w.split(rx).reject(&:empty?)
416
417
  e = parts.size - 1
417
418
  (0..e).map do |i|
418
419
  p = parts[i]
@@ -606,9 +607,10 @@ module List
606
607
  dup_count.reverse.each do |repeats, seq, start, finish|
607
608
  a = atomy? seq
608
609
  sl = seq.length
610
+ # only condense if this makes things shorter
609
611
  if ( a ? 0 : engine.wrap_size ) + 2 + repeats.to_s.length + sl < sl * repeats
610
612
  copy[start...finish] = ( a ? seq : wrap(seq) ) + "{#{repeats}}"
611
- return copy;
613
+ return copy
612
614
  end
613
615
  end
614
616
  end
@@ -617,9 +619,23 @@ module List
617
619
  elements
618
620
  end
619
621
 
620
- # infer atomic patterns
622
+ # infer atomic patterns -- things that can safely be repeated without wrapping
621
623
  def atomy?(s)
622
- s.size == 1 || /\A(?>\\\w|\[(?>[^\[\]\\]|\\.)++\])\z/ === s
624
+ s.size == 1 || %r/
625
+ \A
626
+ (?>
627
+ \\\w # one of the canned character class expressions
628
+ | # OR
629
+ \[ # an ad hoc character class expression
630
+ (?>
631
+ [^\[\]\\]
632
+ |
633
+ \\.
634
+ )++
635
+ \]
636
+ )
637
+ \z
638
+ /x === s
623
639
  end
624
640
 
625
641
  # iterated repeat condensation
@@ -712,6 +728,20 @@ module List
712
728
 
713
729
  def cc_quote(c)
714
730
  return Regexp.quote(c) if c =~ /\s/
731
+ code = c.ord
732
+ # Hex escape for control characters 1-8 for readability
733
+ if code >= 1 && code <= 8
734
+ return "\\x#{code.to_s(16).rjust(2, '0')}"
735
+ end
736
+ # Named escapes for other control characters
737
+ case code
738
+ when 9 then '\\t'
739
+ when 10 then '\\n'
740
+ when 11 then '\\v'
741
+ when 12 then '\\f'
742
+ when 13 then '\\r'
743
+ when 27 then '\\e'
744
+ end
715
745
  case c
716
746
  when '[' then '\['
717
747
  when ']' then '\]'
@@ -742,9 +772,9 @@ module List
742
772
 
743
773
  class Alternate < Node
744
774
 
745
- def initialize(engine, symbols, list)
775
+ def initialize(engine, specializer, list)
746
776
  super(engine, nil)
747
- @children = list.group_by{ |s| s[0] }.values.map{ |ar| engine.tree( ar, symbols ) }
777
+ @children = list.group_by{ |s| s[0] }.values.map{ |ar| engine.tree( ar, specializer ) }
748
778
  end
749
779
 
750
780
  def convert
data/list_matcher.gemspec CHANGED
@@ -9,20 +9,25 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["dfhoughton"]
10
10
  spec.email = ["dfhoughton@gmail.com"]
11
11
  spec.summary = %q{List::Matcher automates the generation of efficient regular expressions.}
12
- spec.description = <<-END
12
+ spec.description = <<~END
13
13
  List::Matcher automates the creation of regular expressions from lists, including lists of other regular
14
14
  expressions. The expressions it generates from lists of strings are non-backtracking and compact.
15
15
  END
16
16
  spec.homepage = "https://github.com/dfhoughton/list_matcher"
17
17
  spec.license = "MIT"
18
+ spec.metadata = {
19
+ "changelog_uri" => "https://github.com/dfhoughton/list_matcher/blob/master/CHANGELOG.md",
20
+ "source_code_uri" => "https://github.com/dfhoughton/list_matcher",
21
+ "bug_tracker_uri" => "https://github.com/dfhoughton/list_matcher/issues"
22
+ }
18
23
 
19
24
  spec.files = `git ls-files -z`.split("\x0")
20
25
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
26
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
27
  spec.require_paths = ["lib"]
23
- spec.required_ruby_version = '>= 2.0'
28
+ spec.required_ruby_version = '>= 3.0'
24
29
 
25
- spec.add_development_dependency "bundler", "~> 1.7"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "minitest", "~> 5"
30
+ spec.add_development_dependency "bundler", ">= 2.0"
31
+ spec.add_development_dependency "rake", ">= 13.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
28
33
  end
data/test/basic_test.rb CHANGED
@@ -321,4 +321,88 @@ class BasicTest < Minitest::Test
321
321
  def test_empty_list
322
322
  assert_equal '(?!)', List::Matcher.pattern([])
323
323
  end
324
+
325
+ # Unicode support tests (ported from list-matcher-js)
326
+ def test_emoji
327
+ emojis = ['😀', '😁', '😂']
328
+ rx = List::Matcher.rx emojis
329
+ emojis.each do |emoji|
330
+ assert rx === emoji, "can match emoji #{emoji}"
331
+ end
332
+ assert rx !~ '🤔', 'does not match other emoji'
333
+ end
334
+
335
+ def test_supplementary_plane_characters
336
+ # Deseret script characters (code points > 65535)
337
+ chars = ['𐐷', '𐐸', '𐐹']
338
+ rx = List::Matcher.rx chars
339
+ chars.each do |c|
340
+ assert rx === c, "can match supplementary plane char #{c}"
341
+ end
342
+ assert rx !~ '𐐺', 'does not match other supplementary plane char'
343
+ end
344
+
345
+ def test_mixed_ascii_and_emoji
346
+ words = ['cat', '😀', 'dog']
347
+ rx = List::Matcher.rx words
348
+ words.each do |w|
349
+ assert rx === w, "can match mixed word #{w}"
350
+ end
351
+ assert rx !~ 'bird', 'does not match other words'
352
+ end
353
+
354
+ def test_zero_width_characters
355
+ zwsp = "\u200b" # zero-width space
356
+ zwj = "\u200d" # zero-width joiner
357
+ zwnj = "\u200c" # zero-width non-joiner
358
+ rx = List::Matcher.rx [zwsp, zwj, zwnj]
359
+ assert rx === zwsp, 'matches zero-width space'
360
+ assert rx === zwj, 'matches zero-width joiner'
361
+ assert rx === zwnj, 'matches zero-width non-joiner'
362
+ end
363
+
364
+ def test_combined_unicode_nfc_vs_nfd
365
+ # é can be U+00E9 (single) or U+0065 + U+0301 (e + combining acute)
366
+ single = "\u00e9"
367
+ combined = "e\u0301"
368
+ rx = List::Matcher.rx [single, combined]
369
+ assert rx === single, 'matches NFC é'
370
+ assert rx === combined, 'matches NFD é'
371
+ end
372
+
373
+ def test_control_characters_1_to_8
374
+ # Control characters 1-8 should be escaped as hex
375
+ control_chars = (1..8).map { |i| i.chr(Encoding::UTF_8) }
376
+ rx = List::Matcher.rx control_chars
377
+ control_chars.each do |c|
378
+ assert rx === c, "can match control character #{c.ord}"
379
+ end
380
+ # Verify they're escaped as hex in the pattern
381
+ pattern = List::Matcher.pattern control_chars
382
+ assert pattern.include?('\\x01'), 'control char 1 should be hex escaped'
383
+ assert pattern.include?('\\x08'), 'control char 8 should be hex escaped'
384
+ end
385
+
386
+ def test_control_characters_9_to_13
387
+ # Control characters 9-13 should be properly escaped
388
+ control_chars = [9, 10, 11, 12, 13].map { |i| i.chr(Encoding::UTF_8) }
389
+ rx = List::Matcher.rx control_chars
390
+ control_chars.each do |c|
391
+ assert rx === c, "can match control character #{c.ord}"
392
+ end
393
+ # The pattern may be optimized as a character class range [\t-\r]
394
+ # or individual escapes, both are valid
395
+ pattern = List::Matcher.pattern control_chars
396
+ # At minimum, it should contain tab and carriage return in some form
397
+ assert pattern.include?('\\t') || pattern.include?('[\\t'), 'tab should be escaped'
398
+ assert pattern.include?('\\r') || pattern.include?('\\r'), 'carriage return should be escaped'
399
+ end
400
+
401
+ def test_all_control_characters
402
+ control_chars = (0..31).map { |i| i.chr(Encoding::UTF_8) }
403
+ rx = List::Matcher.rx control_chars
404
+ control_chars.each do |c|
405
+ assert rx === c, "can match all control characters"
406
+ end
407
+ end
324
408
  end
data/test/doc_test.rb CHANGED
@@ -16,8 +16,8 @@ class DocTest < Minitest::Test
16
16
  assert_equal '(?:[b-d]ad)', (m.pattern %w( cad bad dad ))
17
17
  assert_equal '(?:cat(?:alog)?)', (m.pattern %w( cat catalog ))
18
18
  assert_equal '(?:[4-9]|1\d?|2\d?|3[01]?)', (m.pattern (1..31).to_a)
19
- assert_equal "(?:cat|dog)", (List::Matcher.pattern %w( cat dog ))
20
- assert_equal /(?:cat|dog)/, (List::Matcher.rx %w( cat dog ))
19
+ assert_equal "(?:cat|dog)", (List::Matcher.pattern %w( cat dog ))
20
+ assert_equal %r/(?:cat|dog)/, (List::Matcher.rx %w( cat dog ))
21
21
  m = List::Matcher.new normalize_whitespace: true, bound: true, case_insensitive: true, multiline: true, atomic: false, symbols: { num: '\d++' }
22
22
  m2 = m.bud case_insensitive: false
23
23
  assert !m2.case_insensitive
metadata CHANGED
@@ -1,60 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: list_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.8
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dfhoughton
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2017-12-09 00:00:00.000000000 Z
10
+ date: 2026-11-28 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '1.7'
18
+ version: '2.0'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - "~>"
23
+ - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '1.7'
25
+ version: '2.0'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rake
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - "~>"
30
+ - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: '10.0'
32
+ version: '13.0'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
- - - "~>"
37
+ - - ">="
39
38
  - !ruby/object:Gem::Version
40
- version: '10.0'
39
+ version: '13.0'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: minitest
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: '5'
46
+ version: '5.0'
48
47
  type: :development
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: '5'
55
- description: |2
56
- List::Matcher automates the creation of regular expressions from lists, including lists of other regular
57
- expressions. The expressions it generates from lists of strings are non-backtracking and compact.
53
+ version: '5.0'
54
+ description: |
55
+ List::Matcher automates the creation of regular expressions from lists, including lists of other regular
56
+ expressions. The expressions it generates from lists of strings are non-backtracking and compact.
58
57
  email:
59
58
  - dfhoughton@gmail.com
60
59
  executables: []
@@ -62,6 +61,7 @@ extensions: []
62
61
  extra_rdoc_files: []
63
62
  files:
64
63
  - ".gitignore"
64
+ - CHANGELOG.md
65
65
  - Gemfile
66
66
  - LICENSE.txt
67
67
  - README.md
@@ -78,8 +78,10 @@ files:
78
78
  homepage: https://github.com/dfhoughton/list_matcher
79
79
  licenses:
80
80
  - MIT
81
- metadata: {}
82
- post_install_message:
81
+ metadata:
82
+ changelog_uri: https://github.com/dfhoughton/list_matcher/blob/master/CHANGELOG.md
83
+ source_code_uri: https://github.com/dfhoughton/list_matcher
84
+ bug_tracker_uri: https://github.com/dfhoughton/list_matcher/issues
83
85
  rdoc_options: []
84
86
  require_paths:
85
87
  - lib
@@ -87,16 +89,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
89
  requirements:
88
90
  - - ">="
89
91
  - !ruby/object:Gem::Version
90
- version: '2.0'
92
+ version: '3.0'
91
93
  required_rubygems_version: !ruby/object:Gem::Requirement
92
94
  requirements:
93
95
  - - ">="
94
96
  - !ruby/object:Gem::Version
95
97
  version: '0'
96
98
  requirements: []
97
- rubyforge_project:
98
- rubygems_version: 2.4.8
99
- signing_key:
99
+ rubygems_version: 3.6.2
100
100
  specification_version: 4
101
101
  summary: List::Matcher automates the generation of efficient regular expressions.
102
102
  test_files: