regextest 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +7 -0
- data/lib/pre-generate-spec.rb +129 -0
- data/lib/regextest/back/element.rb +12 -9
- data/lib/regextest/back/main.rb +4 -3
- data/lib/regextest/back/result.rb +3 -3
- data/lib/regextest/version.rb +1 -1
- data/regextest.gemspec +5 -1
- metadata +36 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b51a91bb714731ac6c008e71cc768024e7125ae0
|
4
|
+
data.tar.gz: e6f0cf1de571dc253c9097313c067763e4b09b14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e2cafea68bc1bde41e965fd3348c4bc8e4ad4160f96acb506081faa5b0db0d440461a879e5b6400bfa0dc8e04f4df3bc1276df26b7dc00e257c5bed72e5ef6e
|
7
|
+
data.tar.gz: 8848c862ab67d58fc053798d71139c84e84c5be3ccb6fb8651bb22dc9cb51ce70c728a613e6168773fc523b9d240913b53706e4914068496a54a3a6cf84374bf
|
data/Rakefile
CHANGED
@@ -31,6 +31,12 @@ file 'lib/regextest/front/case-folding.rb' => 'lib/pre-case-folding.rb' do
|
|
31
31
|
sh 'ruby lib/pre-case-folding.rb'
|
32
32
|
end
|
33
33
|
|
34
|
+
# Generating regression test suite
|
35
|
+
file 'spec/regression_spec.rb' => 'lib/pre-generate-spec.rb' do
|
36
|
+
puts "making spec/regression_spec.rb"
|
37
|
+
sh 'ruby lib/pre-generate-spec.rb'
|
38
|
+
end
|
39
|
+
|
34
40
|
# Generating documents
|
35
41
|
file 'doc/index.html' => ['lib/regextest.rb', 'lib/regextest/regexp.rb', 'README.md'] do
|
36
42
|
puts "making document for Regextest"
|
@@ -42,6 +48,7 @@ task :make =>
|
|
42
48
|
'lib/regextest/front/bracket-parser.rb',
|
43
49
|
'lib/regextest/front/unicode.rb',
|
44
50
|
'lib/regextest/front/case-folding.rb',
|
51
|
+
'spec/regression_spec.rb',
|
45
52
|
'doc/index.html',
|
46
53
|
] do
|
47
54
|
puts "Rake it!"
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Copyright (C) 2016 Mikio Ikoma
|
4
|
+
|
5
|
+
require 'regextest'
|
6
|
+
require 'kconv'
|
7
|
+
require 'timeout'
|
8
|
+
require 'pp'
|
9
|
+
|
10
|
+
class Regextest::Test
|
11
|
+
def initialize
|
12
|
+
time_out = 1
|
13
|
+
results = do_test(time_out)
|
14
|
+
@spec_file = "spec/regression_spec.rb"
|
15
|
+
puts_spec(@spec_file, results)
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def do_test(timeout_seconds)
|
20
|
+
results = []
|
21
|
+
get_lines(timeout_seconds).each_with_index do | line, i |
|
22
|
+
begin
|
23
|
+
warn line
|
24
|
+
eval(line)
|
25
|
+
rescue SyntaxError => ex
|
26
|
+
warn "EVAL ERROR: #{ex}, #{line}"
|
27
|
+
#results.push({
|
28
|
+
# explain: "raises #{ex}, when eval (#{line})",
|
29
|
+
# expect: "eval('#{line}')",
|
30
|
+
# raises: "#{ex.class}"
|
31
|
+
#})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
results
|
35
|
+
end
|
36
|
+
|
37
|
+
def puts_spec(spec_file, results)
|
38
|
+
File.open(spec_file, "w") do |fp|
|
39
|
+
fp.puts "require 'spec_helper'"
|
40
|
+
fp.puts "describe Regextest do"
|
41
|
+
results.each do | result |
|
42
|
+
explain = result[:explain].gsub("'", "\\\\'")
|
43
|
+
expect = result[:expect] # .gsub("'", "\\\\'")
|
44
|
+
fp.puts " it '#{explain}' do"
|
45
|
+
if result[:to_be]
|
46
|
+
fp.puts " expect(#{expect}).to be_a(#{result[:to_be]})"
|
47
|
+
elsif result[:raises]
|
48
|
+
fp.puts " expect {#{expect}}.to raise_error(#{result[:raises]})"
|
49
|
+
else
|
50
|
+
raise "Invalid result: #{result}"
|
51
|
+
end
|
52
|
+
fp.puts " end"
|
53
|
+
end
|
54
|
+
fp.puts "end"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_lines(timeout_seconds)
|
59
|
+
lines = []
|
60
|
+
# py_source = IO.read("./contrib/Onigmo/testpy.py")
|
61
|
+
File::open("./contrib/Onigmo/testpy.py") do |f|
|
62
|
+
f.each.with_index do |line, line_num|
|
63
|
+
# break if line_num > 800
|
64
|
+
line.force_encoding("utf-8")
|
65
|
+
if !line.match(/ONIG_SYNTAX_PERL/)
|
66
|
+
if(md = line.match(/^\s*(?:x|x2|n)\s*\(.+?$/u) rescue nil)
|
67
|
+
line.sub!(/,\s*\".+?$/, ", results, timeout_seconds)") rescue nil
|
68
|
+
lines.push line if line
|
69
|
+
end
|
70
|
+
else
|
71
|
+
warn "Perl syntax. \nline:#{line}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
lines
|
76
|
+
end
|
77
|
+
|
78
|
+
def check_normal_test(reg, results, timeout_seconds)
|
79
|
+
result = nil
|
80
|
+
a_test = eval("/#{reg}/")
|
81
|
+
timeout(timeout_seconds) do
|
82
|
+
10.times do | i |
|
83
|
+
md = a_test.match_data(seed: i)
|
84
|
+
if(md)
|
85
|
+
# print "OK md:#{md},"
|
86
|
+
result = {
|
87
|
+
explain: "can parse (#{reg}) and generate match-data",
|
88
|
+
expect: "/#{reg}/.match_data",
|
89
|
+
to_be: "MatchData"
|
90
|
+
}
|
91
|
+
else
|
92
|
+
warn "Failed. reg='#{a_test}', reason=#{obj.reason}"
|
93
|
+
result = {
|
94
|
+
explain: "cannot parse / generate (#{reg})",
|
95
|
+
expect: "/#{reg}/.match_data",
|
96
|
+
to_be: "Nil"
|
97
|
+
}
|
98
|
+
break
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
results.push result
|
103
|
+
rescue => ex
|
104
|
+
warn "GOO: #{ex} #{ex.class}"
|
105
|
+
results.push({
|
106
|
+
explain: "raises #{ex}, when parse / generate (#{reg})",
|
107
|
+
expect: "/#{reg}/.match_data",
|
108
|
+
raises: "#{ex.class}"
|
109
|
+
})
|
110
|
+
end
|
111
|
+
|
112
|
+
def x(reg, *params)
|
113
|
+
check_normal_test(reg, *params)
|
114
|
+
end
|
115
|
+
|
116
|
+
def x2(reg, *params)
|
117
|
+
check_normal_test(reg, *params)
|
118
|
+
end
|
119
|
+
|
120
|
+
def n(reg, *params)
|
121
|
+
check_normal_test(reg, *params)
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
# Test suite (execute when this file is specified in command line)
|
127
|
+
if __FILE__ == $0
|
128
|
+
Regextest::Test.new
|
129
|
+
end
|
@@ -8,6 +8,7 @@ require 'regextest/common'
|
|
8
8
|
class Regextest::Back::Element
|
9
9
|
include Regextest::Common
|
10
10
|
def initialize(param)
|
11
|
+
# puts "Element param:#{param[:cmd]} data:#{param[:data].size}"
|
11
12
|
@command = param[:cmd]
|
12
13
|
@param = param
|
13
14
|
@candidates = param[:data] if @command == :CMD_SELECT
|
@@ -24,7 +25,7 @@ class Regextest::Back::Element
|
|
24
25
|
else
|
25
26
|
raise "invalid command at random_fix: #{@command}"
|
26
27
|
end
|
27
|
-
result
|
28
|
+
[result].pack("U*") # tranforms from code point to a letter
|
28
29
|
end
|
29
30
|
|
30
31
|
# size of candidates
|
@@ -96,32 +97,34 @@ class Regextest::Back::Element
|
|
96
97
|
|
97
98
|
# Includes new line or not
|
98
99
|
def new_line?
|
99
|
-
@candidates.index(
|
100
|
+
@candidates.index(0xa)
|
100
101
|
end
|
101
102
|
|
102
103
|
# Sets new line
|
103
104
|
def set_new_line
|
104
|
-
@candidates = [
|
105
|
+
@candidates = [0xa]
|
105
106
|
end
|
106
107
|
|
107
108
|
# Is word-elements only?
|
108
109
|
def word_elements?
|
109
|
-
@candidates.
|
110
|
+
letters = @candidates.map{|elem| [elem].pack("U*")}
|
111
|
+
letters.join("").match(/^\p{Word}+$/)
|
110
112
|
end
|
111
113
|
|
112
114
|
# is non-word-elements only?
|
113
115
|
def non_word_elements?
|
114
|
-
@candidates.
|
116
|
+
letters = @candidates.map{|elem| [elem].pack("U*")}
|
117
|
+
letters.join("").match(/^\p{^Word}+$/)
|
115
118
|
end
|
116
119
|
|
117
120
|
# set word-elements
|
118
121
|
def set_word_elements
|
119
|
-
@candidates.select!{|elem| elem.match(/^\w$/)}
|
122
|
+
@candidates.select!{|elem| [elem].pack("U*").match(/^\w$/)}
|
120
123
|
end
|
121
124
|
|
122
125
|
# set non_word-elements
|
123
126
|
def set_non_word_elements
|
124
|
-
@candidates.select!{|elem| elem.match(/^\W$/)}
|
127
|
+
@candidates.select!{|elem| [elem].pack("U*").match(/^\W$/)}
|
125
128
|
end
|
126
129
|
|
127
130
|
# checks empty
|
@@ -132,12 +135,12 @@ class Regextest::Back::Element
|
|
132
135
|
# factory method to generate any char element
|
133
136
|
def self.any_char
|
134
137
|
# BUG: must consider other character set!
|
135
|
-
Regextest::Back::Element.new({cmd: :CMD_SELECT, data: (
|
138
|
+
Regextest::Back::Element.new({cmd: :CMD_SELECT, data: (0x20..0x7e).to_a})
|
136
139
|
end
|
137
140
|
|
138
141
|
# factory method to generate any char element
|
139
142
|
def reverse
|
140
|
-
@candidates = ((
|
143
|
+
@candidates = ((0x20..0x7e).to_a) - @candidates
|
141
144
|
self
|
142
145
|
end
|
143
146
|
|
data/lib/regextest/back/main.rb
CHANGED
@@ -266,8 +266,7 @@ class Regextest::Back::Main
|
|
266
266
|
target = param[:json]
|
267
267
|
letter = []
|
268
268
|
codepoints = (target["begin"]..target["end"]).to_a
|
269
|
-
|
270
|
-
result = Regextest::Back::Element.new({cmd: :CMD_SELECT, data: letter})
|
269
|
+
result = Regextest::Back::Element.new({cmd: :CMD_SELECT, data: codepoints})
|
271
270
|
end
|
272
271
|
|
273
272
|
# back_refer
|
@@ -305,7 +304,8 @@ class Regextest::Back::Main
|
|
305
304
|
target = param[:json]
|
306
305
|
case target["value"]
|
307
306
|
when String
|
308
|
-
|
307
|
+
codepoint = target["value"].unpack("U*")[0]
|
308
|
+
result = Regextest::Back::Element.new({cmd: :CMD_SELECT, data: [codepoint]})
|
309
309
|
else
|
310
310
|
result = generate_candidates({json: target["value"]})
|
311
311
|
end
|
@@ -314,6 +314,7 @@ class Regextest::Back::Main
|
|
314
314
|
|
315
315
|
# narrow down candidates considering anchors
|
316
316
|
def narrow_down_candidates(candidate_array)
|
317
|
+
# pp candidate_array
|
317
318
|
results = Regextest::Back::Result.new
|
318
319
|
candidate_array.each do | elem |
|
319
320
|
command = elem.command
|
@@ -127,18 +127,18 @@ class Regextest::Back::Result
|
|
127
127
|
# Merge each elements of not-look-aheads
|
128
128
|
def merge_not_look_ahead_elems(offset, sub_results)
|
129
129
|
if Regextest::Back::Result === sub_results
|
130
|
-
term_offset = offset + sub_results.end_offset
|
130
|
+
term_offset = offset + sub_results.end_offset
|
131
131
|
else
|
132
|
-
term_offset = offset + sub_results.size
|
132
|
+
term_offset = offset + sub_results.size
|
133
133
|
end
|
134
134
|
try_order = TstShuffle(sub_results.size.times.to_a)
|
135
|
-
|
136
135
|
found = false
|
137
136
|
# exclude, at least, one element
|
138
137
|
try_order.each do | j |
|
139
138
|
results_work = @results.dup
|
140
139
|
cur_offset = offset + j
|
141
140
|
|
141
|
+
# puts "offset=#{offset} term_offset=#{term_offset}"
|
142
142
|
offset.step(term_offset-1).each do | i |
|
143
143
|
sub_elem = sub_results[i-offset]
|
144
144
|
|
data/lib/regextest/version.rb
CHANGED
data/regextest.gemspec
CHANGED
@@ -19,8 +19,12 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.required_ruby_version = '>= 1.9.3'
|
23
|
+
|
24
|
+
spec.add_development_dependency "ruby"
|
22
25
|
spec.add_development_dependency "bundler", "~> 1.8"
|
23
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "racc", "~> 1.4.12"
|
24
28
|
spec.add_development_dependency "yard", "~> 0.9.5"
|
25
|
-
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.5.0"
|
26
30
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regextest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
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-
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,20 @@ dependencies:
|
|
38
52
|
- - ~>
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: racc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.4.12
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.4.12
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: yard
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +84,16 @@ dependencies:
|
|
56
84
|
name: rspec
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
|
-
- -
|
87
|
+
- - ~>
|
60
88
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
89
|
+
version: 3.5.0
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
|
-
- -
|
94
|
+
- - ~>
|
67
95
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
96
|
+
version: 3.5.0
|
69
97
|
description: 'Regextest generates sample string that matches with regular expression.
|
70
98
|
Unlike similar tools, it recognizes anchors, charactor classes and other advanced
|
71
99
|
notation of ruby regex. Target users are programmers or students for debugging/learning
|
@@ -101,6 +129,7 @@ files:
|
|
101
129
|
- contrib/unicode/Scripts.txt
|
102
130
|
- contrib/unicode/UnicodeData.txt
|
103
131
|
- lib/pre-case-folding.rb
|
132
|
+
- lib/pre-generate-spec.rb
|
104
133
|
- lib/pre-posix-char-class.rb
|
105
134
|
- lib/pre-unicode.rb
|
106
135
|
- lib/regextest.rb
|
@@ -151,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
180
|
requirements:
|
152
181
|
- - '>='
|
153
182
|
- !ruby/object:Gem::Version
|
154
|
-
version:
|
183
|
+
version: 1.9.3
|
155
184
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
185
|
requirements:
|
157
186
|
- - '>='
|