rfs 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +7 -0
- data/Rakefile.rb +193 -0
- data/bin/RenameFileSet.rbw +14 -0
- data/bin/rfs.rb +214 -0
- data/bin/rfsd.rb +8 -0
- data/description.txt +24 -0
- data/lib/RenameFileSet.bak.rb +372 -0
- data/lib/errors.rb +15 -0
- data/lib/filters.rb +68 -0
- data/lib/gui.rb +216 -0
- data/lib/innate/array.rb +104 -0
- data/lib/innate/coverage.rb +315 -0
- data/lib/innate/debug.rb +12 -0
- data/lib/innate/debugger.rb +944 -0
- data/lib/innate/file.rb +5 -0
- data/lib/innate/filelines.rb +148 -0
- data/lib/innate/kernel.rb +41 -0
- data/lib/innate/metaid.rb +30 -0
- data/lib/innate/mkdirs.rb +12 -0
- data/lib/innate/regexp.rb +80 -0
- data/lib/innate/reload.rb +11 -0
- data/lib/innate/roman.rb +72 -0
- data/lib/innate/scriptlines.rb +60 -0
- data/lib/innate/string.rb +56 -0
- data/lib/innate/test/all_tests.rb +11 -0
- data/lib/innate/test/files/mkdirs_dummy.file +1 -0
- data/lib/innate/test/files/reloadtarget.rb +5 -0
- data/lib/innate/test/files/reloadtarget1.rb +5 -0
- data/lib/innate/test/files/reloadtarget2.rb +5 -0
- data/lib/innate/test/test_coverage.rb +13 -0
- data/lib/innate/test/testarray.rb +98 -0
- data/lib/innate/test/testfile.rb +15 -0
- data/lib/innate/test/testfilelines.rb +106 -0
- data/lib/innate/test/testkernel.rb +30 -0
- data/lib/innate/test/testmkdirs.rb +19 -0
- data/lib/innate/test/testregexp.rb +86 -0
- data/lib/innate/test/testreload.rb +61 -0
- data/lib/innate/test/testroman.rb +54 -0
- data/lib/innate/test/testscriptlines.rb +39 -0
- data/lib/innate/test/teststring.rb +52 -0
- data/lib/innate/test/testtitlecase.rb +20 -0
- data/lib/innate/titlecase.rb +64 -0
- data/lib/innate/tracerequire.rb +22 -0
- data/lib/namesource.rb +53 -0
- data/lib/options.rb +64 -0
- data/lib/providers.rb +93 -0
- data/lib/regexp.rb +56 -0
- data/lib/rename_functions.rb +142 -0
- data/lib/renamer.rb +210 -0
- data/lib/results.rb +83 -0
- data/lib/test/test_helper.rb +147 -0
- data/tests/dir/file1 +0 -0
- data/tests/dir/file2 +0 -0
- data/tests/dir/file3 +0 -0
- data/tests/test_helper.rb +147 -0
- data/tests/test_rename_functions.rb +605 -0
- metadata +105 -0
@@ -0,0 +1,147 @@
|
|
1
|
+
$TESTING ||= true
|
2
|
+
#require 'innate/tracerequire'
|
3
|
+
require 'innate/debug'
|
4
|
+
require 'innate/reload'
|
5
|
+
require 'pp'
|
6
|
+
require 'test/unit'
|
7
|
+
$:.unshift '../lib'
|
8
|
+
require 'renamer'
|
9
|
+
require 'cursor/indexed'
|
10
|
+
|
11
|
+
|
12
|
+
class RenamerMock < Renamer
|
13
|
+
attr_reader :renames
|
14
|
+
|
15
|
+
def run(name, options, &block)
|
16
|
+
@onrename = block
|
17
|
+
@renames = []
|
18
|
+
@yielded = true
|
19
|
+
p = options[:file_provider]
|
20
|
+
if p.methods.include? "on_after"
|
21
|
+
p.on_after do
|
22
|
+
unless @onrename and @yielded
|
23
|
+
@onrename.call :result => @result, :result_type => @result_type, :result_path => @result_path, :result_file => @result_file
|
24
|
+
@yielded = true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
super(name, options) do |rtype, result, path, file|
|
29
|
+
@result = result
|
30
|
+
@result_type = rtype
|
31
|
+
@result_path = path
|
32
|
+
@result_file = file
|
33
|
+
@yielded = false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def rename(path, oldfn, newfn, full_path = false)
|
38
|
+
super
|
39
|
+
if @onrename
|
40
|
+
r = @onrename.call(:path => path,
|
41
|
+
:oldfn => oldfn,
|
42
|
+
:newfn => newfn,
|
43
|
+
:full_path => full_path,
|
44
|
+
:result => @result,
|
45
|
+
:result_type => @result_type,
|
46
|
+
:result_path => @result_path,
|
47
|
+
:result_file => @result_file,
|
48
|
+
:confirm => @confirm)
|
49
|
+
@yielded = true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
alias actual_rename_orig actual_rename
|
54
|
+
|
55
|
+
def actual_rename(o, n)
|
56
|
+
@renames << [o, n]
|
57
|
+
end
|
58
|
+
|
59
|
+
alias actual_delete_orig actual_delete
|
60
|
+
|
61
|
+
def actual_delete(fn)
|
62
|
+
@renames << [fn, :deleted]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
module FileProviderTestEvents
|
68
|
+
def self.extended(base)
|
69
|
+
base.class.class_eval do
|
70
|
+
alias_method :each_before_fpte, :each
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def each
|
75
|
+
each_before_fpte do |path, file|
|
76
|
+
before path, file
|
77
|
+
yield path, file
|
78
|
+
after path, file
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def on_before &block
|
83
|
+
@on_before = [block]
|
84
|
+
end
|
85
|
+
|
86
|
+
def on_after &block
|
87
|
+
@on_after = [block]
|
88
|
+
end
|
89
|
+
|
90
|
+
def before p, f
|
91
|
+
return unless @on_before
|
92
|
+
@on_before.each do |m|
|
93
|
+
m.call p, f if m
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def after p, f
|
98
|
+
return unless @on_before
|
99
|
+
@on_after.each do |m|
|
100
|
+
m.call p, f if m
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class BaseTest < Test::Unit::TestCase
|
106
|
+
def setup
|
107
|
+
new_files( %w{ dir/. dir/.. dir/file1 dir/file2 dir/file3 } )
|
108
|
+
@r = RenamerMock.new
|
109
|
+
end
|
110
|
+
|
111
|
+
def new_files(files)
|
112
|
+
@files = Provider::File::Array.new(files)
|
113
|
+
add_file_events
|
114
|
+
end
|
115
|
+
|
116
|
+
def add_file_events
|
117
|
+
@files.extend FileProviderTestEvents
|
118
|
+
@files.on_before do |p, f|
|
119
|
+
@path = p
|
120
|
+
@file = f
|
121
|
+
@full_name = fp File.join(p, f)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def fp(path)
|
126
|
+
File.expand_path path
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_shutup; end
|
130
|
+
|
131
|
+
def r(action, name = :rename_replace, expected_yields = nil, options = {})
|
132
|
+
options[:file_provider] ||= @files
|
133
|
+
options[:action] ||= action
|
134
|
+
options[:filter] = Filter.add options[:filter], Filter.new(/^\.+$/) unless options[:test_r_nofilter]
|
135
|
+
yc = 0
|
136
|
+
@r.run name, options do |h|
|
137
|
+
yc += 1
|
138
|
+
yield h if block_given?
|
139
|
+
end
|
140
|
+
if options[:test_r_count]
|
141
|
+
raise 'exception raised' if expected_yields and expected_yields != yc
|
142
|
+
else
|
143
|
+
assert_equal expected_yields, yc, 'Expected yields from renamer' if expected_yields
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
data/tests/dir/file1
ADDED
File without changes
|
data/tests/dir/file2
ADDED
File without changes
|
data/tests/dir/file3
ADDED
File without changes
|
@@ -0,0 +1,147 @@
|
|
1
|
+
$TESTING ||= true
|
2
|
+
#require 'innate/tracerequire'
|
3
|
+
require 'innate/debug'
|
4
|
+
require 'innate/reload'
|
5
|
+
require 'pp'
|
6
|
+
require 'test/unit'
|
7
|
+
$:.unshift '../lib'
|
8
|
+
require 'renamer'
|
9
|
+
require 'cursor/indexed'
|
10
|
+
|
11
|
+
|
12
|
+
class RenamerMock < Renamer
|
13
|
+
attr_reader :renames
|
14
|
+
|
15
|
+
def run(name, options, &block)
|
16
|
+
@onrename = block
|
17
|
+
@renames = []
|
18
|
+
@yielded = true
|
19
|
+
p = options[:file_provider]
|
20
|
+
if p.methods.include? "on_after"
|
21
|
+
p.on_after do
|
22
|
+
unless @onrename and @yielded
|
23
|
+
@onrename.call :result => @result, :result_type => @result_type, :result_path => @result_path, :result_file => @result_file
|
24
|
+
@yielded = true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
super(name, options) do |rtype, result, path, file|
|
29
|
+
@result = result
|
30
|
+
@result_type = rtype
|
31
|
+
@result_path = path
|
32
|
+
@result_file = file
|
33
|
+
@yielded = false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def rename(path, oldfn, newfn, full_path = false)
|
38
|
+
super
|
39
|
+
if @onrename
|
40
|
+
r = @onrename.call(:path => path,
|
41
|
+
:oldfn => oldfn,
|
42
|
+
:newfn => newfn,
|
43
|
+
:full_path => full_path,
|
44
|
+
:result => @result,
|
45
|
+
:result_type => @result_type,
|
46
|
+
:result_path => @result_path,
|
47
|
+
:result_file => @result_file,
|
48
|
+
:confirm => @confirm)
|
49
|
+
@yielded = true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
alias actual_rename_orig actual_rename
|
54
|
+
|
55
|
+
def actual_rename(o, n)
|
56
|
+
@renames << [o, n]
|
57
|
+
end
|
58
|
+
|
59
|
+
alias actual_delete_orig actual_delete
|
60
|
+
|
61
|
+
def actual_delete(fn)
|
62
|
+
@renames << [fn, :deleted]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
module FileProviderTestEvents
|
68
|
+
def self.extended(base)
|
69
|
+
base.class.class_eval do
|
70
|
+
alias_method :each_before_fpte, :each
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def each
|
75
|
+
each_before_fpte do |path, file|
|
76
|
+
before path, file
|
77
|
+
yield path, file
|
78
|
+
after path, file
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def on_before &block
|
83
|
+
@on_before = [block]
|
84
|
+
end
|
85
|
+
|
86
|
+
def on_after &block
|
87
|
+
@on_after = [block]
|
88
|
+
end
|
89
|
+
|
90
|
+
def before p, f
|
91
|
+
return unless @on_before
|
92
|
+
@on_before.each do |m|
|
93
|
+
m.call p, f if m
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def after p, f
|
98
|
+
return unless @on_before
|
99
|
+
@on_after.each do |m|
|
100
|
+
m.call p, f if m
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class BaseTest < Test::Unit::TestCase
|
106
|
+
def setup
|
107
|
+
new_files( %w{ dir/. dir/.. dir/file1 dir/file2 dir/file3 } )
|
108
|
+
@r = RenamerMock.new
|
109
|
+
end
|
110
|
+
|
111
|
+
def new_files(files)
|
112
|
+
@files = Provider::File::Array.new(files)
|
113
|
+
add_file_events
|
114
|
+
end
|
115
|
+
|
116
|
+
def add_file_events
|
117
|
+
@files.extend FileProviderTestEvents
|
118
|
+
@files.on_before do |p, f|
|
119
|
+
@path = p
|
120
|
+
@file = f
|
121
|
+
@full_name = fp File.join(p, f)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def fp(path)
|
126
|
+
File.expand_path path
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_shutup; end
|
130
|
+
|
131
|
+
def r(action, name = :rename_replace, expected_yields = nil, options = {})
|
132
|
+
options[:file_provider] ||= @files
|
133
|
+
options[:action] ||= action
|
134
|
+
options[:filter] = Filter.add options[:filter], Filter.new(/^\.+$/) unless options[:test_r_nofilter]
|
135
|
+
yc = 0
|
136
|
+
@r.run name, options do |h|
|
137
|
+
yc += 1
|
138
|
+
yield h if block_given?
|
139
|
+
end
|
140
|
+
if options[:test_r_count]
|
141
|
+
raise 'exception raised' if expected_yields and expected_yields != yc
|
142
|
+
else
|
143
|
+
assert_equal expected_yields, yc, 'Expected yields from renamer' if expected_yields
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
@@ -0,0 +1,605 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class TestBasics < BaseTest
|
4
|
+
def test_list
|
5
|
+
r :list, :rename_replace, 5, :test_r_nofilter => true do |h|
|
6
|
+
if ['.', '..'].include? @file
|
7
|
+
assert_equal @file + '/', h[:result]
|
8
|
+
else
|
9
|
+
assert_equal @file, h[:result]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_wrong_iterations
|
15
|
+
assert_raise(RuntimeError) {
|
16
|
+
r :list, :rename_replace, 1000, :test_r_count => true do |h|
|
17
|
+
if ['.', '..'].include? @file
|
18
|
+
assert_equal @file + '/', h[:result]
|
19
|
+
else
|
20
|
+
assert_equal @file, h[:result]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_bad_action
|
27
|
+
assert_raise(ActionError) {
|
28
|
+
r :no, :rename_replace
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_bad_method
|
33
|
+
assert_raise(NameError) {
|
34
|
+
r :preview, :foo_bar
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_missing_option
|
39
|
+
assert_raise(MissingOptionError) {
|
40
|
+
r :preview, :rename_replace
|
41
|
+
}
|
42
|
+
end
|
43
|
+
def test_missing_option1
|
44
|
+
# this doesn't raise MissingOptionError because the error is caught and given as result feedback
|
45
|
+
r :preview, :rename_replace, 3, :search => /file/ do |h|
|
46
|
+
assert_match(/MissingOptionError/, h[:result])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
def test_missing_option2
|
50
|
+
assert_raise(MissingOptionError) {
|
51
|
+
r :preview, :rename_replace, nil, :replace => 'good'
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_bad_search
|
56
|
+
assert_raise(BadOptionValueError) {
|
57
|
+
r :preview, :rename_replace, nil, :search => 3
|
58
|
+
}
|
59
|
+
end
|
60
|
+
def test_bad_search1
|
61
|
+
# this doesn't raise BadOptionValueError because the error is caught and given as result feedback
|
62
|
+
r :preview, :rename_replace, 3, :search => /file/, :replace => /aeu/ do |h|
|
63
|
+
assert_match(/BadOptionValueError/, h[:result])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
class TestReplace < BaseTest
|
70
|
+
def rr(expected_yields = nil, options = {}, &b)
|
71
|
+
r :preview, :rename_replace, expected_yields, options, &b
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_replace
|
75
|
+
rr 0, :search => (/none/)
|
76
|
+
rr 1, :search => (/1/), :replace => '9' do |h|
|
77
|
+
assert_equal 'file9', h[:result]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_replace_commit
|
82
|
+
r :commit, :rename_replace, 3, :search => (/file/), :replace => 'boob' do |h|
|
83
|
+
assert_match(/boob[1-3]/, h[:result])
|
84
|
+
end
|
85
|
+
assert_equal [["dir/file1", "dir/boob1"],
|
86
|
+
["dir/file2", "dir/boob2"],
|
87
|
+
["dir/file3", "dir/boob3"]], @r.renames
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_replace_cap
|
91
|
+
rr 3, :search => (/(f)ile/), :replace => 'sm' do |h|
|
92
|
+
assert_match(/smile[1-3]/, h[:result])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_replace_caps
|
97
|
+
rr 3, :search => (/((f)(i)(l)(e)(\d))/),
|
98
|
+
:replace => '->%6%5%4%3%2<-' do |h|
|
99
|
+
assert_match(/->[1-3]elif<-/, h[:result])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_replace_other_cap
|
104
|
+
rr 3, :search => (/((f)(i)(l)(e)(\d))/),
|
105
|
+
:replace => '%6%5%4%3%2',
|
106
|
+
:capture_num => 2 do |h|
|
107
|
+
assert_match(/[1-3]elifile[1-3]/, h[:result])
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
class TestFilter < BaseTest
|
114
|
+
def rr(expected_yields = nil, options = {}, &b)
|
115
|
+
r :preview, :rename_replace, expected_yields, options, &b
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_filter
|
119
|
+
rr 2, :search => (/(.*)\d/), :replace => 'new', :filter => Filter.new(/2/) do |h|
|
120
|
+
assert_match(/new[13]/, h[:newfn])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_filter2
|
125
|
+
rr(5, :search => (/(.*)\d/), :replace => 'new', :filter => Filter.new(/2/),
|
126
|
+
:verbose => true) do |h|
|
127
|
+
if h[:newfn]
|
128
|
+
assert_match(/new[13]/, h[:newfn])
|
129
|
+
else
|
130
|
+
assert_match(/filtered: (\.\.?|file2)/, h[:result])
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_filter3
|
136
|
+
rr(5, :search => (/(.*)\d/), :replace => 'new', :filter => FilterNonMatches.new(/2/),
|
137
|
+
:verbose => true) do |h|
|
138
|
+
if h[:newfn]
|
139
|
+
assert_equal 'new2' , h[:newfn]
|
140
|
+
else
|
141
|
+
assert_match(/filtered: (\.\.?|file[13])/, h[:result])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
class TestConfirm < BaseTest
|
149
|
+
def rr(expected_yields = nil, options = {}, &b)
|
150
|
+
r :commit, :rename_replace, expected_yields, options, &b
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_confirm_yes
|
154
|
+
confirms = 0
|
155
|
+
rr 3, :confirm => (proc {|path, oldfn, newfn, full_name, exists, default|
|
156
|
+
confirms += 1
|
157
|
+
assert_equal 'dir', path
|
158
|
+
assert_match(/file[1-3]/, oldfn)
|
159
|
+
assert_match(/new[1-3]/, newfn)
|
160
|
+
assert_equal false, full_name
|
161
|
+
assert_equal((oldfn[-1] == ?1) ? :yes : :yes, default)
|
162
|
+
:yes
|
163
|
+
}),
|
164
|
+
:search => (/file/), :replace => 'new' do |h|
|
165
|
+
assert_match(/new[123]/, h[:newfn])
|
166
|
+
assert_equal :ok, h[:result_type]
|
167
|
+
assert_equal h[:newfn], h[:result]
|
168
|
+
assert_equal h[:confirm], :yes
|
169
|
+
end
|
170
|
+
assert_equal 3, confirms
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_confirm_all
|
174
|
+
confirms = 0
|
175
|
+
rr 3, :confirm => (proc {|path, oldfn, newfn, full_name, exists, default|
|
176
|
+
confirms += 1
|
177
|
+
assert_equal :yes, default
|
178
|
+
:all
|
179
|
+
}),
|
180
|
+
:search => (/file/), :replace => 'new' do |h|
|
181
|
+
assert_match(/new[123]/, h[:newfn])
|
182
|
+
assert_equal :ok, h[:result_type]
|
183
|
+
assert_equal h[:newfn], h[:result]
|
184
|
+
assert_equal h[:confirm], :all
|
185
|
+
end
|
186
|
+
assert_equal 1, confirms
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_confirm_no
|
190
|
+
confirms = 0
|
191
|
+
rr 3, :confirm => (proc {|path, oldfn, newfn, full_name, exists, default|
|
192
|
+
confirms += 1
|
193
|
+
assert_equal((oldfn[-1] == ?1) ? :yes : :no, default)
|
194
|
+
:no
|
195
|
+
}),
|
196
|
+
:search => (/file/), :replace => 'new' do |h|
|
197
|
+
assert_match(/new[123]/, h[:newfn])
|
198
|
+
assert_equal :skipped, h[:result_type]
|
199
|
+
assert_equal h[:oldfn], h[:result]
|
200
|
+
assert_equal h[:confirm], :no
|
201
|
+
end
|
202
|
+
assert_equal 3, confirms
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_confirm_cancel
|
206
|
+
confirms = 0
|
207
|
+
rr 0, :confirm => (proc {|path, oldfn, newfn, full_name, exists, default|
|
208
|
+
confirms += 1
|
209
|
+
assert_equal :yes, default
|
210
|
+
:cancel
|
211
|
+
}),
|
212
|
+
:search => (/file/), :replace => 'new' do |h|
|
213
|
+
fail
|
214
|
+
end
|
215
|
+
assert_equal 1, confirms
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_confirm_exists
|
219
|
+
raise NotImplementedError.new
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
|
224
|
+
class TestFilesTxt < BaseTest
|
225
|
+
def rr(ey, o, &b)
|
226
|
+
r :preview, :rename_name_source, ey, o, &b
|
227
|
+
end
|
228
|
+
|
229
|
+
def t(s, items, results)
|
230
|
+
rr 3, :search => s,
|
231
|
+
:source => NameStreamSource.new(StringIO.new(items.join("\n"))) do |h|
|
232
|
+
assert_equal results.read1next, h[:newfn]
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_nocap
|
237
|
+
items = %w{ the_first the_second the_third }
|
238
|
+
results = items.to_cursor
|
239
|
+
t(/.*/, items, results)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_cap
|
243
|
+
items = %w{ the_first the_second the_third }
|
244
|
+
results = %w{ filethe_first1 filethe_second2 filethe_third3 }.to_cursor
|
245
|
+
t(/file()/, items, results)
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_not_enough
|
249
|
+
items = %w{ the_first the_second }
|
250
|
+
results = ['filethe_first1', 'filethe_second2', 'file--no data--3'].to_cursor
|
251
|
+
assert_raise(EOFError) {
|
252
|
+
t(/file()/, items, results)
|
253
|
+
}
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_too_many
|
257
|
+
items = %w{ the_first the_second the_third the_extra }
|
258
|
+
results = %w{ filethe_first1 filethe_second2 filethe_third3 nevergethere }.to_cursor
|
259
|
+
t(/file()/, items, results)
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_real_file
|
263
|
+
raise NotImplementedError.new
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_real_file_recursive
|
267
|
+
raise NotImplementedError.new
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
|
272
|
+
class TestAdd < BaseTest
|
273
|
+
def rr(ey = nil, o = {}, &b)
|
274
|
+
r :preview, :rename_add, ey, o, &b
|
275
|
+
end
|
276
|
+
|
277
|
+
def test_add
|
278
|
+
rr 3, :search => (/\d/), :add => 5, :action => :commit do |h|
|
279
|
+
assert_equal h[:oldfn].succ.succ.succ.succ.succ, h[:newfn]
|
280
|
+
end
|
281
|
+
#make sure it went in reverse
|
282
|
+
assert_equal [['dir/file3', 'dir/file8'],
|
283
|
+
['dir/file2', 'dir/file7'],
|
284
|
+
['dir/file1', 'dir/file6']], @r.renames
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_add_neg
|
288
|
+
c = %w{ file-2 file-1 file0 }.to_cursor
|
289
|
+
rr 3, :search => (/\d/), :add => -3, :action => :commit do |h|
|
290
|
+
assert_equal c.read1next, h[:newfn]
|
291
|
+
end
|
292
|
+
#make sure it went in reverse
|
293
|
+
assert_equal [['dir/file1', 'dir/file-2'],
|
294
|
+
['dir/file2', 'dir/file-1'],
|
295
|
+
['dir/file3', 'dir/file0']], @r.renames
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_add_cap
|
299
|
+
rr 3, :search => (/(\d)/), :add => 5 do |h|
|
300
|
+
assert_equal h[:oldfn].succ.succ.succ.succ.succ, h[:newfn]
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
def test_missing_add
|
305
|
+
assert_raise MissingOptionError do
|
306
|
+
rr(3, :search => (/(\d)/)) { |h| fail "shouldn't get here" }
|
307
|
+
end
|
308
|
+
assert_raise BadOptionValueError do
|
309
|
+
rr(3, :search => (/(\d)/), :add => 'something') { |h| fail "shouldn't get here" }
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
|
315
|
+
class TestCount < BaseTest
|
316
|
+
def test_count
|
317
|
+
count = 0
|
318
|
+
r :preview, :rename_count, 3, :search => /()./ do |h|
|
319
|
+
count += 1
|
320
|
+
assert_equal "#{count}#{h[:oldfn]}", h[:newfn]
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
|
326
|
+
class TestFullName < BaseTest
|
327
|
+
def rr(ey = nil, o = {}, &b)
|
328
|
+
r :preview, :rename_from_full_name, ey, o, &b
|
329
|
+
end
|
330
|
+
|
331
|
+
def test_no_cap
|
332
|
+
rr 3, :search => (/file/), :pattern => (/dir/) do |h|
|
333
|
+
assert_match(/dir[1-3]/, h[:newfn], h[:result])
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
def test_cap
|
338
|
+
rr 3, :search => (/(file)/), :pattern => (/(dir)/) do |h|
|
339
|
+
assert_match(/dir[1-3]/, h[:newfn])
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
|
345
|
+
class TestMoveUp < BaseTest
|
346
|
+
def rr(ey = nil, o = {}, &b)
|
347
|
+
r :preview, :rename_move_up, ey, o, &b
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_match
|
351
|
+
rr 3, :search => (/./) do |h|
|
352
|
+
assert_match(%r{^\./file[1-3]$}, h[:newfn], h[:result])
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
def test_no_match
|
357
|
+
rr 0, :search => (/nothing/)
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
|
362
|
+
class TestRoman < BaseTest
|
363
|
+
def rr(ey, o, &b)
|
364
|
+
r :preview, :rename_roman, ey, o, &b
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_to_roman
|
368
|
+
count = 0
|
369
|
+
rr 3, :search => (/(\d)/) do |h|
|
370
|
+
count += 1
|
371
|
+
rn = 'file' + case count
|
372
|
+
when 1; 'I'
|
373
|
+
when 2; 'II'
|
374
|
+
when 3; 'III'
|
375
|
+
end
|
376
|
+
assert_equal rn, h[:newfn]
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
def test_from_roman
|
381
|
+
rr 1, :search => (/of (roman)/i), :file_provider =>
|
382
|
+
TestFileProvider.new(['glory/great war of mcmxiv']) do |h|
|
383
|
+
assert_equal 'great war of 1914', h[:result]
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
|
389
|
+
class TestMarkChange < BaseTest
|
390
|
+
def rr(ey, o, &b)
|
391
|
+
r :preview, :rename_mark_change, ey, o, &b
|
392
|
+
end
|
393
|
+
|
394
|
+
def setup
|
395
|
+
super
|
396
|
+
@changes = %w{ SECTION1.1 SECTION2.1
|
397
|
+
SECTION3.5 SECTION4.1 }.to_cursor
|
398
|
+
new_files(%w{ section1.1
|
399
|
+
section1.2 section1.3
|
400
|
+
section2.1 section3.5 hello section3.6
|
401
|
+
section4.1 section4.2 })
|
402
|
+
end
|
403
|
+
|
404
|
+
def test_changes
|
405
|
+
rr 4, :search => (/section(\d)\./), :replace_pattern => (/section/),
|
406
|
+
:replace_text => 'SECTION' do |h|
|
407
|
+
if h[:newfn]
|
408
|
+
assert_equal @changes.read1next, h[:newfn]
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_changes_rcap
|
414
|
+
rr 4, :search => (/section(\d)\./), :replace_pattern => (/(\w*)\d\./),
|
415
|
+
:replace_text => 'SECTION' do |h|
|
416
|
+
if h[:newfn]
|
417
|
+
assert_equal @changes.read1next, h[:newfn]
|
418
|
+
end
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
def test_changes_rcap_other
|
423
|
+
rr 4, :search => (/section(\d)\./), :replace_pattern => (/()()()(\w*)\d\./),
|
424
|
+
:replace_text => 'SECTION',
|
425
|
+
:capture_num => 4 do |h|
|
426
|
+
if h[:newfn]
|
427
|
+
assert_equal @changes.read1next, h[:newfn]
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
def test_changes_no_cap
|
433
|
+
rr 4, :search => (/\d/), :replace_pattern => (/section/),
|
434
|
+
:replace_text => 'SECTION' do |h|
|
435
|
+
if h[:newfn]
|
436
|
+
assert_equal @changes.read1next, h[:newfn]
|
437
|
+
end
|
438
|
+
end
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
442
|
+
|
443
|
+
class TestTapeNumbers < BaseTest
|
444
|
+
def t(r)
|
445
|
+
results = %w{ tape1 tape2 tape3 tape4}.to_cursor
|
446
|
+
new_files(%w{ tape1A tape1B tape2a tape2b })
|
447
|
+
r(:preview, :rename_tape_numbers, 4, :search => r) do |h|
|
448
|
+
assert_equal results.read1next, h[:newfn]
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
def test_cap
|
453
|
+
t(/tape(..)/)
|
454
|
+
end
|
455
|
+
|
456
|
+
def test_no_cap
|
457
|
+
t(/\d./)
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
|
462
|
+
class TestCapitalize < BaseTest
|
463
|
+
def rr(ey, o, &b)
|
464
|
+
new_files(
|
465
|
+
['this sentence should be capitalized',
|
466
|
+
'here is another one. the best is to see what will happen! is it good?',
|
467
|
+
'how many more do i need here? a few.',
|
468
|
+
"i'll have to get this done soon, it may get boring..."])
|
469
|
+
r :preview, :rename_capitalize, ey, o, &b
|
470
|
+
end
|
471
|
+
|
472
|
+
def test_capitalize
|
473
|
+
changes = ['This Sentence Should Be Capitalized',
|
474
|
+
'Here is Another One. The Best is to See What Will Happen! Is it Good?',
|
475
|
+
'How Many More Do I Need Here? A Few.',
|
476
|
+
"I'll Have to Get This Done Soon, it May Get Boring..."].to_cursor
|
477
|
+
rr 4, :search => (/.*/) do |h|
|
478
|
+
assert_equal changes.read1next, h[:newfn]
|
479
|
+
end
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
483
|
+
|
484
|
+
class TestFill < BaseTest
|
485
|
+
def t(re, f, res = nil)
|
486
|
+
new_files(%w{ first1.1 section1.2 section1.3
|
487
|
+
second2.1 third3.5 hello section3.6
|
488
|
+
fourth4.1 section4.2 })
|
489
|
+
results = res || (%w{ first1.1 first1.2 first1.3
|
490
|
+
second2.1 third3.5 third3.6
|
491
|
+
fourth4.1 fourth4.2 }).to_cursor
|
492
|
+
r :preview, :rename_fill, 9, :search => re, :fill => f do |h|
|
493
|
+
if h[:newfn]
|
494
|
+
assert_equal results.read1next, h[:newfn]
|
495
|
+
elsif h[:result] == '* No capture to fill * hello'
|
496
|
+
# ok...
|
497
|
+
else
|
498
|
+
assert_equal 'source: ' + results.read1next, h[:result]
|
499
|
+
end
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
def test_cap_nocap
|
504
|
+
t(/(.*?)\d/, /section/)
|
505
|
+
end
|
506
|
+
def test_nocap_nocap
|
507
|
+
t(/first|second|third|fourth/, /section/)
|
508
|
+
end
|
509
|
+
def test_cap_cap
|
510
|
+
t(/(.*?)\d/, /(section)/)
|
511
|
+
end
|
512
|
+
def test_cap_cap2
|
513
|
+
t(/(.*?)\d/, /section()/, %w{ first1.1 sectionfirst1.2 sectionfirst1.3
|
514
|
+
second2.1 third3.5 sectionthird3.6
|
515
|
+
fourth4.1 sectionfourth4.2 }.to_cursor)
|
516
|
+
end
|
517
|
+
end
|
518
|
+
|
519
|
+
|
520
|
+
class TestDelete < BaseTest
|
521
|
+
def teardown
|
522
|
+
super
|
523
|
+
unless File.exists? 'dir'
|
524
|
+
Dir.mkdir 'dir'
|
525
|
+
end
|
526
|
+
%w{file1 file2 file3}.each do |f|
|
527
|
+
fn = File.join('dir', f)
|
528
|
+
unless File.exists? fn
|
529
|
+
File.open(fn, 'w') {|f| f.puts fn }
|
530
|
+
end
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
def rr(expected_yields = nil, options = {}, &b)
|
535
|
+
r :preview, :rename_remove, expected_yields, options, &b
|
536
|
+
end
|
537
|
+
|
538
|
+
def test_delete_file
|
539
|
+
rr 1, :search => (/^file2$/), :action => :commit do |h|
|
540
|
+
assert_equal [["dir/file2", :deleted]], @r.renames
|
541
|
+
assert_equal :ok, h[:result_type]
|
542
|
+
assert_equal '<<file2>>', h[:result]
|
543
|
+
assert_equal 'dir', h[:result_path]
|
544
|
+
assert_equal 'file2', h[:result_file]
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
def test_delete_dir_not_empty_sim
|
549
|
+
new_files(%w{ . .. dir })
|
550
|
+
rr 1, :search => (/^dir$/), :action => :commit do |h|
|
551
|
+
assert_equal [["./dir", :deleted]], @r.renames
|
552
|
+
assert_equal :ok, h[:result_type]
|
553
|
+
assert_equal '<<dir>>', h[:result]
|
554
|
+
assert_equal '.', h[:result_path]
|
555
|
+
assert_equal 'dir', h[:result_file]
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
559
|
+
def test_delete_dir_not_empty_real
|
560
|
+
new_files(%w{ . .. dir })
|
561
|
+
class << @r
|
562
|
+
alias actual_delete actual_delete_orig
|
563
|
+
end
|
564
|
+
rr 1, :search => (/^dir$/), :action => :commit do |h|
|
565
|
+
assert_equal :fileerror, h[:result_type]
|
566
|
+
assert_equal "Errno::ENOTEMPTY: Directory not empty - ./dir", h[:result]
|
567
|
+
assert_equal '.', h[:result_path]
|
568
|
+
assert_equal 'dir', h[:result_file]
|
569
|
+
end
|
570
|
+
end
|
571
|
+
|
572
|
+
def test_delete_dir_not_empty_real
|
573
|
+
new_files(%w{ . .. dir })
|
574
|
+
class << @r
|
575
|
+
alias actual_delete actual_delete_orig
|
576
|
+
end
|
577
|
+
rr 1, :search => (/^dir$/), :action => :commit do |h|
|
578
|
+
assert_equal :fileerror, h[:result_type]
|
579
|
+
assert_equal "Errno::ENOTEMPTY: Directory not empty - ./dir", h[:result]
|
580
|
+
assert_equal '.', h[:result_path]
|
581
|
+
assert_equal 'dir', h[:result_file]
|
582
|
+
end
|
583
|
+
end
|
584
|
+
|
585
|
+
def test_delete_recursive
|
586
|
+
@files = Provider::File::Recursive.new(['.'])
|
587
|
+
add_file_events
|
588
|
+
class << @r
|
589
|
+
#alias actual_delete actual_delete_orig
|
590
|
+
end
|
591
|
+
c = %w{ ./dir/file1 ./dir/file2 ./dir/file3 ./dir }.to_cursor
|
592
|
+
rr 4, :search => (/^(dir|file[1-3])$/), :action => :commit do |h|
|
593
|
+
assert_equal :ok, h[:result_type]
|
594
|
+
p, f = File.split c.read1next
|
595
|
+
assert_equal p, h[:result_path]
|
596
|
+
assert_equal f, h[:result_file]
|
597
|
+
end
|
598
|
+
c.pos = 0
|
599
|
+
@r.renames.each do |a|
|
600
|
+
fn, r = a
|
601
|
+
assert_equal c.read1next, fn
|
602
|
+
assert_equal :deleted, r
|
603
|
+
end
|
604
|
+
end
|
605
|
+
end
|