RegexpBench 0.5.0 → 0.5.1
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.
- data/bin/regexp-bench +21 -1
- data/doc/README +58 -2
- data/lib/regexp-bench/arguments.rb +20 -0
- data/lib/regexp-bench/commands.rb +68 -20
- data/lib/regexp-bench/regexp-bench.rb +56 -0
- metadata +8 -7
data/bin/regexp-bench
CHANGED
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
#!/bin/env ruby
|
|
2
2
|
require 'regexp-bench/commands'
|
|
3
|
+
require 'yaml'
|
|
4
|
+
|
|
5
|
+
loaded_strings = []
|
|
6
|
+
|
|
7
|
+
ARGV.each do |arg|
|
|
8
|
+
if File.exists?(arg) and File.file?(arg)
|
|
9
|
+
File::open(arg, "r") do |match_list|
|
|
10
|
+
loaded_strings += RegexpBench.clean_strings(YAML::load(match_list))
|
|
11
|
+
end
|
|
12
|
+
else
|
|
13
|
+
warn "#{arg} couldn't be opened for loading"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
3
16
|
|
|
4
17
|
interpreter = Command::TextInterpreter.new
|
|
18
|
+
|
|
19
|
+
def interpreter.get_formatter()
|
|
20
|
+
Command::Results::StrategyFormatter.new(::Command::raw_stdout)
|
|
21
|
+
end
|
|
22
|
+
|
|
5
23
|
interpreter.command_set = RegexpBench::commands
|
|
6
24
|
|
|
25
|
+
interpreter.behavior(:debug_commands => true)
|
|
26
|
+
|
|
7
27
|
subject = interpreter.subject_template
|
|
8
|
-
subject.test_strings =
|
|
28
|
+
subject.test_strings = loaded_strings
|
|
9
29
|
subject.interpreter = interpreter
|
|
10
30
|
subject.command_set = interpreter.command_set
|
|
11
31
|
|
data/doc/README
CHANGED
|
@@ -1,2 +1,58 @@
|
|
|
1
|
-
==
|
|
2
|
-
|
|
1
|
+
== Welcome to Regexp Bench
|
|
2
|
+
|
|
3
|
+
Basically, start up 'regexp-bench' You'll get an interactive command line,
|
|
4
|
+
complete with a help function.
|
|
5
|
+
|
|
6
|
+
An example exchange with regexp-bench:
|
|
7
|
+
|
|
8
|
+
$ bin/regexp-bench
|
|
9
|
+
> load_matches do
|
|
10
|
+
do doc/ dog-cat.yaml
|
|
11
|
+
> load_matches dog-cat.yaml
|
|
12
|
+
> list_matches
|
|
13
|
+
Match: dog
|
|
14
|
+
Don't Match: cat
|
|
15
|
+
> test .o.
|
|
16
|
+
Regexp compiles as: (?-mix:.o.)
|
|
17
|
+
Matching "dog"
|
|
18
|
+
Successful match:
|
|
19
|
+
Before:
|
|
20
|
+
m[0]: dog
|
|
21
|
+
After:
|
|
22
|
+
Matching "cat"
|
|
23
|
+
Successful null match
|
|
24
|
+
> test ...
|
|
25
|
+
Regexp compiles as: (?-mix:...)
|
|
26
|
+
Matching "dog"
|
|
27
|
+
Successful match:
|
|
28
|
+
Before:
|
|
29
|
+
m[0]: dog
|
|
30
|
+
After:
|
|
31
|
+
Matching "cat"
|
|
32
|
+
ERROR: match:
|
|
33
|
+
Before:
|
|
34
|
+
m[0]: cat
|
|
35
|
+
After:
|
|
36
|
+
> help
|
|
37
|
+
clear_matches
|
|
38
|
+
dont_match <string> [<string>]
|
|
39
|
+
help <terms> [<terms>]
|
|
40
|
+
list_matches
|
|
41
|
+
load_matches <load_from> [<load_from>]
|
|
42
|
+
match <string> [<string>]
|
|
43
|
+
quit
|
|
44
|
+
redo
|
|
45
|
+
remove <string> [<string>]
|
|
46
|
+
save_matches <save_to> [<save_to>]
|
|
47
|
+
test <regex> [<regex>]
|
|
48
|
+
undo
|
|
49
|
+
> quit
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
Still not as pretty as I'd like it to be, but we'll get there before 1.0.
|
|
53
|
+
|
|
54
|
+
== TODO
|
|
55
|
+
|
|
56
|
+
- Better help documentation!
|
|
57
|
+
- Rspec file output
|
|
58
|
+
- Code generation based on a successful test
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
module Command
|
|
4
|
+
#This is a demonstration of how easy it is to extend arguments. Probably
|
|
5
|
+
#this class belongs in the main CommandSet, but 0.8.0 doesn't have it yet,
|
|
6
|
+
#so it's added here.
|
|
7
|
+
class RestOfLine < StringArgument
|
|
8
|
+
register "rest"
|
|
9
|
+
|
|
10
|
+
def consume(subject, arguments)
|
|
11
|
+
term = arguments.join(" ")
|
|
12
|
+
arguments.clear
|
|
13
|
+
unless validate(term, subject)
|
|
14
|
+
raise ArgumentInvalidException, {@name => term}
|
|
15
|
+
end
|
|
16
|
+
return {@name => parse(subject, term)}
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'command-set'
|
|
2
2
|
require 'command-set/standard-commands'
|
|
3
3
|
require 'regexp-bench/regexp-bench'
|
|
4
|
+
require 'regexp-bench/arguments'
|
|
4
5
|
|
|
5
6
|
module RegexpBench
|
|
6
7
|
def self.commands
|
|
@@ -10,33 +11,29 @@ module RegexpBench
|
|
|
10
11
|
include_commands Command::StandardCommands::Undo
|
|
11
12
|
|
|
12
13
|
command :test do
|
|
13
|
-
|
|
14
|
+
rest_argument :regex, "The regular expression to be tested"
|
|
14
15
|
|
|
15
16
|
subject_methods :test_strings
|
|
16
17
|
|
|
17
18
|
doesnt_undo
|
|
18
19
|
|
|
20
|
+
format_advice do
|
|
21
|
+
list do |list|
|
|
22
|
+
if list.depth == 1
|
|
23
|
+
{:type => :indent}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
19
28
|
action do
|
|
20
29
|
begin
|
|
21
30
|
regex = Regexp.compile(regex().chomp)
|
|
22
|
-
item regex
|
|
31
|
+
item "Regexp compiles as: " + regex.to_s
|
|
23
32
|
|
|
24
33
|
list "tests" do
|
|
25
|
-
subject.test_strings.each do |
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
item "Matching: \"#{test_string}\""
|
|
29
|
-
match = regex.match(test_string)
|
|
30
|
-
|
|
31
|
-
if(match.nil?)
|
|
32
|
-
puts "Null match"
|
|
33
|
-
else
|
|
34
|
-
puts "Before: " + match.pre_match
|
|
35
|
-
match.to_a.each_index do |idx|
|
|
36
|
-
puts "m[#{idx}]: #{match[idx]}"
|
|
37
|
-
end
|
|
38
|
-
puts "After: " + match.post_match
|
|
39
|
-
end
|
|
34
|
+
subject.test_strings.each do |test_string|
|
|
35
|
+
list "Matching \"#{test_string.to_s}\"" do
|
|
36
|
+
test_string.test_match(regex)
|
|
40
37
|
end
|
|
41
38
|
end
|
|
42
39
|
end
|
|
@@ -47,7 +44,7 @@ module RegexpBench
|
|
|
47
44
|
end
|
|
48
45
|
|
|
49
46
|
command :match do
|
|
50
|
-
|
|
47
|
+
rest_argument :string, "A string to match"
|
|
51
48
|
|
|
52
49
|
subject_methods :test_strings
|
|
53
50
|
|
|
@@ -62,7 +59,7 @@ module RegexpBench
|
|
|
62
59
|
end
|
|
63
60
|
|
|
64
61
|
command :dont_match do
|
|
65
|
-
|
|
62
|
+
rest_argument :string, "A string to match"
|
|
66
63
|
|
|
67
64
|
subject_methods :test_strings
|
|
68
65
|
|
|
@@ -103,12 +100,63 @@ module RegexpBench
|
|
|
103
100
|
action do
|
|
104
101
|
list "matches" do
|
|
105
102
|
subject.test_strings.each do |string|
|
|
106
|
-
|
|
103
|
+
string.list
|
|
107
104
|
end
|
|
108
105
|
end
|
|
109
106
|
end
|
|
110
107
|
end
|
|
111
108
|
|
|
109
|
+
command :clear_matches do
|
|
110
|
+
subject_methods :test_strings
|
|
111
|
+
|
|
112
|
+
action do
|
|
113
|
+
@saved_strings = subject.test_strings.dup
|
|
114
|
+
subject.test_strings.clear
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
undo do
|
|
118
|
+
subject.test_strings.replace(@saved_strings)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
command :save_matches do
|
|
123
|
+
file_argument :save_to do |path|
|
|
124
|
+
not File::exists?(path) or File::file?(path)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
subject_methods :test_strings
|
|
128
|
+
|
|
129
|
+
doesnt_undo
|
|
130
|
+
|
|
131
|
+
action do
|
|
132
|
+
require 'yaml'
|
|
133
|
+
|
|
134
|
+
File::open(save_to(), "w") do |save|
|
|
135
|
+
save.write(YAML.dump(subject.test_strings))
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
command :load_matches do
|
|
141
|
+
file_argument :load_from, {}
|
|
142
|
+
|
|
143
|
+
subject_methods :test_strings
|
|
144
|
+
|
|
145
|
+
action do
|
|
146
|
+
require 'yaml'
|
|
147
|
+
|
|
148
|
+
@saved_strings = subject.test_strings.dup
|
|
149
|
+
|
|
150
|
+
File::open(load_from(), "r") do |file|
|
|
151
|
+
strings = RegexpBench.clean_strings(YAML.load(file))
|
|
152
|
+
subject.test_strings.push(*strings)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
undo do
|
|
157
|
+
subject.test_strings.replace(@saved_strings)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
112
160
|
end
|
|
113
161
|
end
|
|
114
162
|
end
|
|
@@ -1,13 +1,69 @@
|
|
|
1
1
|
module RegexpBench
|
|
2
|
+
def self.clean_strings(array)
|
|
3
|
+
array.map! do |string|
|
|
4
|
+
unless MatchString === string
|
|
5
|
+
string = MatchString.new(string.to_s)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
string
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
2
12
|
class MatchString
|
|
3
13
|
def initialize(string)
|
|
4
14
|
@string = string
|
|
5
15
|
end
|
|
6
16
|
|
|
7
17
|
attr_reader :string
|
|
18
|
+
|
|
19
|
+
def to_s
|
|
20
|
+
return @string.dup
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def list
|
|
24
|
+
puts "Match: " + string
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_match(regex)
|
|
28
|
+
match = regex.match(string)
|
|
29
|
+
|
|
30
|
+
if(match.nil?)
|
|
31
|
+
null_match
|
|
32
|
+
else
|
|
33
|
+
matched(match)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def null_match
|
|
38
|
+
puts "ERROR: Null match"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def matched(match)
|
|
42
|
+
puts "Successful match:"
|
|
43
|
+
puts "Before: " + match.pre_match
|
|
44
|
+
match.to_a.each_index do |idx|
|
|
45
|
+
puts "m[#{idx}]: #{match[idx]}"
|
|
46
|
+
end
|
|
47
|
+
puts "After: " + match.post_match
|
|
48
|
+
end
|
|
8
49
|
end
|
|
9
50
|
|
|
10
51
|
class DontMatchString < MatchString
|
|
52
|
+
def list
|
|
53
|
+
puts "Don't Match: " + string
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def null_match
|
|
57
|
+
puts "Successful null match"
|
|
58
|
+
end
|
|
11
59
|
|
|
60
|
+
def matched(match)
|
|
61
|
+
puts "ERROR: match:"
|
|
62
|
+
puts "Before: " + match.pre_match
|
|
63
|
+
match.to_a.each_index do |idx|
|
|
64
|
+
puts "m[#{idx}]: #{match[idx]}"
|
|
65
|
+
end
|
|
66
|
+
puts "After: " + match.post_match
|
|
67
|
+
end
|
|
12
68
|
end
|
|
13
69
|
end
|
metadata
CHANGED
|
@@ -3,15 +3,15 @@ rubygems_version: 0.9.4
|
|
|
3
3
|
specification_version: 1
|
|
4
4
|
name: RegexpBench
|
|
5
5
|
version: !ruby/object:Gem::Version
|
|
6
|
-
version: 0.5.
|
|
7
|
-
date: 2007-12-
|
|
6
|
+
version: 0.5.1
|
|
7
|
+
date: 2007-12-10 00:00:00 -08:00
|
|
8
8
|
summary: Regular expression experimental user app.
|
|
9
9
|
require_paths:
|
|
10
10
|
- lib
|
|
11
11
|
email: nyarly@gmail.com
|
|
12
12
|
homepage:
|
|
13
13
|
rubyforge_project:
|
|
14
|
-
description: Interactive testing and experimentation with regular expressions.
|
|
14
|
+
description: "Interactive testing and experimentation with regular expressions. To start, type 'regexp-bench' First command: help. Current nicest feature: saving and restoring test strings from a YAML file. Biggest wishlist item: automatic rspec output."
|
|
15
15
|
autorequire:
|
|
16
16
|
default_executable:
|
|
17
17
|
bindir: bin
|
|
@@ -25,11 +25,12 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
|
25
25
|
platform: ruby
|
|
26
26
|
signing_key:
|
|
27
27
|
cert_chain:
|
|
28
|
-
post_install_message:
|
|
28
|
+
post_install_message: To begin, run 'regexp-bench' - try 'help' as your first command
|
|
29
29
|
authors:
|
|
30
30
|
- Judson Lester
|
|
31
31
|
files:
|
|
32
32
|
- lib/regexp-bench
|
|
33
|
+
- lib/regexp-bench/arguments.rb
|
|
33
34
|
- lib/regexp-bench/commands.rb
|
|
34
35
|
- lib/regexp-bench/regexp-bench.rb
|
|
35
36
|
- lib/regexp-bench/regex-test.rb
|
|
@@ -43,11 +44,11 @@ rdoc_options:
|
|
|
43
44
|
- --main
|
|
44
45
|
- doc/README
|
|
45
46
|
- --title
|
|
46
|
-
- RegexpBench-0.5.
|
|
47
|
+
- RegexpBench-0.5.1 RDoc
|
|
47
48
|
extra_rdoc_files:
|
|
48
49
|
- doc/README
|
|
49
|
-
executables:
|
|
50
|
-
|
|
50
|
+
executables:
|
|
51
|
+
- regexp-bench
|
|
51
52
|
extensions: []
|
|
52
53
|
|
|
53
54
|
requirements: []
|