patman 0.0.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.
- checksums.yaml +7 -0
- data/CHANGELOG.rdoc +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +14 -0
- data/doc/Patman/PatmanError.html +138 -0
- data/doc/Patman/PatmanFileError.html +142 -0
- data/doc/Patman/PatmanSearchError.html +142 -0
- data/doc/Patman.html +3313 -0
- data/doc/_index.html +134 -0
- data/doc/class_list.html +58 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +339 -0
- data/doc/file.CHANGELOG.html +79 -0
- data/doc/file.README.html +87 -0
- data/doc/file_list.html +63 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +87 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +181 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +309 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/patman.rb +525 -0
- data/lib/version.rb +6 -0
- data/test/input/test_file1.txt +10 -0
- data/test/test_patman.rb +175 -0
- metadata +72 -0
data/test/test_patman.rb
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'patman'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
# require 'byebug'
|
6
|
+
|
7
|
+
|
8
|
+
class PatmanTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
# Test all editing features.
|
11
|
+
def test_editing
|
12
|
+
|
13
|
+
ifile = 'test/input/test_file1.txt'
|
14
|
+
|
15
|
+
# Open file.
|
16
|
+
r = Patman.read( ifile )
|
17
|
+
|
18
|
+
# Should be at file beginning.
|
19
|
+
assert_equal( r.line, 1 )
|
20
|
+
assert_equal( r.edited?, false )
|
21
|
+
|
22
|
+
# ------------------------------------------------------------
|
23
|
+
# Test diff jumping commands and their return values:
|
24
|
+
r.step; assert_equal( r.line, 2 )
|
25
|
+
r.step -1; assert_equal( r.line, 1 )
|
26
|
+
true; assert_equal( r.step.line, 2 )
|
27
|
+
true; assert_equal( r.step(-1).line, 1 )
|
28
|
+
r.line( 5 ); assert_equal( r.line, 5 )
|
29
|
+
r.firstline; assert_equal( r.line, 1 )
|
30
|
+
r.lastline; assert_equal( r.line, 10 )
|
31
|
+
|
32
|
+
|
33
|
+
# ------------------------------------------------------------
|
34
|
+
# Test searching:
|
35
|
+
assert_equal( r.firstline.find( /Line 1/ ), true )
|
36
|
+
assert_equal( r.firstline.find( /Line 2/ ), true )
|
37
|
+
assert_equal( r.line( 4 ).find( /Line 3/ ), false )
|
38
|
+
assert_equal( r.firstline.search( /Line 1/ ).line, 1 )
|
39
|
+
assert_equal( r.search( /Line 2/ ).line, 2 )
|
40
|
+
assert_equal( r.search( /ne 8/ ).line, 8 )
|
41
|
+
l = r.excursion do
|
42
|
+
r.search( /Line 9/ ).line
|
43
|
+
end
|
44
|
+
assert_equal( r.line, 8 )
|
45
|
+
assert_equal( l, 9 )
|
46
|
+
|
47
|
+
err = false
|
48
|
+
begin
|
49
|
+
r.search( /Line 2/ )
|
50
|
+
rescue Patman::PatmanSearchError
|
51
|
+
err = true
|
52
|
+
end
|
53
|
+
assert_equal( err, true )
|
54
|
+
|
55
|
+
err = false
|
56
|
+
begin
|
57
|
+
r.search( /Line 2/, false )
|
58
|
+
rescue Patman::PatmanSearchError
|
59
|
+
err = true
|
60
|
+
end
|
61
|
+
assert_equal( err, false )
|
62
|
+
assert_equal( r.line, 2 )
|
63
|
+
|
64
|
+
err = false
|
65
|
+
begin
|
66
|
+
r.search( /Line 9/, false )
|
67
|
+
rescue Patman::PatmanSearchError
|
68
|
+
err = true
|
69
|
+
end
|
70
|
+
assert_equal( err, true )
|
71
|
+
assert_equal( r.line, 2 )
|
72
|
+
|
73
|
+
|
74
|
+
# ------------------------------------------------------------
|
75
|
+
# Test content queries:
|
76
|
+
assert_equal( r.firstline.get, "Line 1" )
|
77
|
+
assert_equal( r.ref( 10 ), "Line 10" )
|
78
|
+
assert_equal( r.ref( 11 ), nil )
|
79
|
+
assert_equal( r.line, 1 )
|
80
|
+
assert_equal( r.get_range( 1, 2 ), ["Line 1", "Line 2"] )
|
81
|
+
assert_equal( r.get_for( 1, 2 ), ["Line 1", "Line 2"] )
|
82
|
+
|
83
|
+
|
84
|
+
# ------------------------------------------------------------
|
85
|
+
# Test content manipulation:
|
86
|
+
l = r.get
|
87
|
+
r.set( "foobar" )
|
88
|
+
assert_equal( r.get, "foobar" )
|
89
|
+
r.set( l )
|
90
|
+
assert_equal( r.length, 10 )
|
91
|
+
|
92
|
+
r.update do |c|
|
93
|
+
c.gsub( /ne/, 'en' )
|
94
|
+
end
|
95
|
+
assert_equal( r.get, "Lien 1" )
|
96
|
+
r.set( l )
|
97
|
+
|
98
|
+
|
99
|
+
r.insert( 'Line -1' )
|
100
|
+
assert_equal( r.length, 11 )
|
101
|
+
assert_equal( r.get, "Line -1" )
|
102
|
+
r.delete
|
103
|
+
assert_equal( r.length, 10 )
|
104
|
+
assert_equal( r.get, "Line 1" )
|
105
|
+
|
106
|
+
c = %w{foo bar}
|
107
|
+
r.insert( c )
|
108
|
+
assert_equal( r.length, 12 )
|
109
|
+
assert_equal( r.get_range( 1, 2 ), c )
|
110
|
+
assert_equal( r.delete(2).length, 10 )
|
111
|
+
|
112
|
+
assert_equal( r.lastline.append( 'foo' ).get, 'foo' )
|
113
|
+
assert_equal( r.append( 'bar' ).get, 'bar' )
|
114
|
+
assert_equal( r.length, 12 )
|
115
|
+
assert_equal( r.get_range(11,12), c )
|
116
|
+
assert_equal( r.line, r.length )
|
117
|
+
assert_equal( r.append( %w{foo bar} ).length, 14 )
|
118
|
+
assert_equal( r.get_range(13,14), c )
|
119
|
+
r.line( 11 ).delete( 4 )
|
120
|
+
|
121
|
+
len = r.length
|
122
|
+
assert_equal( r.firstline.insertfile( ifile ).length, 2*len )
|
123
|
+
assert_equal( r.lastline.step.insertfile( ifile ).length, 3*len )
|
124
|
+
|
125
|
+
r.do_all do |r|
|
126
|
+
r.sub( /Line/, 'foobar' )
|
127
|
+
end
|
128
|
+
assert_equal( r.get_range(5,6), [ 'foobar 5', 'foobar 6' ] )
|
129
|
+
r.blockline
|
130
|
+
assert_equal( r.line, 30 )
|
131
|
+
|
132
|
+
r.do_range( 1, r.length-1 ) do |r|
|
133
|
+
r.sub( /foobar/, 'Line' )
|
134
|
+
end
|
135
|
+
assert_equal( r.get_range(5,6), [ 'Line 5', 'Line 6' ] )
|
136
|
+
|
137
|
+
r.do_for( 1, r.length-1 ) do |r|
|
138
|
+
r.sub( /Line/, 'foobar' )
|
139
|
+
end
|
140
|
+
assert_equal( r.get_range(5,6), [ 'foobar 5', 'foobar 6' ] )
|
141
|
+
|
142
|
+
|
143
|
+
# ------------------------------------------------------------
|
144
|
+
# Test misc commands:
|
145
|
+
r.clear
|
146
|
+
assert_equal( r.lines, [ ] )
|
147
|
+
assert_equal( r.edited?, true )
|
148
|
+
|
149
|
+
r.mark
|
150
|
+
r.step
|
151
|
+
assert_equal( r.line, 2 )
|
152
|
+
r.unmark
|
153
|
+
assert_equal( r.line, 1 )
|
154
|
+
|
155
|
+
|
156
|
+
# ------------------------------------------------------------
|
157
|
+
# Test file saving:
|
158
|
+
|
159
|
+
ofile = 'test/output/test_file1.txt'
|
160
|
+
r.copy( ofile )
|
161
|
+
|
162
|
+
r2 = Patman.read( ofile )
|
163
|
+
assert_equal( r.lines, r2.lines )
|
164
|
+
|
165
|
+
r3 = Patman.read( ifile )
|
166
|
+
r2.lines r3.lines
|
167
|
+
r2.write
|
168
|
+
|
169
|
+
assert( system( "diff #{ifile} #{ofile} " ) )
|
170
|
+
|
171
|
+
FileUtils.rm_f ofile
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: patman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tero Isannainen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Patman (Patch Manipulator) is a library for text file patching.
|
14
|
+
email: tero.isannainen@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files:
|
18
|
+
- README.rdoc
|
19
|
+
- CHANGELOG.rdoc
|
20
|
+
files:
|
21
|
+
- CHANGELOG.rdoc
|
22
|
+
- LICENSE
|
23
|
+
- README.rdoc
|
24
|
+
- doc/Patman.html
|
25
|
+
- doc/Patman/PatmanError.html
|
26
|
+
- doc/Patman/PatmanFileError.html
|
27
|
+
- doc/Patman/PatmanSearchError.html
|
28
|
+
- doc/_index.html
|
29
|
+
- doc/class_list.html
|
30
|
+
- doc/css/common.css
|
31
|
+
- doc/css/full_list.css
|
32
|
+
- doc/css/style.css
|
33
|
+
- doc/file.CHANGELOG.html
|
34
|
+
- doc/file.README.html
|
35
|
+
- doc/file_list.html
|
36
|
+
- doc/frames.html
|
37
|
+
- doc/index.html
|
38
|
+
- doc/js/app.js
|
39
|
+
- doc/js/full_list.js
|
40
|
+
- doc/js/jquery.js
|
41
|
+
- doc/method_list.html
|
42
|
+
- doc/top-level-namespace.html
|
43
|
+
- lib/patman.rb
|
44
|
+
- lib/version.rb
|
45
|
+
- test/input/test_file1.txt
|
46
|
+
- test/test_patman.rb
|
47
|
+
homepage:
|
48
|
+
licenses:
|
49
|
+
- Ruby
|
50
|
+
metadata: {}
|
51
|
+
post_install_message: Check README...
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.9.3
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.5.2.1
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Patman is used to patch text files.
|
71
|
+
test_files: []
|
72
|
+
has_rdoc:
|