RegexpBench 0.5.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.
data/bin/regexp-bench ADDED
@@ -0,0 +1,13 @@
1
+ #!/bin/env ruby
2
+ require 'regexp-bench/commands'
3
+
4
+ interpreter = Command::TextInterpreter.new
5
+ interpreter.command_set = RegexpBench::commands
6
+
7
+ subject = interpreter.subject_template
8
+ subject.test_strings = []
9
+ subject.interpreter = interpreter
10
+ subject.command_set = interpreter.command_set
11
+
12
+ interpreter.subject = subject
13
+ interpreter.go
data/doc/README ADDED
@@ -0,0 +1,2 @@
1
+ == This is a Really Cool Ruby Thing
2
+ === ( That deserves better documentation than this. )
@@ -0,0 +1,116 @@
1
+ require 'command-set'
2
+ require 'command-set/standard-commands'
3
+ require 'regexp-bench/regexp-bench'
4
+
5
+ module RegexpBench
6
+ def self.commands
7
+ Command::CommandSet::define_commands do
8
+ include_commands Command::StandardCommands::Quit
9
+ include_commands Command::StandardCommands::Help
10
+ include_commands Command::StandardCommands::Undo
11
+
12
+ command :test do
13
+ argument :regex, "The regular expression to be tested"
14
+
15
+ subject_methods :test_strings
16
+
17
+ doesnt_undo
18
+
19
+ action do
20
+ begin
21
+ regex = Regexp.compile(regex().chomp)
22
+ item regex
23
+
24
+ list "tests" do
25
+ subject.test_strings.each do |match_test_string|
26
+ test_string = match_test_string.string
27
+ list test_string do
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
40
+ end
41
+ end
42
+ end
43
+ rescue RegexpError => ree
44
+ puts ree.message
45
+ end
46
+ end
47
+ end
48
+
49
+ command :match do
50
+ argument :string, "A string to match"
51
+
52
+ subject_methods :test_strings
53
+
54
+ action do
55
+ @string = MatchString.new(string)
56
+ subject.test_strings << @string
57
+ end
58
+
59
+ undo do
60
+ subject.test_strings.delete(@string)
61
+ end
62
+ end
63
+
64
+ command :dont_match do
65
+ argument :string, "A string to match"
66
+
67
+ subject_methods :test_strings
68
+
69
+ action do
70
+ @string = DontMatchString.new(string)
71
+ subject.test_strings << @string
72
+ end
73
+
74
+ undo do
75
+ subject.test_strings.delete(@string)
76
+ end
77
+ end
78
+
79
+ command :remove do
80
+ argument :string do |prefix, subject|
81
+ subject.test_strings.grep(%r{^#{prefix}.*})
82
+ end
83
+
84
+ subject_methods :test_strings
85
+
86
+ action do
87
+ @string = subject.test_strings.find do |matcher|
88
+ matcher.string == string()
89
+ end
90
+ subject.test_strings.delete(@string)
91
+ end
92
+
93
+ undo do
94
+ subject.test_strings << @string
95
+ end
96
+ end
97
+
98
+ command :list_matches do
99
+ subject_methods :test_strings
100
+
101
+ doesnt_undo
102
+
103
+ action do
104
+ list "matches" do
105
+ subject.test_strings.each do |string|
106
+ item string
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ end
113
+ end
114
+ end
115
+
116
+
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'readline'
4
+
5
+ test_strings = ARGV
6
+
7
+ while test = Readline::readline('Regex: ', true)
8
+ begin
9
+ regex = Regexp.compile(test.chomp)
10
+ puts regex
11
+ puts ""
12
+
13
+ test_strings.each do |test_string|
14
+ puts "Matching: \"#{test_string}\""
15
+ match = regex.match(test_string)
16
+
17
+ if(match.nil?)
18
+ puts "Null match"
19
+ else
20
+ puts "Before: " + match.pre_match
21
+ match.to_a.each_index do |idx|
22
+ puts "m[#{idx}]: #{match[idx]}"
23
+ end
24
+ puts "After: " + match.post_match
25
+ end
26
+ puts ""
27
+ end
28
+ rescue RegexpError => ree
29
+ puts ree.message
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ module RegexpBench
2
+ class MatchString
3
+ def initialize(string)
4
+ @string = string
5
+ end
6
+
7
+ attr_reader :string
8
+ end
9
+
10
+ class DontMatchString < MatchString
11
+
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: RegexpBench
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.5.0
7
+ date: 2007-12-06 00:00:00 -08:00
8
+ summary: Regular expression experimental user app.
9
+ require_paths:
10
+ - lib
11
+ email: nyarly@gmail.com
12
+ homepage:
13
+ rubyforge_project:
14
+ description: Interactive testing and experimentation with regular expressions. Ultimately, you can use it to generate RSpec descriptions based on the interactive testing you do.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message: Another tidy package brought to you Judson
29
+ authors:
30
+ - Judson Lester
31
+ files:
32
+ - lib/regexp-bench
33
+ - lib/regexp-bench/commands.rb
34
+ - lib/regexp-bench/regexp-bench.rb
35
+ - lib/regexp-bench/regex-test.rb
36
+ - bin/regexp-bench
37
+ - doc/README
38
+ test_files: []
39
+
40
+ rdoc_options:
41
+ - --diagram
42
+ - --inline-source
43
+ - --main
44
+ - doc/README
45
+ - --title
46
+ - RegexpBench-0.5.0 RDoc
47
+ extra_rdoc_files:
48
+ - doc/README
49
+ executables: []
50
+
51
+ extensions: []
52
+
53
+ requirements: []
54
+
55
+ dependencies:
56
+ - !ruby/object:Gem::Dependency
57
+ name: command-set
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Version::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 0.8.0
64
+ version: