aef-breakverter 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,175 @@
1
+ # Copyright 2009 Alexander E. Fischer <aef@raxys.net>
2
+ #
3
+ # This file is part of BreakVerter.
4
+ #
5
+ # BreakVerter is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require 'lib/breakverter'
19
+ require 'tempfile'
20
+
21
+ require 'rubygems'
22
+ require 'sys/uname'
23
+
24
+ module BreakVerterSpecHelper
25
+ # If there is a way to get the executable path of the currently running ruby
26
+ # interpreter, please tell me how.
27
+ warn 'Attention: If the ruby interpreter to be tested with is not ruby in the' +
28
+ "default path, you have to change this manually in #{__FILE__} line #{__LINE__ + 1}"
29
+ RUBY_PATH = 'ruby'
30
+
31
+ def executable_path
32
+ "#{RUBY_PATH} bin/breakverter"
33
+ end
34
+
35
+ def fixture_path(name)
36
+ File.join('spec/fixtures', name)
37
+ end
38
+
39
+ def windows?
40
+ Sys::Uname.sysname.downcase.include?('windows')
41
+ end
42
+
43
+ def unix_fixture
44
+ "Abcdef\nAbcdef\nAbcdef"
45
+ end
46
+
47
+ def windows_fixture
48
+ "Abcdef\r\nAbcdef\r\nAbcdef"
49
+ end
50
+
51
+ def mac_fixture
52
+ "Abcdef\rAbcdef\rAbcdef"
53
+ end
54
+
55
+ def custom_fixture
56
+ "AbcdeffnordAbcdeffnordAbcdef"
57
+ end
58
+ end
59
+
60
+ describe Aef::BreakVerter do
61
+ include BreakVerterSpecHelper
62
+
63
+ context 'library' do
64
+ it 'should convert correctly from unix to windows format' do
65
+ Aef::BreakVerter.convert(unix_fixture, :windows).should eql(windows_fixture)
66
+ end
67
+
68
+ it 'should convert correctly from unix to mac format' do
69
+ Aef::BreakVerter.convert(unix_fixture, :mac).should eql(mac_fixture)
70
+ end
71
+
72
+ it 'should convert correctly from unix to a custom format' do
73
+ Aef::BreakVerter.convert(unix_fixture, 'fnord').should eql(custom_fixture)
74
+ end
75
+
76
+ it 'should convert correctly from windows to unix format' do
77
+ Aef::BreakVerter.convert(windows_fixture, :unix).should eql(unix_fixture)
78
+ end
79
+
80
+ it 'should convert correctly from windows to mac format' do
81
+ Aef::BreakVerter.convert(windows_fixture, :mac).should eql(mac_fixture)
82
+ end
83
+
84
+ it 'should convert correctly from unix to a custom format' do
85
+ Aef::BreakVerter.convert(windows_fixture, 'fnord').should eql(custom_fixture)
86
+ end
87
+
88
+ it 'should convert correctly from mac to unix format' do
89
+ Aef::BreakVerter.convert(mac_fixture, :unix).should eql(unix_fixture)
90
+ end
91
+
92
+ it 'should convert correctly from mac to windows format' do
93
+ Aef::BreakVerter.convert(mac_fixture, :windows).should eql(windows_fixture)
94
+ end
95
+
96
+ it 'should convert correctly from unix to a custom format' do
97
+ Aef::BreakVerter.convert(mac_fixture, 'fnord').should eql(custom_fixture)
98
+ end
99
+ end
100
+
101
+ context 'commandline tool' do
102
+ it 'should use unix as default format' do
103
+ `#{executable_path} #{fixture_path('windows.txt')}`.should eql(unix_fixture + "\n")
104
+ end
105
+
106
+ it 'should accept -o option to specify output format' do
107
+ `#{executable_path} -o mac #{fixture_path('unix.txt')}`.should eql(mac_fixture + "\n")
108
+ end
109
+
110
+ it 'should also accept --output option to specify output format' do
111
+ `#{executable_path} --output windows #{fixture_path('mac.txt')}`.should eql(windows_fixture + "\n")
112
+ end
113
+
114
+ it 'should abort on invalid output formats' do
115
+ puts "\nAn error output after this line is expected behavior, simply ignore it:\n"
116
+ `#{executable_path} -o fnord #{fixture_path('mac.txt')}`.should be_empty
117
+ end
118
+
119
+ it 'should accept BREAKVERTER_OUTPUT environment variable to specify output format' do
120
+ if windows?
121
+ `set BREAKVERTER_OUTPUT=mac`
122
+ `#{executable_path} --output mac #{fixture_path('windows.txt')}`.should eql(mac_fixture + "\n")
123
+ else
124
+ `env BREAKVERTER_OUTPUT=mac #{executable_path} --output mac #{fixture_path('windows.txt')}`.should eql(mac_fixture + "\n")
125
+ end
126
+ end
127
+
128
+ it 'should use output format specified with -o even if BREAKVERTER_OUTPUT environment variable is set' do
129
+ if windows?
130
+ `set BREAKVERTER_OUTPUT=windows`
131
+ `#{executable_path} -o mac #{fixture_path('unix.txt')}`.should eql(mac_fixture + "\n")
132
+ else
133
+ `env BREAKVERTER_OUTPUT=windows #{executable_path} -o mac #{fixture_path('unix.txt')}`.should eql(mac_fixture + "\n")
134
+ end
135
+ end
136
+
137
+ it 'should use a second argument as target file' do
138
+ temp_file = Tempfile.open('breakverter_spec')
139
+ location = temp_file.path
140
+ temp_file.close
141
+ temp_file.unlink
142
+
143
+ `#{executable_path} --output windows #{fixture_path('unix.txt')} #{location}`.should be_empty
144
+
145
+ File.read(location).should eql(windows_fixture)
146
+ File.unlink(location)
147
+ end
148
+
149
+ it 'should display correct version and licensing information with the --version switch' do
150
+ message = <<-EOF
151
+ BreakVerter 1.2.0
152
+
153
+ Project: https://rubyforge.org/projects/aef/
154
+ RDoc: http://aef.rubyforge.org/breakverter/
155
+ Github: http://github.com/aef/breakverter/
156
+
157
+ Copyright 2009 Alexander E. Fischer <aef@raxys.net>
158
+
159
+ BreakVerter is free software: you can redistribute it and/or modify
160
+ it under the terms of the GNU General Public License as published by
161
+ the Free Software Foundation, either version 3 of the License, or
162
+ (at your option) any later version.
163
+
164
+ This program is distributed in the hope that it will be useful,
165
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
166
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
167
+ GNU General Public License for more details.
168
+
169
+ You should have received a copy of the GNU General Public License
170
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
171
+ EOF
172
+ `#{executable_path} --version`.should eql(message)
173
+ end
174
+ end
175
+ 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 ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aef-breakverter
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander E. Fischer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-05 00:00:00 -07:00
13
+ default_executable: breakverter
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: user-choices
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: sys-uname
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: hoe
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.11.0
54
+ version:
55
+ description: BreakVerter is a Ruby library and commandline tool for conversion of text between linebreak encoding formats of unix, windows or mac.
56
+ email:
57
+ - aef@raxys.net
58
+ executables:
59
+ - breakverter
60
+ extensions: []
61
+
62
+ extra_rdoc_files:
63
+ - History.txt
64
+ - Manifest.txt
65
+ - COPYING.txt
66
+ - README.rdoc
67
+ files:
68
+ - History.txt
69
+ - Manifest.txt
70
+ - README.rdoc
71
+ - COPYING.txt
72
+ - Rakefile
73
+ - bin/breakverter
74
+ - lib/breakverter.rb
75
+ - lib/breakverter/breakverter.rb
76
+ - spec/breakverter_spec.rb
77
+ - spec/fixtures/unix.txt
78
+ - spec/fixtures/windows.txt
79
+ - spec/fixtures/mac.txt
80
+ has_rdoc: true
81
+ homepage: https://rubyforge.org/projects/aef/
82
+ post_install_message:
83
+ rdoc_options:
84
+ - --main
85
+ - README.rdoc
86
+ - --inline-source
87
+ - --line-numbers
88
+ - --title
89
+ - BreakVerter
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ version:
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ version:
104
+ requirements: []
105
+
106
+ rubyforge_project: aef
107
+ rubygems_version: 1.2.0
108
+ signing_key:
109
+ specification_version: 2
110
+ summary: BreakVerter is a Ruby library and commandline tool for conversion of text between linebreak encoding formats of unix, windows or mac.
111
+ test_files: []
112
+