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
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestFilesTxt < BaseTest
|
3
|
+
def rr(ey, o, &b)
|
4
|
+
r :preview, :rename_name_source, ey, o, &b
|
5
|
+
end
|
6
|
+
|
7
|
+
def t(s, items, results)
|
8
|
+
rr 3, :search => s,
|
9
|
+
:source => NameStreamSource.new(StringIO.new(items.join("\n"))) do |h|
|
10
|
+
assert_equal results.read1next, h[:newfn]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_nocap
|
15
|
+
items = %w{ the_first the_second the_third }
|
16
|
+
results = items.to_cursor
|
17
|
+
t(/.*/, items, results)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_cap
|
21
|
+
items = %w{ the_first the_second the_third }
|
22
|
+
results = %w{ filethe_first1 filethe_second2 filethe_third3 }.to_cursor
|
23
|
+
t(/file()/, items, results)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_not_enough
|
27
|
+
items = %w{ the_first the_second }
|
28
|
+
results = ['filethe_first1', 'filethe_second2', 'file--no data--3'].to_cursor
|
29
|
+
assert_raise(EOFError) {
|
30
|
+
t(/file()/, items, results)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_too_many
|
35
|
+
items = %w{ the_first the_second the_third the_extra }
|
36
|
+
results = %w{ filethe_first1 filethe_second2 filethe_third3 nevergethere }.to_cursor
|
37
|
+
t(/file()/, items, results)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_real_file
|
41
|
+
c = %w{ data1 data2 data3 }.to_cursor
|
42
|
+
File.open('dir/datafile', 'w') do |f|
|
43
|
+
3.times { f.puts c.read1next }
|
44
|
+
end
|
45
|
+
c.pos = 0
|
46
|
+
fs = NameFileSource.new('datafile')
|
47
|
+
begin
|
48
|
+
rr 3, :search => (/.*/), :source => fs do |h|
|
49
|
+
assert_equal c.read1next, h[:newfn]
|
50
|
+
assert_equal :ok, h[:result_type]
|
51
|
+
end
|
52
|
+
ensure
|
53
|
+
fs.close
|
54
|
+
File.delete('dir/datafile')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_real_file_recursive
|
59
|
+
begin
|
60
|
+
c = %w{ data1 data2 data3 data4 data5 data6 }.to_cursor
|
61
|
+
res = %w{ data4 data5 data6 data1 data2 data3 }.to_cursor
|
62
|
+
File.open('dir/datafile', 'w') do |f|
|
63
|
+
3.times { f.puts c.read1next }
|
64
|
+
end
|
65
|
+
Dir.mkdir 'dir/dir2'
|
66
|
+
File.open('dir/dir2/datafile', 'w') do |f|
|
67
|
+
3.times do |x|
|
68
|
+
File.open("dir/dir2/file#{x}", 'w') {|ff| ff.puts 'file' }
|
69
|
+
f.puts c.read1next
|
70
|
+
end
|
71
|
+
end
|
72
|
+
fs = NameFileSource.new('datafile')
|
73
|
+
@files = Provider::File::Recursive.new(['./dir'])
|
74
|
+
add_file_events
|
75
|
+
rr 6, :search => (/file./), :source => fs,
|
76
|
+
:filter => Filter.new(/\.svn/) do |h|
|
77
|
+
assert_equal res.read1next, h[:newfn]
|
78
|
+
assert_equal :ok, h[:result_type]
|
79
|
+
end
|
80
|
+
ensure
|
81
|
+
fs.close if fs
|
82
|
+
3.times {|x| File.delete "dir/dir2/file#{x}" }
|
83
|
+
File.delete 'dir/dir2/datafile'
|
84
|
+
Dir.rmdir 'dir/dir2'
|
85
|
+
File.delete 'dir/datafile'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
data/tests/test_fill.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestFill < BaseTest
|
3
|
+
def t(re, f, res = nil)
|
4
|
+
new_files(%w{ first1.1 section1.2 section1.3
|
5
|
+
second2.1 third3.5 hello section3.6
|
6
|
+
fourth4.1 section4.2 })
|
7
|
+
results = res || (%w{ first1.1 first1.2 first1.3
|
8
|
+
second2.1 third3.5 third3.6
|
9
|
+
fourth4.1 fourth4.2 }).to_cursor
|
10
|
+
r :preview, :rename_fill, 9, :search => re, :fill => f do |h|
|
11
|
+
if h[:newfn]
|
12
|
+
assert_equal results.read1next, h[:newfn]
|
13
|
+
elsif h[:result] == '* No capture to fill * hello'
|
14
|
+
# ok...
|
15
|
+
else
|
16
|
+
assert_equal 'source: ' + results.read1next, h[:result]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_cap_nocap
|
22
|
+
t(/(.*?)\d/, /section/)
|
23
|
+
end
|
24
|
+
def test_nocap_nocap
|
25
|
+
t(/first|second|third|fourth/, /section/)
|
26
|
+
end
|
27
|
+
def test_cap_cap
|
28
|
+
t(/(.*?)\d/, /(section)/)
|
29
|
+
end
|
30
|
+
def test_cap_cap2
|
31
|
+
t(/(.*?)\d/, /section()/, %w{ first1.1 sectionfirst1.2 sectionfirst1.3
|
32
|
+
second2.1 third3.5 sectionthird3.6
|
33
|
+
fourth4.1 sectionfourth4.2 }.to_cursor)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestFilter < BaseTest
|
3
|
+
def rr(expected_yields = nil, options = {}, &b)
|
4
|
+
r :preview, :rename_replace, expected_yields, options, &b
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_filter
|
8
|
+
rr 2, :search => (/(.*)\d/), :replace => 'new', :filter => Filter.new(/2/) do |h|
|
9
|
+
assert_match(/new[13]/, h[:newfn])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_filter2
|
14
|
+
rr(5, :search => (/(.*)\d/), :replace => 'new', :filter => Filter.new(/2/),
|
15
|
+
:verbose => true) do |h|
|
16
|
+
if h[:newfn]
|
17
|
+
assert_match(/new[13]/, h[:newfn])
|
18
|
+
else
|
19
|
+
assert_match(/filtered: (\.\.?|file2)/, h[:result])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_filter3
|
25
|
+
rr(5, :search => (/(.*)\d/), :replace => 'new', :filter => FilterNonMatches.new(/2/),
|
26
|
+
:verbose => true) do |h|
|
27
|
+
if h[:newfn]
|
28
|
+
assert_equal 'new2' , h[:newfn]
|
29
|
+
else
|
30
|
+
assert_match(/filtered: (\.\.?|file[13])/, h[:result])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestFullName < BaseTest
|
3
|
+
def rr(ey = nil, o = {}, &b)
|
4
|
+
r :preview, :rename_from_full_name, ey, o, &b
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_no_cap
|
8
|
+
rr 3, :search => (/file/), :pattern => (/dir/) do |h|
|
9
|
+
assert_match(/dir[1-3]/, h[:newfn], h[:result])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_cap
|
14
|
+
rr 3, :search => (/(file)/), :pattern => (/(dir)/) do |h|
|
15
|
+
assert_match(/dir[1-3]/, h[:newfn])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
data/tests/test_glob.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
|
3
|
+
class TestGlob < BaseTest
|
4
|
+
def test_glob
|
5
|
+
g = Provider::File::Glob.new(['frog', 'dir/*3', 'flooz'])
|
6
|
+
g.each do |path, file|
|
7
|
+
assert_equal 'dir', path
|
8
|
+
assert_equal 'file3', file
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestMarkChange < BaseTest
|
3
|
+
def rr(ey, o, &b)
|
4
|
+
r :preview, :rename_mark_change, ey, o, &b
|
5
|
+
end
|
6
|
+
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
@changes = %w{ SECTION1.1 SECTION2.1
|
10
|
+
SECTION3.5 SECTION4.1 }.to_cursor
|
11
|
+
new_files(%w{ section1.1
|
12
|
+
section1.2 section1.3
|
13
|
+
section2.1 section3.5 hello section3.6
|
14
|
+
section4.1 section4.2 })
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_changes
|
18
|
+
rr 4, :search => (/section(\d)\./), :replace_pattern => (/section/),
|
19
|
+
:replace_text => 'SECTION' do |h|
|
20
|
+
if h[:newfn]
|
21
|
+
assert_equal @changes.read1next, h[:newfn]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_changes_rcap
|
27
|
+
rr 4, :search => (/section(\d)\./), :replace_pattern => (/(\w*)\d\./),
|
28
|
+
:replace_text => 'SECTION' do |h|
|
29
|
+
if h[:newfn]
|
30
|
+
assert_equal @changes.read1next, h[:newfn]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_changes_rcap_other
|
36
|
+
rr 4, :search => (/section(\d)\./), :replace_pattern => (/()()()(\w*)\d\./),
|
37
|
+
:replace_text => 'SECTION',
|
38
|
+
:capture_num => 4 do |h|
|
39
|
+
if h[:newfn]
|
40
|
+
assert_equal @changes.read1next, h[:newfn]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_changes_no_cap
|
46
|
+
rr 4, :search => (/\d/), :replace_pattern => (/section/),
|
47
|
+
:replace_text => 'SECTION' do |h|
|
48
|
+
if h[:newfn]
|
49
|
+
assert_equal @changes.read1next, h[:newfn]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestMoveUp < BaseTest
|
3
|
+
def rr(ey = nil, o = {}, &b)
|
4
|
+
r :preview, :rename_move_up, ey, o, &b
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_match
|
8
|
+
rr 3, :search => (/./) do |h|
|
9
|
+
assert_match(%r{^\./file[1-3]$}, h[:newfn], h[:result])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_no_match
|
14
|
+
rr 0, :search => (/nothing/)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestReplace < BaseTest
|
3
|
+
def rr(expected_yields = nil, options = {}, &b)
|
4
|
+
r :preview, :rename_replace, expected_yields, options, &b
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_replace
|
8
|
+
rr 0, :search => (/none/)
|
9
|
+
rr 1, :search => (/1/), :replace => '9' do |h|
|
10
|
+
assert_equal 'file9', h[:result]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_replace_commit
|
15
|
+
r :commit, :rename_replace, 3, :search => (/file/), :replace => 'boob' do |h|
|
16
|
+
assert_match(/boob[1-3]/, h[:result])
|
17
|
+
end
|
18
|
+
assert_equal [["dir/file1", "dir/boob1"],
|
19
|
+
["dir/file2", "dir/boob2"],
|
20
|
+
["dir/file3", "dir/boob3"]], @r.renames
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_replace_cap
|
24
|
+
rr 3, :search => (/(f)ile/), :replace => 'sm' do |h|
|
25
|
+
assert_match(/smile[1-3]/, h[:result])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_replace_caps
|
30
|
+
rr 3, :search => (/((f)(i)(l)(e)(\d))/),
|
31
|
+
:replace => '->%6%5%4%3%2<-' do |h|
|
32
|
+
assert_match(/->[1-3]elif<-/, h[:result])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_replace_other_cap
|
37
|
+
rr 3, :search => (/((f)(i)(l)(e)(\d))/),
|
38
|
+
:replace => '%6%5%4%3%2',
|
39
|
+
:capture_num => 2 do |h|
|
40
|
+
assert_match(/[1-3]elifile[1-3]/, h[:result])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
data/tests/test_roman.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestRoman < BaseTest
|
3
|
+
def rr(ey, o, &b)
|
4
|
+
r :preview, :rename_roman, ey, o, &b
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_to_roman
|
8
|
+
count = 0
|
9
|
+
rr 3, :search => (/(\d)/) do |h|
|
10
|
+
count += 1
|
11
|
+
rn = 'file' + case count
|
12
|
+
when 1; 'I'
|
13
|
+
when 2; 'II'
|
14
|
+
when 3; 'III'
|
15
|
+
end
|
16
|
+
assert_equal rn, h[:newfn]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_from_roman
|
21
|
+
new_files ['glory/great war of mcmxiv']
|
22
|
+
rr 1, :search => (/of (roman)/i) do |h|
|
23
|
+
assert_equal 'great war of 1914', h[:result]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestTapeNumbers < BaseTest
|
3
|
+
def t(r)
|
4
|
+
results = %w{ tape1 tape2 tape3 tape4}.to_cursor
|
5
|
+
new_files(%w{ tape1A tape1B tape2a tape2b })
|
6
|
+
r(:preview, :rename_tape_numbers, 4, :search => r) do |h|
|
7
|
+
assert_equal results.read1next, h[:newfn]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_cap
|
12
|
+
t(/tape(..)/)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_no_cap
|
16
|
+
t(/\d./)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.split(__FILE__).first + "/../lib/test/test_helper"
|
2
|
+
class TestUpcase < BaseTest
|
3
|
+
def rr(ey, o, &b)
|
4
|
+
r :preview, :rename_upcase, ey, o, &b
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_upcase
|
8
|
+
c = %w{ File1 File2 File3 }.to_cursor
|
9
|
+
rr 3, :search => (/./) do |h|
|
10
|
+
assert_equal(c.read1next, h[:newfn])
|
11
|
+
assert_equal(:ok, h[:result_type])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_upcase_entire
|
16
|
+
c = %w{ FILE1 FILE2 FILE3 }.to_cursor
|
17
|
+
rr 3, :search => (/(.*)/) do |h|
|
18
|
+
assert_equal(c.read1next, h[:newfn])
|
19
|
+
assert_equal(:ok, h[:result_type])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rfs
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "0.
|
7
|
-
date: 2005-09-
|
6
|
+
version: "0.3"
|
7
|
+
date: 2005-09-13 00:00:00 -04:00
|
8
8
|
summary: A utility that allows you to use regular expressions to rename large sets of files or folders. Fxruby and cmd-line interfaces.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,6 +30,7 @@ authors:
|
|
30
30
|
- Darrick Wiebe
|
31
31
|
files:
|
32
32
|
- "./bin"
|
33
|
+
- "./CHANGELOG"
|
33
34
|
- "./description.txt"
|
34
35
|
- "./lib"
|
35
36
|
- "./MIT-LICENSE"
|
@@ -88,13 +89,31 @@ files:
|
|
88
89
|
- "./lib/innate/test/files/reloadtarget1.rb"
|
89
90
|
- "./lib/innate/test/files/reloadtarget2.rb"
|
90
91
|
- "./lib/test/test_helper.rb"
|
92
|
+
- "./tests/all_tests.rb"
|
91
93
|
- "./tests/dir"
|
92
|
-
- "./tests/
|
94
|
+
- "./tests/test_add.rb"
|
95
|
+
- "./tests/test_basics.rb"
|
96
|
+
- "./tests/test_capitalize.rb"
|
97
|
+
- "./tests/test_confirm.rb"
|
98
|
+
- "./tests/test_count.rb"
|
99
|
+
- "./tests/test_delete.rb"
|
100
|
+
- "./tests/test_downcase.rb"
|
101
|
+
- "./tests/test_files_txt.rb"
|
102
|
+
- "./tests/test_fill.rb"
|
103
|
+
- "./tests/test_filter.rb"
|
104
|
+
- "./tests/test_full_name.rb"
|
105
|
+
- "./tests/test_glob.rb"
|
106
|
+
- "./tests/test_mark_change.rb"
|
107
|
+
- "./tests/test_move_up.rb"
|
108
|
+
- "./tests/test_replace.rb"
|
109
|
+
- "./tests/test_roman.rb"
|
110
|
+
- "./tests/test_tape_numbers.rb"
|
111
|
+
- "./tests/test_upcase.rb"
|
93
112
|
- "./tests/dir/file1"
|
94
113
|
- "./tests/dir/file2"
|
95
114
|
- "./tests/dir/file3"
|
96
115
|
test_files:
|
97
|
-
- "./tests/
|
116
|
+
- "./tests/all_tests.rb"
|
98
117
|
- "./lib/innate/test/all_tests.rb"
|
99
118
|
rdoc_options: []
|
100
119
|
extra_rdoc_files: []
|