sparehand 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +2 -0
- data/Manifest.txt +17 -0
- data/README.txt +37 -0
- data/Rakefile +54 -0
- data/bin/comment_block +8 -0
- data/coverage/index.html +259 -0
- data/coverage/lib-comment_block_rb.html +670 -0
- data/lib/comment_block.rb +52 -0
- data/lib/safe_modify.rb +18 -0
- data/lib/sparehand/version.rb +9 -0
- data/setup.rb +1585 -0
- data/test/comment_block_cli_test.rb +28 -0
- data/test/comment_block_test.rb +66 -0
- data/test/fixtures/example_hosts_file +7 -0
- data/test/fixtures/safe_modify_data +1 -0
- data/test/safe_modify_test.rb +28 -0
- data/test/test_helper.rb +8 -0
- metadata +64 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class CommentBlockCLITest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@ruby = 'ruby'
|
6
|
+
@ruby_opts = "-I#{$:.last}"
|
7
|
+
@cli = File.join(File.dirname(__FILE__), '..', 'bin', 'comment_block')
|
8
|
+
@file = fixtures 'example_hosts_file'
|
9
|
+
@command = "#{@ruby} #{@ruby_opts} #{@cli} #{@file}"
|
10
|
+
@original_data = File.read(@file)
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
File.open(@file, 'w') { |f| f.print @original_data }
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_cli_comment_operation
|
18
|
+
`#{@command} comment internal`
|
19
|
+
assert(/^#internal/ =~ File.read(@file))
|
20
|
+
assert(/^#external/ =~ File.read(@file))
|
21
|
+
`#{@command} toggle external`
|
22
|
+
assert(/^#internal/ =~ File.read(@file))
|
23
|
+
assert(/^external/ =~ File.read(@file))
|
24
|
+
`#{@command} uncomment external`
|
25
|
+
assert(/^#internal/ =~ File.read(@file))
|
26
|
+
assert(/^external/ =~ File.read(@file))
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'comment_block'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
class CommentBlockTest < Test::Unit::TestCase
|
6
|
+
@@input = <<EOF
|
7
|
+
uncommented
|
8
|
+
#BEGIN a
|
9
|
+
to be commented
|
10
|
+
#END a
|
11
|
+
EOF
|
12
|
+
|
13
|
+
@@comment_expected = <<EOF
|
14
|
+
uncommented
|
15
|
+
#BEGIN a
|
16
|
+
#to be commented
|
17
|
+
#END a
|
18
|
+
EOF
|
19
|
+
@@uncomment_expected = <<EOF
|
20
|
+
uncommented
|
21
|
+
#BEGIN a
|
22
|
+
to be commented
|
23
|
+
#END a
|
24
|
+
EOF
|
25
|
+
|
26
|
+
def test_ignore_doesnt_change_line
|
27
|
+
assert_equal('hi', Sparehand::CommentBlock.ignore('hi'))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_comment_operation_forces_comment
|
31
|
+
assert_equal('#hi', process('hi', :comment))
|
32
|
+
assert_equal('#hi', process('#hi', :comment))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_uncomment_operation_forces_uncomment
|
36
|
+
assert_equal('hi', process('#hi', :uncomment))
|
37
|
+
assert_equal('hi', process('hi', :uncomment))
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_any_other_operation_causes_toggle
|
41
|
+
assert_equal('hi', process('#hi', :toggle))
|
42
|
+
assert_equal('#hi', process('hi', :something_other_than_toggle))
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_comment_character_can_be_changed
|
46
|
+
assert_equal('hi', process('//hi', :uncomment, '//'))
|
47
|
+
assert_equal('hi', process('//hi', :toggle, '//'))
|
48
|
+
end
|
49
|
+
|
50
|
+
def process data, op, comment = '#'
|
51
|
+
Sparehand::CommentBlock.process_line(data, op, comment)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_process_should_operate_between_blocks
|
55
|
+
assert_equal(@@comment_expected, Sparehand::CommentBlock.process(@@input, 'a', :comment))
|
56
|
+
assert_equal(@@comment_expected, Sparehand::CommentBlock.process(@@input, 'a', :toggle))
|
57
|
+
assert_equal(@@uncomment_expected, Sparehand::CommentBlock.process(@@input, 'a', :uncomment))
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_process_should_operate_on_streams_and_return_nil
|
61
|
+
input = StringIO.new(@@input)
|
62
|
+
output = StringIO.new
|
63
|
+
assert_nil Sparehand::CommentBlock.process(@@input, 'a', :toggle, '#', output)
|
64
|
+
assert_equal(@@comment_expected, output.string)
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
changed!
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'safe_modify'
|
3
|
+
|
4
|
+
class SafeModifyTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@file = fixtures('safe_modify_data')
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_problem_in_block_should_leave_original
|
10
|
+
original = File.read @file
|
11
|
+
begin
|
12
|
+
File.safe_modify(@file) do |input, output|
|
13
|
+
raise 'Error on write'
|
14
|
+
end
|
15
|
+
rescue Exception
|
16
|
+
end
|
17
|
+
|
18
|
+
assert_equal original, File.read(@file)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_load_and_modify_file
|
22
|
+
File.safe_modify(@file) do |input, output|
|
23
|
+
assert_equal File.read(@file), input.read
|
24
|
+
output.print 'changed!'
|
25
|
+
end
|
26
|
+
assert_equal 'changed!', File.read(@file)
|
27
|
+
end
|
28
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.1
|
3
|
+
specification_version: 1
|
4
|
+
name: sparehand
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-02-10 00:00:00 -05:00
|
8
|
+
summary: A collection of utilities for system manipulations both from Ruby or CLI.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: mat.schaffer@gmail.com
|
12
|
+
homepage: http://phillyonrails.rubyforge.org/sparehand
|
13
|
+
rubyforge_project: phillyonrails
|
14
|
+
description: A collection of utilities for system manipulations both from Ruby or CLI.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Mat Schaffer
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- bin/comment_block
|
37
|
+
- coverage/index.html
|
38
|
+
- coverage/lib-comment_block_rb.html
|
39
|
+
- lib/comment_block.rb
|
40
|
+
- lib/safe_modify.rb
|
41
|
+
- lib/sparehand/version.rb
|
42
|
+
- setup.rb
|
43
|
+
- test/comment_block_cli_test.rb
|
44
|
+
- test/comment_block_test.rb
|
45
|
+
- test/fixtures/example_hosts_file
|
46
|
+
- test/fixtures/safe_modify_data
|
47
|
+
- test/safe_modify_test.rb
|
48
|
+
- test/test_helper.rb
|
49
|
+
test_files:
|
50
|
+
- test/comment_block_cli_test.rb
|
51
|
+
- test/comment_block_test.rb
|
52
|
+
- test/safe_modify_test.rb
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
executables:
|
58
|
+
- comment_block
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
dependencies: []
|
64
|
+
|