linebreak-cli 2.0.0

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.
@@ -0,0 +1,48 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2009-2012
4
+
5
+ This file is part of Linebreak::CLI.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ require 'user-choices'
21
+ require 'aef/linebreak'
22
+
23
+ # Namespace for projects of Alexander E. Fischer <aef@raxys.net>.
24
+ #
25
+ # If you want to be able to simply type Example instead of Aef::Example to
26
+ # address classes in this namespace simply write the following before using the
27
+ # classes.
28
+ #
29
+ # @example Including the namespace
30
+ # include Aef
31
+ # @author Alexander E. Fischer
32
+ module Aef
33
+
34
+ # Namespace for the linebreak library
35
+ module Linebreak
36
+
37
+ # Namespace for the linebreak command-line tool
38
+ module CLI
39
+
40
+ end
41
+ end
42
+ end
43
+
44
+ require 'aef/linebreak/cli/version'
45
+ require 'aef/linebreak/cli/pathname_conversion'
46
+ require 'aef/linebreak/cli/commands/encode'
47
+ require 'aef/linebreak/cli/commands/encodings'
48
+ require 'aef/linebreak/cli/commands/version'
@@ -0,0 +1,80 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2009-2012
4
+
5
+ This file is part of Linebreak::CLI.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ module Aef
21
+ module Linebreak
22
+ module CLI
23
+
24
+ # Command-line sub-command for re-ncoding of files.
25
+ class EncodeCommand < UserChoices::Command
26
+ include UserChoices
27
+
28
+ # Prepare configuration sources
29
+ def add_sources(builder)
30
+ builder.add_source(
31
+ CommandLineSource, :usage,
32
+ "Usage: #$PROGRAM_NAME encode [OPTIONS] [INPUT] [OUTPUT]\n\n",
33
+ "Convert all linebreak encodings of a file.\n",
34
+ "Use the environment variable LINEBREAK_SYSTEM to specify a default output encoding.\n"
35
+ )
36
+
37
+ builder.add_source(EnvironmentSource, :mapping,
38
+ :system => 'LINEBREAK_SYSTEM'
39
+ )
40
+ end
41
+
42
+ # Define configuration options
43
+ def add_choices(builder)
44
+ systems = Aef::Linebreak::BREAK_BY_SYSTEM.keys.map{|key| key.to_s}
45
+ builder.add_choice(:system, :default => 'unix', :type => systems) do |cli|
46
+ cli.uses_option('-s', '--system SYSTEM',
47
+ "Output encoding system. Possible settings: #{systems.join(', ')}")
48
+ end
49
+
50
+ builder.add_choice(:files, :length => 0..2, :type => :pathname) {|cli| cli.uses_arglist}
51
+ end
52
+
53
+ # Manual option post processing
54
+ def postprocess_user_choices
55
+ if @user_choices[:files][0] and @user_choices[:files][0] != Pathname('-')
56
+ @user_choices[:input] = @user_choices[:files][0].open('r')
57
+ else
58
+ @user_choices[:input] = STDIN
59
+ end
60
+
61
+ if @user_choices[:files][1] and @user_choices[:files][1] != Pathname('-')
62
+ @user_choices[:output] = @user_choices[:files][1].open('w')
63
+ else
64
+ @user_choices[:output] = STDOUT
65
+ end
66
+ end
67
+
68
+ # Main program
69
+ def execute
70
+ @user_choices[:input].each_line do |line|
71
+ @user_choices[:output] << Aef::Linebreak.encode(line, @user_choices[:system].to_sym)
72
+ end
73
+
74
+ [:input, :output].each {|stream| @user_choices[stream].close }
75
+ end
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,97 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2009-2012
4
+
5
+ This file is part of Linebreak::CLI.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ module Aef
21
+ module Linebreak
22
+ module CLI
23
+
24
+ # Command-line sub command for encoding detection.
25
+ class EncodingsCommand < UserChoices::Command
26
+ include UserChoices
27
+
28
+ # Prepare configuration sources
29
+ def add_sources(builder)
30
+ builder.add_source(CommandLineSource, :usage,
31
+ "Usage: #$PROGRAM_NAME encodings [OPTIONS] [FILE]\n\n",
32
+ "Detect linebreak encoding systems of a file.\n"
33
+ )
34
+ end
35
+
36
+ # Define configuration options
37
+ def add_choices(builder)
38
+ builder.add_choice(:ensure, :type => [:string]) do |cli|
39
+ cli.uses_option('-e', '--ensure SYSTEMLIST',
40
+ "Verify that given encodings are existent. Separated by commas without spaces. Possible settings: #{Aef::Linebreak::BREAK_BY_SYSTEM.keys.join(', ')}.")
41
+ end
42
+
43
+ builder.add_choice(:files, :type => :pathname) {|cli| cli.uses_arglist}
44
+ end
45
+
46
+ # Manual option post processing
47
+ def postprocess_user_choices
48
+ if @user_choices[:ensure]
49
+ @user_choices[:ensure] = @user_choices[:ensure].map{|string| string.to_sym }.to_set
50
+ end
51
+
52
+ if @user_choices[:files].empty? or @user_choices[:files].include?(Pathname('-'))
53
+ @user_choices[:files] = [STDIN]
54
+ end
55
+ end
56
+
57
+ # Main program
58
+ def execute
59
+ systems_by_file = {}
60
+
61
+ @user_choices[:files].each do |file|
62
+ unless systems_by_file[file]
63
+ systems_by_file[file] = Set.new
64
+
65
+ file.each_line do |line|
66
+ systems_by_file[file] = Aef::Linebreak.encodings(line) + systems_by_file[file]
67
+ end
68
+ end
69
+ end
70
+
71
+ failed = false
72
+
73
+ systems_by_file.each do |file, systems|
74
+ print "#{file}: " unless file == STDIN
75
+
76
+ sorted_systems = systems.sort do |a,b|
77
+ order = [:unix, :windows, :mac]
78
+ order.index(a) <=> order.index(b)
79
+ end
80
+
81
+ print sorted_systems.join(',')
82
+
83
+ if @user_choices[:ensure] and systems != @user_choices[:ensure]
84
+ failed = true
85
+ puts ' (failed)'
86
+ else
87
+ puts
88
+ end
89
+ end
90
+
91
+ exit false if failed
92
+ end
93
+ end
94
+
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2009-2012
4
+
5
+ This file is part of Linebreak::CLI.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ module Aef
21
+ module Linebreak
22
+ module CLI
23
+
24
+ # Command-line sub-command to display version and license info.
25
+ class VersionCommand
26
+
27
+ # Main program
28
+ def execute
29
+ # Read licensing information from the top of this file
30
+ license = File.read(__FILE__)[/=begin\n(.*)\n=end/m, 1]
31
+
32
+ puts <<-TEXT
33
+ Linebreak::CLI #{Aef::Linebreak::CLI::VERSION}
34
+ using Linebreak #{Aef::Linebreak::VERSION}
35
+
36
+ Project: https://github.com/aef/linebreak-cli/
37
+ Documentation: http://rdoc.info/github/aef/linebreak-cli/
38
+
39
+ #{license}
40
+ TEXT
41
+
42
+ exit false
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2009-2012
4
+
5
+ This file is part of Linebreak::CLI.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ module Aef
21
+ module Linebreak
22
+ module CLI
23
+
24
+ # This class adds the type :pathname to user-choices
25
+ #
26
+ # @private
27
+ class ConversionToPathname < UserChoices::Conversion
28
+ def self.described_by?(conversion_tag)
29
+ conversion_tag == :pathname
30
+ end
31
+
32
+ def description
33
+ "a pathname"
34
+ end
35
+
36
+ def suitable?(actual)
37
+ true
38
+ end
39
+
40
+ def convert(value)
41
+ case value
42
+ when Array
43
+ pathnames = []
44
+
45
+ value.each {|path| pathnames << Pathname(path) }
46
+
47
+ pathnames
48
+ else
49
+ Pathname(value)
50
+ end
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2009-2012
4
+
5
+ This file is part of Linebreak::CLI.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ module Aef
21
+ module Linebreak
22
+ module CLI
23
+
24
+ # The currently loaded library version
25
+ #
26
+ # Using Semantic Versioning (2.0.0-rc.1) rules
27
+ # @see http://semver.org/
28
+ VERSION = '2.0.0'.freeze
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2009-2012
4
+
5
+ This file is part of Linebreak::CLI.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ require File.expand_path('../lib/aef/linebreak/cli/version', __FILE__)
21
+
22
+ Gem::Specification.new do |s|
23
+ s.name = 'linebreak-cli'
24
+ s.version = Aef::Linebreak::CLI::VERSION.dup
25
+ s.authors = ['Alexander E. Fischer']
26
+ s.email = ['aef@raxys.net']
27
+ s.homepage = 'http://github.com/aef/linebreak-cli'
28
+ s.license = 'ISC'
29
+ s.summary = 'Command-line linebreak system conversion tool'
30
+ s.description = <<-DESCRIPTION
31
+ Linebreak::CLI is a Ruby command-line tool for conversion of text
32
+ between linebreak encoding formats of unix, windows or mac.
33
+
34
+ Before Linebreak 2.0.0 this tool was part of the linebreak gem.
35
+ Earlier versions of Linebreak were called BreakVerter.
36
+ DESCRIPTION
37
+
38
+ s.rubyforge_project = nil
39
+ s.has_rdoc = 'yard'
40
+ s.extra_rdoc_files = ['HISTORY.md', 'LICENSE.md']
41
+
42
+ s.files = `git ls-files`.lines.map(&:chomp)
43
+ s.test_files = `git ls-files -- {test,spec,features}/*`.lines.map(&:chomp)
44
+ s.executables = `git ls-files -- bin/*`.lines.map{|f| File.basename(f.chomp) }
45
+ s.require_paths = ["lib"]
46
+
47
+ s.required_ruby_version = '>= 1.8.7'
48
+
49
+ s.add_dependency('linebreak', '~> 2.0.0')
50
+ s.add_dependency('user-choices', '~> 1.1.6.1')
51
+
52
+ s.add_development_dependency('bundler', '~> 1.0.21')
53
+ s.add_development_dependency('rake', '~> 0.9.2')
54
+ s.add_development_dependency('rspec', '~> 2.8.0')
55
+ s.add_development_dependency('simplecov', '~> 0.6.1')
56
+ s.add_development_dependency('pry', '~> 0.9.8')
57
+ s.add_development_dependency('yard', '~> 0.7.5')
58
+ s.add_development_dependency('childprocess', '~> 0.3.1')
59
+
60
+ s.cert_chain = "#{ENV['GEM_CERT_CHAIN']}".split(':')
61
+ s.signing_key = ENV['GEM_SIGNING_KEY']
62
+ end
@@ -0,0 +1,163 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Alexander E. Fischer <aef@raxys.net>, 2009-2012
4
+
5
+ This file is part of Linebreak::CLI.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted, provided that the above
9
+ copyright notice and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ =end
19
+
20
+ require 'spec_helper'
21
+
22
+ describe Aef::Linebreak do
23
+ include LinebreakSpecHelper
24
+
25
+ let(:unix_fixture) { "Abcdef\nAbcdef\nAbcdef" }
26
+ let(:windows_fixture) { "Abcdef\r\nAbcdef\r\nAbcdef" }
27
+ let(:mac_fixture) { "Abcdef\rAbcdef\rAbcdef" }
28
+
29
+ context 'commandline tool' do
30
+ describe '"version" command' do
31
+ it 'should display correct version and licensing information with the version argument' do
32
+ `#{executable_path} version`.should eql(version_message)
33
+ end
34
+
35
+ it 'should display correct version and licensing information with the --version argument' do
36
+ `#{executable_path} --version`.should eql(version_message)
37
+ end
38
+
39
+ it 'should display correct version and licensing information with the -v argument' do
40
+ `#{executable_path} -v`.should eql(version_message)
41
+ end
42
+
43
+ it 'should display correct version and licensing information with the -V argument' do
44
+ `#{executable_path} -V`.should eql(version_message)
45
+ end
46
+ end
47
+
48
+ describe '"encode" command' do
49
+ it 'should use unix as default format' do
50
+ `#{executable_path} encode #{fixture_path('windows.txt')}`.should eql(unix_fixture)
51
+ end
52
+
53
+ it 'should accept -s option to specify output format' do
54
+ `#{executable_path} encode -s mac #{fixture_path('unix.txt')}`.should eql(mac_fixture)
55
+ end
56
+
57
+ it 'should also accept --system option to specify output format' do
58
+ `#{executable_path} encode --system windows #{fixture_path('mac.txt')}`.should eql(windows_fixture)
59
+ end
60
+
61
+ it 'should abort on invalid output formats' do
62
+ process, stdout, stderr = command("encode -s fnord #{fixture_path('mac.txt')}")
63
+ process.wait
64
+ process.io.stdout.close
65
+ process.io.stderr.close
66
+
67
+ stdout.read.should be_empty
68
+ stderr.read.should_not be_empty
69
+ end
70
+
71
+ it 'should accept LINEBREAK_SYSTEM environment variable to specify output format' do
72
+ env(:LINEBREAK_SYSTEM => 'mac') do
73
+ `#{executable_path} encode #{fixture_path('windows.txt')}`.should eql(mac_fixture)
74
+ end
75
+ end
76
+
77
+ it 'should use output format specified with -s even if LINEBREAK_SYSTEM environment variable is set' do
78
+ env(:LINEBREAK_SYSTEM => 'windows') do
79
+ `#{executable_path} encode -s mac #{fixture_path('unix.txt')}`.should eql(mac_fixture)
80
+ end
81
+ end
82
+
83
+ it 'should use a second argument as target file' do
84
+ temp_file = Tempfile.open('linebreak_spec')
85
+ location = Pathname(temp_file.path)
86
+ temp_file.close
87
+ location.delete
88
+
89
+ `#{executable_path} encode --system windows #{fixture_path('unix.txt')} #{location}`.should be_empty
90
+
91
+ location.read.should eql(windows_fixture)
92
+ location.delete
93
+ end
94
+ end
95
+
96
+ describe '"encodings" command' do
97
+ it "should correctly detect the linebreak encodings of a file" do
98
+ process, stdout, stderr = command("encodings #{fixture_path('mac.txt')}")
99
+ process.wait
100
+ process.io.stdout.close
101
+ process.io.stderr.close
102
+
103
+ stdout.read.should eql("#{fixture_path('mac.txt')}: mac\n")
104
+ process.exit_code.should eql 0
105
+ end
106
+
107
+ it "should correctly detect the linebreak encodings of multiple files" do
108
+ files = %w{unix_windows.txt windows_mac.txt mac_unix.txt unix_windows_mac.txt}
109
+ files = files.map{|file| fixture_path(file)}
110
+
111
+ process, stdout, stderr = command("encodings #{files.join(' ')}")
112
+ process.wait
113
+ process.io.stdout.close
114
+ process.io.stderr.close
115
+ process.exit_code.should eql 0
116
+
117
+ output = stdout.read
118
+ output.should include("#{files[0]}: unix,windows\n")
119
+ output.should include("#{files[1]}: windows,mac\n")
120
+ output.should include("#{files[2]}: unix,mac\n")
121
+ output.should include("#{files[3]}: unix,windows,mac\n")
122
+ end
123
+
124
+ it "should correctly ensure the linebreak encodings of a valid file" do
125
+ process, stdout, stderr = command("encodings --ensure unix #{fixture_path('unix.txt')}")
126
+ process.wait
127
+ process.io.stdout.close
128
+ process.io.stderr.close
129
+ process.exit_code.should eql 0
130
+
131
+ stdout.read.should eql "#{fixture_path('unix.txt')}: unix\n"
132
+ end
133
+
134
+ it "should correctly ensure the linebreak encodings of an invalid file" do
135
+ process, stdout, stderr = command("encodings --ensure mac #{fixture_path('unix_windows.txt')}")
136
+ process.wait
137
+ process.io.stdout.close
138
+ process.io.stderr.close
139
+ process.exit_code.should eql 1
140
+
141
+ stdout.read.should eql "#{fixture_path('unix_windows.txt')}: unix,windows (failed)\n"
142
+ end
143
+
144
+ it "should correctly ensure the linebreak encodings of multiple files" do
145
+ files = %w{unix_windows.txt windows_mac.txt mac_unix.txt unix_windows_mac.txt}
146
+ files = files.map{|file| fixture_path(file)}
147
+
148
+ process, stdout, stderr = command("encodings --ensure windows,unix #{files.join(' ')}")
149
+ process.wait
150
+ process.io.stdout.close
151
+ process.io.stderr.close
152
+ process.exit_code.should eql 1
153
+
154
+ output = stdout.read
155
+ output.should include("#{files[0]}: unix,windows\n")
156
+ output.should_not include("#{files[0]}: unix,windows (failed)\n")
157
+ output.should include("#{files[1]}: windows,mac (failed)\n")
158
+ output.should include("#{files[2]}: unix,mac (failed)\n")
159
+ output.should include("#{files[3]}: unix,windows,mac (failed)\n")
160
+ end
161
+ end
162
+ end
163
+ end