rfs 0.2 → 0.3
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/CHANGELOG +51 -0
- data/Rakefile.rb +4 -4
- data/bin/rfs.rb +35 -4
- data/lib/innate/array.rb +1 -0
- data/lib/innate/test/all_tests.rb +2 -0
- data/lib/providers.rb +45 -55
- data/lib/rename_functions.rb +12 -0
- data/lib/renamer.rb +9 -9
- data/lib/results.rb +29 -24
- data/lib/test/test_helper.rb +6 -1
- data/tests/all_tests.rb +3 -0
- data/tests/test_add.rb +45 -0
- data/tests/test_basics.rb +67 -0
- data/tests/test_capitalize.rb +24 -0
- data/tests/test_confirm.rb +145 -0
- data/tests/test_count.rb +20 -0
- data/tests/test_delete.rb +106 -0
- data/tests/test_downcase.rb +35 -0
- data/tests/test_files_txt.rb +90 -0
- data/tests/test_fill.rb +37 -0
- data/tests/test_filter.rb +36 -0
- data/tests/test_full_name.rb +20 -0
- data/tests/test_glob.rb +11 -0
- data/tests/test_mark_change.rb +55 -0
- data/tests/test_move_up.rb +18 -0
- data/tests/test_replace.rb +45 -0
- data/tests/test_roman.rb +28 -0
- data/tests/test_tape_numbers.rb +20 -0
- data/tests/test_upcase.rb +24 -0
- metadata +23 -4
- data/tests/test_rename_functions.rb +0 -613
data/tests/all_tests.rb
ADDED
data/tests/test_add.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
|
3
|
+
class TestAdd < BaseTest
|
4
|
+
def rr(ey = nil, o = {}, &b)
|
5
|
+
r :preview, :rename_add, ey, o, &b
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_add
|
9
|
+
rr 3, :search => (/\d/), :add => 5, :action => :commit do |h|
|
10
|
+
assert_equal h[:oldfn].succ.succ.succ.succ.succ, h[:newfn]
|
11
|
+
end
|
12
|
+
#make sure it went in reverse
|
13
|
+
assert_equal [['dir/file3', 'dir/file8'],
|
14
|
+
['dir/file2', 'dir/file7'],
|
15
|
+
['dir/file1', 'dir/file6']], @r.renames
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_add_neg
|
19
|
+
c = %w{ file-2 file-1 file0 }.to_cursor
|
20
|
+
rr 3, :search => (/\d/), :add => -3, :action => :commit do |h|
|
21
|
+
assert_equal c.read1next, h[:newfn]
|
22
|
+
end
|
23
|
+
#make sure it went in reverse
|
24
|
+
assert_equal [['dir/file1', 'dir/file-2'],
|
25
|
+
['dir/file2', 'dir/file-1'],
|
26
|
+
['dir/file3', 'dir/file0']], @r.renames
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_add_cap
|
30
|
+
rr 3, :search => (/(\d)/), :add => 5 do |h|
|
31
|
+
assert_equal h[:oldfn].succ.succ.succ.succ.succ, h[:newfn]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_missing_add
|
36
|
+
assert_raise MissingOptionError do
|
37
|
+
rr(3, :search => (/(\d)/)) { |h| fail "shouldn't get here" }
|
38
|
+
end
|
39
|
+
assert_raise BadOptionValueError do
|
40
|
+
rr(3, :search => (/(\d)/), :add => 'something') { |h| fail "shouldn't get here" }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestBasics < BaseTest
|
3
|
+
def test_list
|
4
|
+
r :list, :rename_replace, 5, :test_r_nofilter => true do |h|
|
5
|
+
if ['.', '..'].include? @file
|
6
|
+
assert_equal @file + '/', h[:result]
|
7
|
+
else
|
8
|
+
assert_equal @file, h[:result]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_wrong_iterations
|
14
|
+
assert_raise(RuntimeError) {
|
15
|
+
r :list, :rename_replace, 1000, :test_r_count => true do |h|
|
16
|
+
if ['.', '..'].include? @file
|
17
|
+
assert_equal @file + '/', h[:result]
|
18
|
+
else
|
19
|
+
assert_equal @file, h[:result]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_bad_action
|
26
|
+
assert_raise(ActionError) {
|
27
|
+
r :no, :rename_replace
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_bad_method
|
32
|
+
assert_raise(NameError) {
|
33
|
+
r :preview, :foo_bar
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_missing_option
|
38
|
+
assert_raise(MissingOptionError) {
|
39
|
+
r :preview, :rename_replace
|
40
|
+
}
|
41
|
+
end
|
42
|
+
def test_missing_option1
|
43
|
+
# this doesn't raise MissingOptionError because the error is caught and given as result feedback
|
44
|
+
r :preview, :rename_replace, 3, :search => /file/ do |h|
|
45
|
+
assert_match(/MissingOptionError/, h[:result])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
def test_missing_option2
|
49
|
+
assert_raise(MissingOptionError) {
|
50
|
+
r :preview, :rename_replace, nil, :replace => 'good'
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_bad_search
|
55
|
+
assert_raise(BadOptionValueError) {
|
56
|
+
r :preview, :rename_replace, nil, :search => 3
|
57
|
+
}
|
58
|
+
end
|
59
|
+
def test_bad_search1
|
60
|
+
# this doesn't raise BadOptionValueError because the error is caught and given as result feedback
|
61
|
+
r :preview, :rename_replace, 3, :search => /file/, :replace => /aeu/ do |h|
|
62
|
+
assert_match(/BadOptionValueError/, h[:result])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestCapitalize < BaseTest
|
3
|
+
def rr(ey, o, &b)
|
4
|
+
new_files(
|
5
|
+
['this sentence should be capitalized',
|
6
|
+
'here is another one. the best is to see what will happen! is it good?',
|
7
|
+
'how many more do i need here? a few.',
|
8
|
+
"i'll have to get this done soon, it may get boring..."])
|
9
|
+
r :preview, :rename_capitalize, ey, o, &b
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_capitalize
|
13
|
+
changes = ['This Sentence Should Be Capitalized',
|
14
|
+
'Here is Another One. The Best is to See What Will Happen! Is it Good?',
|
15
|
+
'How Many More Do I Need Here? A Few.',
|
16
|
+
"I'll Have to Get This Done Soon, it May Get Boring..."].to_cursor
|
17
|
+
rr 4, :search => (/.*/) do |h|
|
18
|
+
assert_equal changes.read1next, h[:newfn]
|
19
|
+
assert_equal(:ok, h[:result_type])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestConfirm < BaseTest
|
3
|
+
def rr(expected_yields = nil, options = {}, &b)
|
4
|
+
r :commit, :rename_replace, expected_yields, options, &b
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_confirm_yes
|
8
|
+
confirms = 0
|
9
|
+
rr 3, :confirm => (proc {|path, oldfn, newfn, full_name, exists, default|
|
10
|
+
confirms += 1
|
11
|
+
assert_equal 'dir', path
|
12
|
+
assert_match(/file[1-3]/, oldfn)
|
13
|
+
assert_match(/new[1-3]/, newfn)
|
14
|
+
assert_equal false, full_name
|
15
|
+
assert_equal((oldfn[-1] == ?1) ? :yes : :yes, default)
|
16
|
+
:yes
|
17
|
+
}),
|
18
|
+
:search => (/file/), :replace => 'new' do |h|
|
19
|
+
assert_match(/new[123]/, h[:newfn])
|
20
|
+
assert_equal :ok, h[:result_type]
|
21
|
+
assert_equal h[:newfn], h[:result]
|
22
|
+
assert_equal h[:confirm], :yes
|
23
|
+
end
|
24
|
+
assert_equal 3, confirms
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_confirm_all
|
28
|
+
confirms = 0
|
29
|
+
rr 3, :confirm => (proc {|path, oldfn, newfn, full_name, exists, default|
|
30
|
+
confirms += 1
|
31
|
+
assert_equal :yes, default
|
32
|
+
:all
|
33
|
+
}),
|
34
|
+
:search => (/file/), :replace => 'new' do |h|
|
35
|
+
assert_match(/new[123]/, h[:newfn])
|
36
|
+
assert_equal :ok, h[:result_type]
|
37
|
+
assert_equal h[:newfn], h[:result]
|
38
|
+
assert_equal h[:confirm], :all
|
39
|
+
end
|
40
|
+
assert_equal 1, confirms
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_confirm_no
|
44
|
+
confirms = 0
|
45
|
+
rr 3, :confirm => (proc {|path, oldfn, newfn, full_name, exists, default|
|
46
|
+
confirms += 1
|
47
|
+
assert_equal((oldfn[-1] == ?1) ? :yes : :no, default)
|
48
|
+
:no
|
49
|
+
}),
|
50
|
+
:search => (/file/), :replace => 'new' do |h|
|
51
|
+
assert_match(/new[123]/, h[:newfn])
|
52
|
+
assert_equal :skipped, h[:result_type]
|
53
|
+
assert_equal h[:oldfn], h[:result]
|
54
|
+
assert_equal h[:confirm], :no
|
55
|
+
end
|
56
|
+
assert_equal 3, confirms
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_confirm_cancel
|
60
|
+
confirms = 0
|
61
|
+
rr 0, :confirm => (proc {|path, oldfn, newfn, full_name, exists, default|
|
62
|
+
confirms += 1
|
63
|
+
assert_equal :yes, default
|
64
|
+
:cancel
|
65
|
+
}),
|
66
|
+
:search => (/file/), :replace => 'new' do |h|
|
67
|
+
fail
|
68
|
+
end
|
69
|
+
assert_equal 1, confirms
|
70
|
+
end
|
71
|
+
|
72
|
+
def exists_test(files, expect, p, s)
|
73
|
+
confirms = 0
|
74
|
+
new_files(files)
|
75
|
+
cp = proc do |path, oldfn, newfn, full_name, exists, default|
|
76
|
+
confirms += 1
|
77
|
+
assert_equal expect, exists
|
78
|
+
:no
|
79
|
+
end
|
80
|
+
|
81
|
+
#class << @r
|
82
|
+
#alias a_e_test already_exists?
|
83
|
+
#def already_exists?(*a)
|
84
|
+
#r = a_e_test(*a)
|
85
|
+
#assert_equal expect, r
|
86
|
+
#end
|
87
|
+
#end
|
88
|
+
rr 3, :confirm => cp, :search => p, :replace => s do |h|
|
89
|
+
# fail
|
90
|
+
end
|
91
|
+
assert_equal 3, confirms
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_exists_same
|
95
|
+
confirms = 0
|
96
|
+
new_files(%w{ ./dir/FILE1 ./dir/FILE2 ./dir/FILE3 })
|
97
|
+
cp = proc do |path, oldfn, newfn, full_name, exists, default|
|
98
|
+
confirms += 1
|
99
|
+
assert_equal nil, exists
|
100
|
+
:no
|
101
|
+
end
|
102
|
+
class << @r
|
103
|
+
alias a_e_test already_exists?
|
104
|
+
def already_exists?(*a)
|
105
|
+
r = a_e_test(*a)
|
106
|
+
raise "false expected but was <#{r}>" unless false == r
|
107
|
+
r
|
108
|
+
end
|
109
|
+
end
|
110
|
+
rr 3, :confirm => cp, :search => (/FILE/), :replace => 'file' do |h|
|
111
|
+
assert_equal :skipped, h[:result_type]
|
112
|
+
end
|
113
|
+
assert_equal 3, confirms
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_exists_diff
|
117
|
+
new_files(%w{ ./dir/FILES1 ./dir/FILES2 ./dir/FILES3 })
|
118
|
+
confirms = 0
|
119
|
+
cp = proc do |path, oldfn, newfn, full_name, exists, default|
|
120
|
+
confirms += 1
|
121
|
+
assert_equal true, exists
|
122
|
+
:no
|
123
|
+
end
|
124
|
+
class << @r
|
125
|
+
alias a_e_test already_exists?
|
126
|
+
def already_exists?(*a)
|
127
|
+
r = a_e_test(*a)
|
128
|
+
raise "true expected but was <#{r}>" unless true == r
|
129
|
+
r
|
130
|
+
end
|
131
|
+
end
|
132
|
+
rr 3, :confirm => cp, :search => (/FILES/), :replace => 'file', :force => true do |h|
|
133
|
+
assert_equal :skipped, h[:result_type]
|
134
|
+
end
|
135
|
+
assert_equal 3, confirms
|
136
|
+
|
137
|
+
confirms = 0
|
138
|
+
rr 3, :confirm => cp, :search => (/FILES/), :replace => 'file' do |h|
|
139
|
+
assert_equal :fileerror, h[:result_type]
|
140
|
+
end
|
141
|
+
assert_equal 0, confirms
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
|
data/tests/test_count.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestCount < BaseTest
|
3
|
+
def test_count
|
4
|
+
count = 0
|
5
|
+
r :preview, :rename_count, 3, :search => (/()./), :count_start => 1 do |h|
|
6
|
+
count += 1
|
7
|
+
assert_equal "#{count}#{h[:oldfn]}", h[:newfn]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_count_string
|
12
|
+
count = "b.9 "
|
13
|
+
r :preview, :rename_count, 3, :search => (/()./), :count_start => count do |h|
|
14
|
+
assert_equal "#{count}#{h[:oldfn]}", h[:newfn]
|
15
|
+
count.succ!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestDelete < BaseTest
|
3
|
+
def teardown
|
4
|
+
super
|
5
|
+
unless File.exists? 'dir'
|
6
|
+
Dir.mkdir 'dir'
|
7
|
+
end
|
8
|
+
%w{file1 file2 file3}.each do |f|
|
9
|
+
fn = File.join('dir', f)
|
10
|
+
unless File.exists? fn
|
11
|
+
File.open(fn, 'w') {|f| f.puts fn }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def rr(expected_yields = nil, options = {}, &b)
|
17
|
+
r :preview, :rename_remove, expected_yields, options, &b
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_delete_file
|
21
|
+
rr 1, :search => (/^file2$/), :action => :commit do |h|
|
22
|
+
assert_equal [["dir/file2", :deleted]], @r.renames
|
23
|
+
assert_equal :ok, h[:result_type]
|
24
|
+
assert_equal '<<file2>>', h[:result]
|
25
|
+
assert_equal 'dir', h[:result_path]
|
26
|
+
assert_equal 'file2', h[:result_file]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_delete_dir_not_empty_sim
|
31
|
+
new_files(%w{ . .. dir })
|
32
|
+
rr 1, :search => (/^dir$/), :action => :commit do |h|
|
33
|
+
assert_equal [["./dir", :deleted]], @r.renames
|
34
|
+
assert_equal :ok, h[:result_type]
|
35
|
+
assert_equal '<<dir>>', h[:result]
|
36
|
+
assert_equal '.', h[:result_path]
|
37
|
+
assert_equal 'dir', h[:result_file]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_delete_dir_not_empty_real
|
42
|
+
new_files(%w{ . .. dir })
|
43
|
+
class << @r
|
44
|
+
alias actual_delete actual_delete_orig
|
45
|
+
end
|
46
|
+
rr 1, :search => (/^dir$/), :action => :commit do |h|
|
47
|
+
assert_equal :fileerror, h[:result_type]
|
48
|
+
assert_equal "Errno::ENOTEMPTY: Directory not empty - ./dir", h[:result]
|
49
|
+
assert_equal '.', h[:result_path]
|
50
|
+
assert_equal 'dir', h[:result_file]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_delete_dir_not_empty_real
|
55
|
+
new_files(%w{ . .. dir })
|
56
|
+
class << @r
|
57
|
+
alias actual_delete actual_delete_orig
|
58
|
+
end
|
59
|
+
rr 1, :search => (/^dir$/), :action => :commit do |h|
|
60
|
+
assert_equal :fileerror, h[:result_type]
|
61
|
+
assert_equal "Errno::ENOTEMPTY: Directory not empty - ./dir", h[:result]
|
62
|
+
assert_equal '.', h[:result_path]
|
63
|
+
assert_equal 'dir', h[:result_file]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_delete_recursive
|
68
|
+
@files = Provider::File::Recursive.new(['.'])
|
69
|
+
add_file_events
|
70
|
+
class << @r
|
71
|
+
#alias actual_delete actual_delete_orig
|
72
|
+
end
|
73
|
+
c = %w{ ./dir/file1 ./dir/file2 ./dir/file3 ./dir }.to_cursor
|
74
|
+
rr 4, :search => (/^(dir|file[1-3])$/), :action => :commit do |h|
|
75
|
+
assert_equal :ok, h[:result_type]
|
76
|
+
p, f = File.split c.read1next
|
77
|
+
assert_equal p, h[:result_path]
|
78
|
+
assert_equal f, h[:result_file]
|
79
|
+
end
|
80
|
+
c.pos = 0
|
81
|
+
@r.renames.each do |a|
|
82
|
+
fn, r = a
|
83
|
+
assert_equal c.read1next, fn
|
84
|
+
assert_equal :deleted, r
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_confirm_delete
|
89
|
+
confirms = 0
|
90
|
+
cp = proc do |path, oldfn, newfn, full_name, exists, default|
|
91
|
+
assert_equal 'dir', path
|
92
|
+
assert_match(/file[1-3]/, oldfn)
|
93
|
+
assert_equal '<<deleted>>', newfn
|
94
|
+
assert_equal false, full_name
|
95
|
+
assert_equal nil, exists
|
96
|
+
confirms += 1
|
97
|
+
:no
|
98
|
+
end
|
99
|
+
rr 3, :search => (/./), :confirm => cp, :action => :commit do |h|
|
100
|
+
assert_equal :skipped, h[:result_type]
|
101
|
+
end
|
102
|
+
assert_equal 3, confirms
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestDowncase < BaseTest
|
3
|
+
def setup
|
4
|
+
super
|
5
|
+
new_files(%w{ FILE1 FILE2 FILE3 })
|
6
|
+
end
|
7
|
+
|
8
|
+
def rr(ey, o, &b)
|
9
|
+
r :preview, :rename_downcase, ey, o, &b
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_downcase
|
13
|
+
c = %w{ File1 File2 File3 }.to_cursor
|
14
|
+
rr 3, :search => (/ILE/) do |h|
|
15
|
+
assert_equal(c.read1next, h[:newfn])
|
16
|
+
assert_equal(:ok, h[:result_type])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_upcase_entire
|
21
|
+
c = %w{ file1 file2 file3 }.to_cursor
|
22
|
+
rr 3, :search => (/(.*)/) do |h|
|
23
|
+
assert_equal(c.read1next, h[:newfn])
|
24
|
+
assert_equal(:ok, h[:result_type])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_no_change
|
29
|
+
new_files(%w{ file1 file2 file3 })
|
30
|
+
rr 3, :search => (/(.*)/) do |h|
|
31
|
+
assert_nil(h[:result_type])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|