rupat 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/version.rb ADDED
@@ -0,0 +1,6 @@
1
+ class Rupat
2
+ VERSION = "0.0.1"
3
+ def Rupat.version
4
+ Rupat::VERSION
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ foo
2
+ bar dii
3
+ duu
4
+ dapadaa
5
+ sii
6
+ duu
7
+ jaa guu
8
+ dapadii
9
+ per
10
+ saukko
@@ -0,0 +1,13 @@
1
+ foo
2
+ duu
3
+ sii
4
+ dapadaa
5
+ duu
6
+ jaa guu
7
+ sii
8
+ fii
9
+ fuu
10
+ daa
11
+ dapadii
12
+ jaska
13
+ aukko
@@ -0,0 +1,10 @@
1
+ Line 0
2
+ Line 1
3
+ Line 2
4
+ Line 3
5
+ Line 4
6
+ Line 5
7
+ Line 6
8
+ Line 7
9
+ Line 8
10
+ Line 9
@@ -0,0 +1,213 @@
1
+ require 'test/unit'
2
+ require 'rupat'
3
+ require 'fileutils'
4
+
5
+
6
+ class RupatTest < Test::Unit::TestCase
7
+
8
+ # Test all editing features.
9
+ def test_editing
10
+
11
+ test_file = 'test/input/test_file1.txt'
12
+
13
+ # Open file.
14
+ r = Rupat.update( test_file ).useAlias
15
+
16
+ # Should be at file beginning.
17
+ assert_equal( r.l, 0 )
18
+
19
+ # ------------------------------------------------------------
20
+ # Test diff jumping commands and their return values:
21
+ r.n; assert_equal( r.l, 1 )
22
+ r.p; assert_equal( r.l, 0 )
23
+ true; assert_equal( r.n.l, 1 )
24
+ true; assert_equal( r.p.l, 0 )
25
+ r.j( 5 ); assert_equal( r.l, 5 )
26
+ true; assert_equal( r.j.l, 0 )
27
+ r.j1( 11 ); assert_equal( r.l, 10 )
28
+ r.jl; assert_equal( r.l, 9 )
29
+ r.jl; assert_equal( r.l, 9 )
30
+ r.je; assert_equal( r.l, 10 )
31
+
32
+
33
+ # ------------------------------------------------------------
34
+ # Test invalid lines:
35
+ err = false
36
+ begin
37
+ r.j( 11 )
38
+ rescue RupatMod::RupatInvalidLineError
39
+ err = true
40
+ end
41
+ assert_equal( err, true )
42
+ assert_equal( r.l, 10 )
43
+
44
+
45
+ # ------------------------------------------------------------
46
+ # Test excursion:
47
+ l = r.excursion do
48
+ r.j( 2 ).l
49
+ end
50
+ assert_equal( r.l, 10 )
51
+ assert_equal( l, 2 )
52
+
53
+
54
+ # ------------------------------------------------------------
55
+ # Test searching:
56
+ assert_equal( r.j(0).f( /Line 0/ ).l, 0 )
57
+ assert_equal( r.f( /Line 1/ ).l, 1 )
58
+ assert_equal( r.f( /ne 8/ ).l, 8 )
59
+ l = r.excursion do
60
+ r.f( /Line 9/ ).l
61
+ end
62
+ assert_equal( r.l, 8 )
63
+ assert_equal( l, 9 )
64
+
65
+ err = false
66
+ begin
67
+ r.findForward( /Line 1/ )
68
+ rescue RupatMod::RupatSearchError
69
+ err = true
70
+ end
71
+ assert_equal( err, true )
72
+
73
+ err = false
74
+ begin
75
+ r.findBackward( /Line 1/ )
76
+ rescue RupatMod::RupatSearchError
77
+ err = true
78
+ end
79
+ assert_equal( err, false )
80
+ assert_equal( r.l, 1 )
81
+
82
+ err = false
83
+ begin
84
+ r.findBackward( /Line 9/ )
85
+ rescue RupatMod::RupatSearchError
86
+ err = true
87
+ end
88
+ assert_equal( err, true )
89
+ assert_equal( r.l, 1 )
90
+
91
+ b = r.findBlock( /Line 7/, /Line 8/ )
92
+ assert_equal( b, [7,8] )
93
+ assert_equal( r[ Range.new( *b ) ], ["Line 7", "Line 8"] )
94
+
95
+
96
+ # ------------------------------------------------------------
97
+ # Test content queries:
98
+ assert_equal( r.j.g, "Line 0" )
99
+ assert_equal( r.g( 9 ), "Line 9" )
100
+ assert_equal( r.g( 10 ), nil )
101
+ assert_equal( r.l, 0 )
102
+ assert_equal( r.gm( 0, 1 ), ["Line 0", "Line 1"] )
103
+ assert_equal( r.gm( 1 ), ["Line 0", "Line 1"] )
104
+ assert_equal( r.cp( 1 ).copybuf, ["Line 0", "Line 1"] )
105
+
106
+
107
+ # ------------------------------------------------------------
108
+ # Test content manipulation:
109
+ l = r.g
110
+ r.s( "foobar" )
111
+ assert_equal( r.g, "foobar" )
112
+ r.s( l )
113
+ assert_equal( r.length, 10 )
114
+
115
+
116
+ r.replace do |c|
117
+ c.gsub( /ne/, 'en' )
118
+ end
119
+ assert_equal( r.g, "Lien 0" )
120
+ r.s( l )
121
+
122
+ r.i( 'Line -1' )
123
+ assert_equal( r.length, 11 )
124
+ assert_equal( r.g, "Line -1" )
125
+ r.d
126
+ assert_equal( r.length, 10 )
127
+ assert_equal( r.g, "Line 0" )
128
+
129
+ c = ["foo", "bar" ]
130
+ r.im( c )
131
+ assert_equal( r.length, 12 )
132
+ assert_equal( r.gm( 1 ), c )
133
+ assert_equal( r.cp(1).pt.gm(1), c )
134
+ assert_equal( r.length, 14 )
135
+ assert_equal( r.dm(4).length, 10 )
136
+
137
+ assert_equal( r.jl.a( 'foo' ).g, 'foo' )
138
+ assert_equal( r.a( 'bar' ).g, 'bar' )
139
+ assert_equal( r.length, 12 )
140
+ assert_equal( r.gm(10,11), c )
141
+ assert_equal( r.l, r.length-1 )
142
+ assert_equal( r.am( "foo\nbar" ).length, 14 )
143
+ assert_equal( r.gm(-1), c )
144
+ assert_equal( r.ct( 10, 13 ).copybuf, c+c )
145
+
146
+ len = r.length
147
+ assert_equal( r.j.ifi( test_file ).length, 2*len )
148
+ assert_equal( r.je.ifi( test_file ).length, 3*len )
149
+
150
+ r.replaceAll( /Line/, 'foobar' )
151
+ assert_equal( r.gm(5,6), [ 'foobar 5', 'foobar 6' ] )
152
+ r.replaceWithin( /foobar/, 'Line', 10, 19 )
153
+
154
+
155
+ # ------------------------------------------------------------
156
+ # Test file saving:
157
+
158
+ # Add lines to file and check for updates.
159
+ r = Rupat.update( test_file ).useAlias
160
+ ref = r.lines.dup
161
+ r.ifi( test_file )
162
+ r.save
163
+ r = Rupat.open( test_file ).useAlias
164
+ assert_equal( r.lines, ref+ref )
165
+
166
+ # File save with nil.
167
+ r = Rupat.open( test_file ).useAlias
168
+ r.ct( 10, r.last )
169
+ err = false
170
+ begin
171
+ r.save
172
+ rescue RupatMod::RupatTypeError
173
+ err = true
174
+ end
175
+ assert_equal( err, true )
176
+
177
+ # Save the file (with original content).
178
+ r.save( test_file )
179
+
180
+ # Edit and save to backup file.
181
+ r = Rupat.edit( test_file ).useAlias
182
+ bu = r.close
183
+ assert_equal( File.exist?( bu ), true )
184
+ FileUtils.rm_f( bu )
185
+
186
+ # Create a new file with ".create".
187
+ bu = test_file+'.dup'
188
+ r = Rupat.create( test_file, bu ).useAlias
189
+ r.close
190
+ assert_equal( File.exist?( bu ), true )
191
+ FileUtils.rm_f( bu )
192
+
193
+ # Create file from lines.
194
+ bu = test_file+'.dup'
195
+ content = Rupat.open( test_file ).lines
196
+ r = Rupat.lines( content )
197
+ r.save( bu )
198
+ assert_equal( File.exist?( bu ), true )
199
+ assert_equal( r.length, 10 )
200
+ FileUtils.rm_f( bu )
201
+
202
+ # File-handle based concatenation.
203
+ fh = File.open( bu, 'w' )
204
+ r = Rupat.open( test_file )
205
+ r.save( fh )
206
+ r.save( fh )
207
+ fh.close
208
+ assert_equal( Rupat.open( bu ).length, 20 )
209
+ FileUtils.rm_f( bu )
210
+
211
+ end
212
+
213
+ end
@@ -0,0 +1,27 @@
1
+ require 'test/unit'
2
+ require 'rupat'
3
+ require 'fileutils'
4
+
5
+ class RupatBinTest < Test::Unit::TestCase
6
+
7
+
8
+ # Test patch generation.
9
+ def test_patch
10
+
11
+ test_dir = 'test/input'
12
+ diff1 = "#{test_dir}/diff_test1.txt"
13
+ diff2 = "#{test_dir}/diff_test2.txt"
14
+ patcher = 'test/patcher.rb'
15
+ patched_diff = "#{test_dir}/patched.txt"
16
+
17
+ system( "bin/rupat -p #{diff1} #{diff2} -o #{patcher}" )
18
+ system( "#{patcher} > #{patched_diff}" )
19
+
20
+ assert_equal( system( "diff #{patched_diff} #{diff2} " ), true )
21
+
22
+ FileUtils.rm_f( patcher )
23
+ FileUtils.rm_f( patched_diff )
24
+
25
+ end
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rupat
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: 2015-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: como
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.5
27
+ description: Rupat is a Ruby Patching utility. It can be used to patch files or for
28
+ extracting information from files. Rupat comes with a library for general use and
29
+ simple executable for patching files.
30
+ email: tero.isannainen@gmail.com
31
+ executables:
32
+ - rupat
33
+ extensions: []
34
+ extra_rdoc_files:
35
+ - README.rdoc
36
+ files:
37
+ - CHANGELOG.rdoc
38
+ - LICENSE
39
+ - README.rdoc
40
+ - bin/rupat
41
+ - doc/Rupat.html
42
+ - doc/RupatAlias.html
43
+ - doc/RupatMod.html
44
+ - doc/RupatMod/RupatError.html
45
+ - doc/RupatMod/RupatInvalidLineError.html
46
+ - doc/RupatMod/RupatPasteError.html
47
+ - doc/RupatMod/RupatSearchError.html
48
+ - doc/RupatMod/RupatTypeError.html
49
+ - doc/_index.html
50
+ - doc/class_list.html
51
+ - doc/css/common.css
52
+ - doc/css/full_list.css
53
+ - doc/css/style.css
54
+ - doc/file.CHANGELOG.html
55
+ - doc/file.README.html
56
+ - doc/file_list.html
57
+ - doc/frames.html
58
+ - doc/index.html
59
+ - doc/js/app.js
60
+ - doc/js/full_list.js
61
+ - doc/js/jquery.js
62
+ - doc/method_list.html
63
+ - doc/top-level-namespace.html
64
+ - lib/rupat.rb
65
+ - lib/version.rb
66
+ - test/input/diff_test1.txt
67
+ - test/input/diff_test2.txt
68
+ - test/input/test_file1.txt
69
+ - test/test_rupat.rb
70
+ - test/test_rupat_bin.rb
71
+ homepage:
72
+ licenses:
73
+ - Ruby
74
+ metadata: {}
75
+ post_install_message: Check README...
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 1.9.3
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Rupat is used to patch text files.
95
+ test_files: []
96
+ has_rdoc: