breakverter 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,9 @@
1
+ === 1.1.0 / 2009-03-01
2
+
3
+ * Tested compatibility with ruby 1.9.1
4
+ * Added support for custom string linebreak encodings in library
5
+ * Added automated tests for the commandline tool
6
+
1
7
  === 1.0.1 / 2009-02-24
2
8
 
3
9
  * Now tested on Windows XP
@@ -6,3 +6,6 @@ Rakefile
6
6
  bin/breakverter
7
7
  lib/breakverter.rb
8
8
  spec/breakverter_spec.rb
9
+ spec/fixtures/unix.txt
10
+ spec/fixtures/windows.txt
11
+ spec/fixtures/mac.txt
data/README.txt CHANGED
@@ -11,7 +11,8 @@ to any of these formats.
11
11
  == FEATURES/PROBLEMS:
12
12
 
13
13
  * Usable as library and commandline tool.
14
- * Tested on Ubuntu Linux and Windows XP
14
+ * Tested on Ubuntu Linux 8.10 and Windows XP
15
+ * Compatible with ruby 1.9.1 (only the library part because of the not yet compatible user-choices gem)
15
16
 
16
17
  == SYNOPSIS:
17
18
 
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require './lib/breakverter.rb'
7
7
  Hoe.new('breakverter', BreakVerter::VERSION) do |p|
8
8
  p.rubyforge_name = 'aef'
9
9
  p.developer('Alexander E. Fischer', 'aef@raxys.net')
10
- p.extra_dev_deps = %w{rspec user-choices}
10
+ p.extra_dev_deps = %w{rspec user-choices sys-uname}
11
11
  p.testlib = 'spec'
12
12
  p.test_globs = ['spec/**/*_spec.rb']
13
13
  end
@@ -17,8 +17,12 @@
17
17
  # You should have received a copy of the GNU General Public License
18
18
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
- require 'rubygems'
21
- require 'breakverter'
20
+ begin
21
+ require 'lib/breakverter'
22
+ rescue LoadError
23
+ require 'rubygems'
24
+ require 'breakverter'
25
+ end
22
26
 
23
27
  begin
24
28
  require 'user-choices'
@@ -65,7 +69,7 @@ class BreakVerter::Application < UserChoices::Command
65
69
  def execute
66
70
  raise "Input file not found (#{@user_choices[:input_filename]})" unless File.exists?(@user_choices[:input_filename])
67
71
  raise "Input file access denied (#{@user_choices[:input_filename]})" unless File.readable?(@user_choices[:input_filename])
68
- result = BreakVerter.convert(File.read(@user_choices[:input_filename]), @user_choices[:output])
72
+ result = BreakVerter.convert(File.read(@user_choices[:input_filename]), @user_choices[:output].to_sym)
69
73
 
70
74
  if @user_choices[:output_filename] == '-'
71
75
  puts result
@@ -17,7 +17,7 @@
17
17
 
18
18
  # Module containing a single method
19
19
  module BreakVerter
20
- VERSION = '1.0.1'
20
+ VERSION = '1.1.0'
21
21
 
22
22
  BREAKS = {
23
23
  :unix => "\n",
@@ -26,14 +26,13 @@ module BreakVerter
26
26
  }
27
27
 
28
28
  # Convert a file with any linebreak encoding to a specific linebreak encoding.
29
+ #
30
+ # If given output_encoding is not a key of BREAKS, all linebreaks are replaced
31
+ # with output_encoding's content itself.
29
32
  def self.convert(input, output_encoding = :unix)
30
33
  if input.respond_to?(:to_s) then input = input.to_s
31
34
  else raise 'Input has to be a string or must support to_s' end
32
35
 
33
- if output_encoding.respond_to?(:to_sym) then output_encoding = output_encoding.to_sym
34
- else raise 'Output encoding has to be a symbol or must support to_sym' end
35
-
36
- raise 'Output encoding unsupported' unless BREAKS.include?(output_encoding)
37
- input.gsub(/\r(?:\n)?|\n/, BREAKS[output_encoding])
36
+ input.gsub(/\r(?:\n)?|\n/, BREAKS[output_encoding] || output_encoding)
38
37
  end
39
38
  end
@@ -15,7 +15,17 @@
15
15
  # You should have received a copy of the GNU General Public License
16
16
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
- require 'breakverter'
18
+ require 'lib/breakverter'
19
+ require 'tempfile'
20
+
21
+ require 'rubygems'
22
+ require 'sys/uname'
23
+
24
+ # If there is a way to get the executable path of the currently running ruby
25
+ # interpreter, please tell me how.
26
+ warn 'Attention: If the ruby interpreter to be tested with is not ruby in the' +
27
+ 'default path, you have to change this manually in spec/breakverter_spec.rb'
28
+ RUBY_PATH = 'ruby'
19
29
 
20
30
  module BreakVerterSpecHelper
21
31
  def unix_fixture
@@ -29,38 +39,99 @@ module BreakVerterSpecHelper
29
39
  def mac_fixture
30
40
  "Abcdef\rAbcdef\rAbcdef"
31
41
  end
42
+
43
+ def custom_fixture
44
+ "AbcdeffnordAbcdeffnordAbcdef"
45
+ end
32
46
  end
33
47
 
34
48
  describe BreakVerter do
35
49
  include BreakVerterSpecHelper
36
50
 
37
- it 'should complain about invalid output formats' do
38
- lambda {
39
- BreakVerter.convert(unix_fixture, :invalid)
40
- }.should raise_error(RuntimeError, 'Output encoding unsupported')
41
- end
51
+ describe 'library' do
52
+ it 'should convert correctly from unix to windows format' do
53
+ BreakVerter.convert(unix_fixture, :windows).should eql(windows_fixture)
54
+ end
42
55
 
43
- it 'should convert correctly from unix to windows format' do
44
- BreakVerter.convert(unix_fixture, :windows).should eql(windows_fixture)
45
- end
56
+ it 'should convert correctly from unix to mac format' do
57
+ BreakVerter.convert(unix_fixture, :mac).should eql(mac_fixture)
58
+ end
46
59
 
47
- it 'should convert correctly from unix to mac format' do
48
- BreakVerter.convert(unix_fixture, :mac).should eql(mac_fixture)
49
- end
60
+ it 'should convert correctly from unix to a custom format' do
61
+ BreakVerter.convert(unix_fixture, 'fnord').should eql(custom_fixture)
62
+ end
50
63
 
51
- it 'should convert correctly from windows to unix format' do
52
- BreakVerter.convert(windows_fixture, :unix).should eql(unix_fixture)
53
- end
64
+ it 'should convert correctly from windows to unix format' do
65
+ BreakVerter.convert(windows_fixture, :unix).should eql(unix_fixture)
66
+ end
54
67
 
55
- it 'should convert correctly from windows to mac format' do
56
- BreakVerter.convert(windows_fixture, :mac).should eql(mac_fixture)
57
- end
68
+ it 'should convert correctly from windows to mac format' do
69
+ BreakVerter.convert(windows_fixture, :mac).should eql(mac_fixture)
70
+ end
71
+
72
+ it 'should convert correctly from unix to a custom format' do
73
+ BreakVerter.convert(windows_fixture, 'fnord').should eql(custom_fixture)
74
+ end
58
75
 
59
- it 'should convert correctly from mac to unix format' do
60
- BreakVerter.convert(mac_fixture, :unix).should eql(unix_fixture)
76
+ it 'should convert correctly from mac to unix format' do
77
+ BreakVerter.convert(mac_fixture, :unix).should eql(unix_fixture)
78
+ end
79
+
80
+ it 'should convert correctly from mac to windows format' do
81
+ BreakVerter.convert(mac_fixture, :windows).should eql(windows_fixture)
82
+ end
83
+
84
+ it 'should convert correctly from unix to a custom format' do
85
+ BreakVerter.convert(mac_fixture, 'fnord').should eql(custom_fixture)
86
+ end
61
87
  end
62
88
 
63
- it 'should convert correctly from mac to windows format' do
64
- BreakVerter.convert(mac_fixture, :windows).should eql(windows_fixture)
89
+ describe 'commandline tool' do
90
+ it 'should use unix as default format' do
91
+ `#{RUBY_PATH} bin/breakverter spec/fixtures/windows.txt`.should eql(unix_fixture + "\n")
92
+ end
93
+
94
+ it 'should accept -o option to specify output format' do
95
+ `#{RUBY_PATH} bin/breakverter -o mac spec/fixtures/unix.txt`.should eql(mac_fixture + "\n")
96
+ end
97
+
98
+ it 'should also accept --output option to specify output format' do
99
+ `#{RUBY_PATH} bin/breakverter -o windows spec/fixtures/mac.txt`.should eql(windows_fixture + "\n")
100
+ end
101
+
102
+ it 'should abort on invalid output formats' do
103
+ puts "\nAn error output after this line is expected behavior, simply ignore it:\n"
104
+ `#{RUBY_PATH} bin/breakverter -o fnord spec/fixtures/mac.txt`.should be_empty
105
+ end
106
+
107
+ it 'should accept BREAKVERTER_OUTPUT environment variable to specify output format' do
108
+ if Sys::Uname.sysname.downcase.include?('windows')
109
+ `set BREAKVERTER_OUTPUT=mac`
110
+ `#{RUBY_PATH} bin/breakverter --output mac spec/fixtures/windows.txt`.should eql(mac_fixture + "\n")
111
+ else
112
+ `env BREAKVERTER_OUTPUT=mac #{RUBY_PATH} bin/breakverter --output mac spec/fixtures/windows.txt`.should eql(mac_fixture + "\n")
113
+ end
114
+ end
115
+
116
+ it 'should use output format specified with -o even if BREAKVERTER_OUTPUT environment variable is set' do
117
+ if Sys::Uname.sysname.downcase.include?('windows')
118
+ `set BREAKVERTER_OUTPUT=windows`
119
+ `#{RUBY_PATH} bin/breakverter -o mac spec/fixtures/unix.txt`.should eql(mac_fixture + "\n")
120
+ else
121
+ `env BREAKVERTER_OUTPUT=windows #{RUBY_PATH} bin/breakverter -o mac spec/fixtures/unix.txt`.should eql(mac_fixture + "\n")
122
+ end
123
+ end
124
+
125
+ it 'should use a second argument as target file' do
126
+ temp_file = Tempfile.open('breakverter_spec')
127
+ location = temp_file.path
128
+ temp_file.close
129
+ temp_file.unlink
130
+
131
+ `#{RUBY_PATH} bin/breakverter --output windows spec/fixtures/unix.txt #{location}`.should be_empty
132
+
133
+ File.read(location).should eql(windows_fixture)
134
+ File.unlink(location)
135
+ end
65
136
  end
66
137
  end
@@ -0,0 +1 @@
1
+ Abcdef
@@ -0,0 +1,3 @@
1
+ Abcdef
2
+ Abcdef
3
+ Abcdef
@@ -0,0 +1,3 @@
1
+ Abcdef
2
+ Abcdef
3
+ Abcdef
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breakverter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander E. Fischer
@@ -29,7 +29,7 @@ cert_chain:
29
29
  55akF+N8NbO6tpVDy6TMagqa10LfEpiQH6dvDHe/xdAqYOCrXKpmqzwu2PI=
30
30
  -----END CERTIFICATE-----
31
31
 
32
- date: 2009-02-25 00:00:00 +01:00
32
+ date: 2009-03-01 00:00:00 +01:00
33
33
  default_executable:
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
@@ -52,6 +52,16 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: "0"
54
54
  version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: sys-uname
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
55
65
  - !ruby/object:Gem::Dependency
56
66
  name: hoe
57
67
  type: :development
@@ -74,6 +84,9 @@ extra_rdoc_files:
74
84
  - Manifest.txt
75
85
  - README.txt
76
86
  - COPYING.txt
87
+ - spec/fixtures/unix.txt
88
+ - spec/fixtures/windows.txt
89
+ - spec/fixtures/mac.txt
77
90
  files:
78
91
  - History.txt
79
92
  - Manifest.txt
@@ -83,6 +96,9 @@ files:
83
96
  - bin/breakverter
84
97
  - lib/breakverter.rb
85
98
  - spec/breakverter_spec.rb
99
+ - spec/fixtures/unix.txt
100
+ - spec/fixtures/windows.txt
101
+ - spec/fixtures/mac.txt
86
102
  has_rdoc: true
87
103
  homepage: "Project: https://rubyforge.org/projects/aef/"
88
104
  post_install_message:
metadata.gz.sig CHANGED
Binary file