match_skeleton 1.0.3 → 1.1.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 +5 -5
- data/.gitignore +44 -0
- data/ChangeLog +11 -0
- data/Makefile +23 -0
- data/README.ja.rdoc +19 -25
- data/lib/match_skeleton.rb +71 -28
- data/lib/match_skeleton/match_data.rb +1 -1
- data/test/test_match_skeleton.rb +37 -8
- metadata +9 -9
- data/News +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a53b8a88e9ca41def7dbc242ecde1d2fe43a1764a7a7058f33bb50d59cc2d609
|
4
|
+
data.tar.gz: 40c07f515ffd7a62c57e314770ee91986e48a83913d9e8ecac1554cdd481c106
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4261a17c5977db97b8ee59bf6525c11d88c077cfc4e347e997446c36d60370601629505fe354583d859c0bc3285f55f609b132b6eb5b5550a8da1a9fd9a2ec24
|
7
|
+
data.tar.gz: d2f551aeb967751182bc57781dac18e0172af90f5098442200f211fcc7aa156ed5e8ed5cd99dfd68ee16e35107f01532d312cbf9f7be5d02ff22a54d6cf783be
|
data/.gitignore
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
/vendor/bundle
|
10
|
+
|
11
|
+
# Ignore all logfiles and tempfiles.
|
12
|
+
/log/*
|
13
|
+
/tmp/*
|
14
|
+
!/log/.keep
|
15
|
+
!/tmp/.keep
|
16
|
+
|
17
|
+
.rbenv-version
|
18
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
19
|
+
.rvmrc
|
20
|
+
|
21
|
+
/node_modules
|
22
|
+
/yarn-error.log
|
23
|
+
|
24
|
+
.byebug_history
|
25
|
+
|
1
26
|
*.[oa]
|
2
27
|
*.so
|
3
28
|
*~
|
@@ -8,3 +33,22 @@
|
|
8
33
|
*.backup
|
9
34
|
*.org
|
10
35
|
*.orig
|
36
|
+
*.elc
|
37
|
+
*.pyc
|
38
|
+
\#*\#
|
39
|
+
|
40
|
+
# Elastic Beanstalk Files
|
41
|
+
.elasticbeanstalk/*
|
42
|
+
!.elasticbeanstalk/*.cfg.yml
|
43
|
+
!.elasticbeanstalk/*.global.yml
|
44
|
+
|
45
|
+
# macOS
|
46
|
+
.DS_Store
|
47
|
+
|
48
|
+
# yard
|
49
|
+
*.yardoc
|
50
|
+
|
51
|
+
# Ruby Gem doc
|
52
|
+
*.gem
|
53
|
+
doc/*
|
54
|
+
|
data/ChangeLog
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
-----
|
2
|
+
(Version: 1.1.0)
|
3
|
+
2019-10-29 Masa Sakano
|
4
|
+
* Mainly bug-fix but some significant update.
|
5
|
+
* Fixed RangeError newly raised in Ruby 2.6 (https://rubyreferences.github.io/rubychanges/2.6.html#endless-range-1) in some cases.
|
6
|
+
* Updated .gitignore and deleted doc from the git repository.
|
7
|
+
* Makefile and .github/README.md added. News deleted.
|
8
|
+
* `==` compares post_match as well now.
|
9
|
+
* `.eql?` is not overwritten now and is left as default.
|
10
|
+
* Updating tests accordingly.
|
11
|
+
|
1
12
|
-----
|
2
13
|
(Version: 1.0.3)
|
3
14
|
2016-05-27 Masa Sakano
|
data/Makefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
ALL =
|
2
|
+
|
3
|
+
objs =
|
4
|
+
|
5
|
+
.SUFFIXES: .so .o .c .f
|
6
|
+
|
7
|
+
#.o.so:
|
8
|
+
# ${LD} ${LFLAGS} -o $@ $< ${LINK_LIB}
|
9
|
+
|
10
|
+
all: ${ALL}
|
11
|
+
|
12
|
+
|
13
|
+
.PHONY: clean test doc
|
14
|
+
clean:
|
15
|
+
$(RM) bin/*~
|
16
|
+
|
17
|
+
## You may need RUBYLIB=`pwd`/lib:$RUBYLIB
|
18
|
+
test:
|
19
|
+
rake test
|
20
|
+
|
21
|
+
doc:
|
22
|
+
yard doc; [[ -x ".github" && ( "README.ja.rdoc" -nt ".github/README.md" ) ]] && ( ruby -r rdoc -e 'puts RDoc::Markup::ToMarkdown.new.convert ARGF.read' < README.ja.rdoc > .github/README.md ; echo ".github/README.md is updated." ) || exit 0
|
23
|
+
|
data/README.ja.rdoc
CHANGED
@@ -2,37 +2,34 @@
|
|
2
2
|
= MatchSkeleton - Equivalent to MatchData with less memory use
|
3
3
|
|
4
4
|
This package provides the class {MatchSkeleton}.
|
5
|
-
It behaves almost exactly like
|
5
|
+
It behaves almost exactly like +MatchData+, except it uses a greatly
|
6
6
|
less and practically negligible internal memory.
|
7
7
|
|
8
|
-
The built-in
|
9
|
-
|
8
|
+
The built-in +MatchData+ class holds a copy of the original
|
9
|
+
+String+, from which the matched data are derived, in a "freeze"
|
10
10
|
state. It is useful because no one can by chance destructively modify
|
11
11
|
the original string. However, if is memory-savvy. Even if
|
12
|
-
|
12
|
+
+MatchData+ is the match of the first few characters of a 1-GB string,
|
13
13
|
it internally holds the entire 1-GB of the original string. If a code
|
14
14
|
running holds 1000 of them, it needs a memory use of 1TB(!).
|
15
15
|
|
16
16
|
This class holds the same information of the matched data as
|
17
|
-
|
17
|
+
+MatchData+ but as positional indices, and the original String object only.
|
18
18
|
Therefore, as long as the original String is not destructively
|
19
19
|
modified by an external process, any method of this class returns the
|
20
|
-
equal result as
|
20
|
+
equal result as +MatchData+. Note that while the instance of this
|
21
21
|
class is kept, the original string is not garbage-collected by the
|
22
22
|
Ruby interpreter.
|
23
23
|
|
24
24
|
One additional function this class offers is the instance variable and
|
25
25
|
method <tt>pos_begin</tt>. It can be set by a user and hold the
|
26
|
-
information (
|
26
|
+
information (+Integer+) at which position the +Regexp+ match has started to
|
27
27
|
generate the matched data.
|
28
28
|
|
29
|
-
Note this library, when required, also modifies the operator
|
29
|
+
Note this library, when required, also modifies the operator +MatchData#==+
|
30
30
|
so that it can be compared with {MatchSkeleton} objects.
|
31
31
|
Now the operator is simply based on duck-typing of
|
32
|
-
|
33
|
-
{MatchData#eql?} is not affected, and therefore any comparison between
|
34
|
-
{MatchData} and {MatchSkeleton} objects with {MatchData#eql?} or
|
35
|
-
{MatchSkeleton#eql?} returns false.
|
32
|
+
+#string+, +regexp+, and +pre_match+.
|
36
33
|
|
37
34
|
== Install
|
38
35
|
|
@@ -40,6 +37,7 @@ The standard procedure to install a gem should work:
|
|
40
37
|
gem install match_skeleton
|
41
38
|
Or, get it from
|
42
39
|
{https://rubygems.org/gems/match_skeleton}
|
40
|
+
or {https://github.com/masasakano/match_skeleton}
|
43
41
|
|
44
42
|
Then just require as
|
45
43
|
require 'match_skeleton'
|
@@ -95,38 +93,34 @@ Versions:: The versions of this package follow Semantic Versioning (2.0.0) http:
|
|
95
93
|
|
96
94
|
= MatchSkeleton - MatchDataに等価でメモリを節約するクラス
|
97
95
|
|
98
|
-
クラス
|
99
|
-
|
96
|
+
クラス +MatchSkeleton+ のGemです。
|
97
|
+
+MatchData+とほぼ完全に等価な動作をします。ただし、メモリ使用量は
|
100
98
|
比較してはるかに少なくなり、ほぼ無視できます。
|
101
99
|
|
102
|
-
|
100
|
+
組込+MatchData+クラスは、正規表現マッチした元の文字列(String)のコピーを
|
103
101
|
"freeze"した状態で保持します。おかげで、外部のプロセスが元文字列を
|
104
|
-
|
102
|
+
破壊的に変更して+MatchData+のオブジェクトも影響を受ける、ということは
|
105
103
|
ありません。しかし、それはメモリ使用量が巨大になり得ます。たとえば、
|
106
104
|
{MatchData}オブジェクトが1GBの文字列の最初の数文字だけのマッチだったと
|
107
105
|
しても、同オブジェクトは、その1GBの文字列を内部的に保持します。
|
108
106
|
もし動作中のコードがそんなオブジェクトを1000個保持していたら、
|
109
107
|
それだけで 1TB(!)のメモリを消費することになります。
|
110
108
|
|
111
|
-
|
109
|
+
このクラスは、+MatchData+と同じ情報を保持しますが、それは内部的に、
|
112
110
|
インデックスと(コピーではない)原文字列そのものだけです。したがって、
|
113
111
|
原文字列が外部のプロセスで破壊的に変更されない限り、このクラスの
|
114
|
-
|
112
|
+
メソッドの返り値は、+MatchData+と同じです。念のため、このクラスの
|
115
113
|
インスタンスが生きている限り、原文字列がガーベージ・コレクトされる
|
116
114
|
ことはありません。
|
117
115
|
|
118
116
|
一点、このクラス独自のパラメーターとして、インスタンス変数かつ
|
119
117
|
メソッドの<tt>pos_begin</tt>が導入されています。正規表現マッチの
|
120
|
-
開始ポジション(
|
118
|
+
開始ポジション(+Integer+)を(ユーザーが設定することで)保持します。
|
121
119
|
|
122
|
-
なお、このライブラリを require した時、演算子
|
120
|
+
なお、このライブラリを require した時、演算子 +MatchData#==+
|
123
121
|
が変更され、{MatchSkeleton} と比較できるようになります。
|
124
122
|
結果、同演算子は、ダック・タイピングとして、
|
125
|
-
|
126
|
-
一方、{MatchData#eql?} は影響を受けません。すなわち、
|
127
|
-
{MatchData#eql?} あるいは {MatchSkeleton#eql?}によって、
|
128
|
-
{MatchData} と {MatchSkeleton} オブジェクトを比較すると常に
|
129
|
-
偽(false)を返します。
|
123
|
+
+#string+, +regexp+, および +#pre_match+に依存するようになります。
|
130
124
|
|
131
125
|
|
132
126
|
== インストール
|
data/lib/match_skeleton.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
|
3
|
+
begin
|
4
|
+
require 'match_skeleton/match_data'
|
5
|
+
rescue LoadError
|
6
|
+
if !MatchData.method_defined? :equal_before_match_skeleton
|
7
|
+
# Probably this file is read with its absolute path explicitly specified.
|
8
|
+
msg = 'WARNING(LoadError): "match_skeleton/match_data" - the library path to %s is not correctly set and hence failed to read some methods.'%(File.basename __FILE__)
|
9
|
+
warn msg
|
10
|
+
end
|
11
|
+
end
|
4
12
|
|
5
13
|
# =Class MatchSkeleton
|
6
14
|
#
|
@@ -24,9 +32,25 @@ class MatchSkeleton
|
|
24
32
|
attr_accessor :pos_begin
|
25
33
|
|
26
34
|
|
35
|
+
# Constructor
|
36
|
+
#
|
37
|
+
# If the second argument is omitted, it is taken from the first argument
|
38
|
+
# with +MatchData#string+. However, it would spoil the whole point of
|
39
|
+
# using this class, given +MatchData#string+ always "dups" the original
|
40
|
+
# string and uses up extra memory space! If you do not specify the second
|
41
|
+
# argument, this class offers almost identical functions but works slower,
|
42
|
+
# save from the bonus information of pos_begin, which can be added in this
|
43
|
+
# initialization in this class.
|
44
|
+
#
|
45
|
+
# The point of using this class is to save the memory when you make multiple
|
46
|
+
# applications with many Regexp to the identical instance of String (with
|
47
|
+
# the same object_id) *and* if you want to keep the results of the Regexp
|
48
|
+
# match as MatchData or equivalent. So, do not forget to specify the second
|
49
|
+
# argument in this initialization!
|
50
|
+
#
|
27
51
|
# @param md [MatchData]
|
28
|
-
# @param string [String] If not specified, it is taken from the first argument
|
29
|
-
# @param pos_begin: [Integer] The position {Regexp} match has started.
|
52
|
+
# @param string [String] If not specified, it is taken from the first argument.
|
53
|
+
# @param pos_begin: [Integer] The position where {Regexp} match has started.
|
30
54
|
def initialize(md, string=nil, pos_begin: nil)
|
31
55
|
size_str = md.string.size
|
32
56
|
if string && string.size != size_str
|
@@ -37,7 +61,7 @@ class MatchSkeleton
|
|
37
61
|
@pre_match = (0...md.pre_match.size) # {Range}
|
38
62
|
@post_match = ((size_str-md.post_match.size)...size_str) # {Range}
|
39
63
|
|
40
|
-
# @offsets is Hash with the keys of both Integer and possibly Symbol
|
64
|
+
# @offsets is Hash of Range-s with the keys of both Integer and possibly Symbol
|
41
65
|
# if names exist.
|
42
66
|
names = md.names
|
43
67
|
ar_off = (0..(md.size-1)).map do |n|
|
@@ -50,7 +74,6 @@ class MatchSkeleton
|
|
50
74
|
ej = ei - 1
|
51
75
|
@offsets[names[ej]] = ev if (ej >= 0 && names[ej])
|
52
76
|
end
|
53
|
-
|
54
77
|
|
55
78
|
@pos_begin = pos_begin
|
56
79
|
end
|
@@ -59,13 +82,14 @@ class MatchSkeleton
|
|
59
82
|
#
|
60
83
|
# A difference in {#pos_begin} is not taken into account.
|
61
84
|
#
|
62
|
-
# @param [Object] The methods of {#string}, {#regexp}, {#pre_match} have to be defined and return the same to be true. Practically, only {MatchSkeleton} and {MatchData} may return true.
|
85
|
+
# @param obj [Object] The methods of {#string}, {#regexp}, {#pre_match} have to be defined and return the same to be true. Practically, only {MatchSkeleton} and {MatchData} may return true.
|
63
86
|
# @return [Boolean]
|
64
87
|
# @see #eql?
|
65
88
|
def ==(obj)
|
66
|
-
!!((defined?(obj.string)
|
67
|
-
(defined?(obj.regexp)
|
68
|
-
(defined?(obj.pre_match)
|
89
|
+
!!((defined?(obj.string) && string == obj.string) &&
|
90
|
+
(defined?(obj.regexp) && regexp == obj.regexp) &&
|
91
|
+
(defined?(obj.pre_match) && pre_match == obj.pre_match) &&
|
92
|
+
(defined?(obj.post_match) && post_match == obj.post_match))
|
69
93
|
# nb., defined?() can return nil, and then nil (not false) will be returned.
|
70
94
|
end
|
71
95
|
|
@@ -110,22 +134,22 @@ class MatchSkeleton
|
|
110
134
|
offset(n)[1]
|
111
135
|
end
|
112
136
|
|
113
|
-
# The same as {#==} but stricter comparison.
|
114
|
-
#
|
115
|
-
# The comparison between {MatchSkeleton} and {MatchData} returns false and
|
116
|
-
# that between {MatchSkeleton} with different {#pos_begin} or
|
117
|
-
# those with strings of different Object-IDs also return false.
|
118
|
-
#
|
119
|
-
# @param [Object]
|
120
|
-
# @return [Boolean]
|
121
|
-
# @see #==
|
122
|
-
def eql?(obj)
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
137
|
+
# # The same as {#==} but stricter comparison.
|
138
|
+
# #
|
139
|
+
# # The comparison between {MatchSkeleton} and {MatchData} returns false and
|
140
|
+
# # that between {MatchSkeleton} with different {#pos_begin} or
|
141
|
+
# # those with strings of different Object-IDs also return false.
|
142
|
+
# #
|
143
|
+
# # @param obj [Object]
|
144
|
+
# # @return [Boolean]
|
145
|
+
# # @see #==
|
146
|
+
# def eql?(obj)
|
147
|
+
# return false if self != obj
|
148
|
+
# return false if !defined?(obj.pos_begin)
|
149
|
+
# return false if (string.object_id != obj.string.object_id)
|
150
|
+
# return false if pos_begin != obj.pos_begin
|
151
|
+
# return true
|
152
|
+
# end
|
129
153
|
|
130
154
|
# Similar to {MatchData#inspect}
|
131
155
|
#
|
@@ -148,6 +172,11 @@ class MatchSkeleton
|
|
148
172
|
|
149
173
|
# The same as {MatchData#offset}
|
150
174
|
#
|
175
|
+
# Due to the change in Ruby 2.6
|
176
|
+
# https://rubyreferences.github.io/rubychanges/2.6.html#endless-range-1
|
177
|
+
# the old routines would raise an Excetion when the end range is nil,
|
178
|
+
# that is, there is no match for MatchData#[n], hence needed updating.
|
179
|
+
#
|
151
180
|
# @param n [Integer]
|
152
181
|
# @return [Array<integer>]
|
153
182
|
def offset(n)
|
@@ -155,8 +184,18 @@ class MatchSkeleton
|
|
155
184
|
n = n.to_s
|
156
185
|
raise IndexError, sprintf("undefined group name reference: %s", n) if !names.include?(n)
|
157
186
|
end
|
158
|
-
|
159
|
-
|
187
|
+
|
188
|
+
## This used to work before Ruby 2.6
|
189
|
+
# [@offsets[n].first,
|
190
|
+
# @offsets[n].last]
|
191
|
+
|
192
|
+
[:first, :last].map do |ec|
|
193
|
+
begin
|
194
|
+
@offsets[n].public_send ec
|
195
|
+
rescue RangeError
|
196
|
+
nil
|
197
|
+
end
|
198
|
+
end
|
160
199
|
end
|
161
200
|
|
162
201
|
# The same as {MatchData#pre_match}
|
@@ -212,8 +251,12 @@ class MatchSkeleton
|
|
212
251
|
|
213
252
|
private
|
214
253
|
|
254
|
+
# @note Due to the change in Ruby 2.6, k.last may raise RangeError.
|
255
|
+
# In this instance, k.first must be always nil when k.last is nil.
|
256
|
+
# So, k.last would not be evaluated when k.last is nil.
|
257
|
+
# But it is playing safe (by adding "rescue").
|
215
258
|
def offset2string(i)
|
216
259
|
k = @offsets[i]
|
217
|
-
(k.first && k.last) ? string[k] : nil
|
260
|
+
(k.first && (k.last rescue nil)) ? string[k] : nil
|
218
261
|
end
|
219
262
|
end # class MatchSkeleton
|
@@ -11,7 +11,7 @@ class MatchData
|
|
11
11
|
|
12
12
|
# Compares with {MatchSkeleton}, in addition to {MatchData}
|
13
13
|
#
|
14
|
-
# @param [#string, #regexp, #pre_match] All the methods have to be there. Practically, {MatchSkeleton} and {MatchData}
|
14
|
+
# @param obj [#string, #regexp, #pre_match] All the methods have to be there. Practically, {MatchSkeleton} and {MatchData}
|
15
15
|
# @return [Boolean]
|
16
16
|
def ==(obj)
|
17
17
|
!!((defined?(obj.string) && string == obj.string) &&
|
data/test/test_match_skeleton.rb
CHANGED
@@ -143,12 +143,25 @@ class TestMatchSkeleton < Minitest::Test
|
|
143
143
|
# pos_begin does not count.
|
144
144
|
ms1p = ms1.dup
|
145
145
|
assert_equal ms1.string.object_id, ms1p.string.object_id
|
146
|
+
assert_equal ms1.regexp.object_id, ms1p.regexp.object_id
|
147
|
+
assert_equal ms1.instance_variable_get(:@pre_match), ms1p.instance_variable_get(:@pre_match)
|
148
|
+
assert_equal ms1.instance_variable_get(:@offsets), ms1p.instance_variable_get(:@offsets)
|
149
|
+
assert_equal ms1.instance_variable_get(:@pos_begin), ms1p.instance_variable_get(:@pos_begin)
|
146
150
|
assert_equal true, (ms1 == ms1p)
|
147
|
-
assert_equal true, (ms1.eql?(ms1p))
|
151
|
+
# assert_equal true, (ms1.eql?(ms1p)) # Not quite sure why.
|
148
152
|
ms1p.pos_begin = 6
|
149
153
|
assert_equal true, (ms1 == ms1p)
|
150
154
|
assert_equal false, (ms1.eql?(ms1p))
|
151
155
|
|
156
|
+
# clone
|
157
|
+
ms1q = ms1.clone
|
158
|
+
assert_equal ms1.string.object_id, ms1q.string.object_id
|
159
|
+
assert_equal true, (ms1 == ms1q)
|
160
|
+
# assert_equal true, (ms1.eql?(ms1q)) # Not quite sure why.
|
161
|
+
ms1q.pos_begin = 6
|
162
|
+
assert_equal true, (ms1 == ms1q)
|
163
|
+
assert_equal false, (ms1.eql?(ms1q))
|
164
|
+
|
152
165
|
# Different Object-ID
|
153
166
|
s2 = s.dup
|
154
167
|
md2 = s2.match(re1, pos)
|
@@ -158,7 +171,7 @@ class TestMatchSkeleton < Minitest::Test
|
|
158
171
|
assert_equal true, (md2 == ms1)
|
159
172
|
assert_equal true, (ms21== md2)
|
160
173
|
assert_equal true, (md2 == ms21)
|
161
|
-
assert_equal true, (ms21.eql?(ms1))
|
174
|
+
# assert_equal true, (ms21.eql?(ms1))
|
162
175
|
|
163
176
|
ms2 = MatchSkeleton.new(md2, s2, pos_begin: pos) # Equal MatchData, but non-identical string s (with the different Object-IDs)
|
164
177
|
assert_equal true, (ms1 == ms2)
|
@@ -241,8 +254,10 @@ class TestMatchSkeleton < Minitest::Test
|
|
241
254
|
md1 = re.match(s)
|
242
255
|
ms1 = MatchSkeleton.new(md1, s)
|
243
256
|
assert_equal md1['foo'], ms1['foo']
|
244
|
-
|
245
|
-
|
257
|
+
assert_nil md1['baa']
|
258
|
+
assert_nil ms1['baa']
|
259
|
+
assert_nil md1[:baa]
|
260
|
+
assert_nil ms1[:baa]
|
246
261
|
end
|
247
262
|
|
248
263
|
def test_begin_end_int01
|
@@ -280,10 +295,21 @@ class TestMatchSkeleton < Minitest::Test
|
|
280
295
|
re = /(ef)(g)?(hi)/
|
281
296
|
md1 = re.match(s)
|
282
297
|
ms1 = MatchSkeleton.new(md1, s)
|
283
|
-
assert_equal md1.begin(2), ms1.begin(2)
|
284
|
-
|
285
|
-
|
286
|
-
|
298
|
+
#assert_equal md1.begin(2), ms1.begin(2) # DEPRECATED: Use assert_nil
|
299
|
+
assert_nil md1.begin(2)
|
300
|
+
assert_nil ms1.begin(2)
|
301
|
+
assert_nil md1.end(2)
|
302
|
+
assert_nil ms1.end(2)
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_begin_end_nil_to_a01
|
306
|
+
s = "efhi2"
|
307
|
+
re = /(ef)(g)?(hi)/
|
308
|
+
md1 = re.match(s)
|
309
|
+
ms1 = MatchSkeleton.new(md1, s)
|
310
|
+
ad1 = md1.to_a
|
311
|
+
as1 = ms1.to_a
|
312
|
+
assert_equal ad1, as1
|
287
313
|
end
|
288
314
|
|
289
315
|
def test_captures01
|
@@ -327,6 +353,9 @@ class TestMatchSkeleton < Minitest::Test
|
|
327
353
|
ms1 = MatchSkeleton.new(md1, s)
|
328
354
|
assert_equal md1.names, ms1.names
|
329
355
|
assert_equal ["x", "y"], ms1.names
|
356
|
+
assert_equal md1[:x], ms1[:x]
|
357
|
+
assert_nil md1[:y]
|
358
|
+
assert_nil ms1[:y]
|
330
359
|
end
|
331
360
|
|
332
361
|
def test_offset_int01
|
metadata
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: match_skeleton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masa Sakano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: MatchSkeleton is a class equivalent to MatchData with negligible memory
|
14
|
-
use
|
15
|
-
|
14
|
+
use when the identical strings are matched repeatedly while matched data are kept
|
15
|
+
in the memory. As long as the original string is not destructively modified, it
|
16
|
+
behaves almost icentical to MatchData.
|
16
17
|
email: info@wisebabel.com
|
17
18
|
executables: []
|
18
19
|
extensions: []
|
@@ -21,7 +22,7 @@ extra_rdoc_files:
|
|
21
22
|
files:
|
22
23
|
- ".gitignore"
|
23
24
|
- ChangeLog
|
24
|
-
-
|
25
|
+
- Makefile
|
25
26
|
- README.ja.rdoc
|
26
27
|
- Rakefile
|
27
28
|
- lib/match_skeleton.rb
|
@@ -30,7 +31,8 @@ files:
|
|
30
31
|
homepage: https://www.wisebabel.com/
|
31
32
|
licenses:
|
32
33
|
- MIT
|
33
|
-
metadata:
|
34
|
+
metadata:
|
35
|
+
yard.run: yri
|
34
36
|
post_install_message:
|
35
37
|
rdoc_options:
|
36
38
|
- "--charset=UTF-8"
|
@@ -47,11 +49,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
49
|
- !ruby/object:Gem::Version
|
48
50
|
version: '0'
|
49
51
|
requirements: []
|
50
|
-
|
51
|
-
rubygems_version: 2.5.1
|
52
|
+
rubygems_version: 3.0.3
|
52
53
|
signing_key:
|
53
54
|
specification_version: 4
|
54
55
|
summary: MatchSkeleton - class equivalent to MatchData with negligible memory use
|
55
56
|
test_files:
|
56
57
|
- test/test_match_skeleton.rb
|
57
|
-
has_rdoc:
|