gli_aziz_light 2.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +17 -0
- data/CONTRIBUTING.md +23 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +201 -0
- data/ObjectModel.graffle +1191 -0
- data/README.rdoc +109 -0
- data/Rakefile +126 -0
- data/bin/gli +59 -0
- data/bin/report_on_rake_results +10 -0
- data/bin/test_all_rubies.sh +6 -0
- data/features/gli_executable.feature +90 -0
- data/features/gli_init.feature +232 -0
- data/features/step_definitions/gli_executable_steps.rb +18 -0
- data/features/step_definitions/gli_init_steps.rb +11 -0
- data/features/step_definitions/todo_steps.rb +88 -0
- data/features/support/env.rb +53 -0
- data/features/todo.feature +413 -0
- data/features/todo_legacy.feature +128 -0
- data/gli.cheat +95 -0
- data/gli.gemspec +34 -0
- data/gli.rdoc +73 -0
- data/lib/gli.rb +35 -0
- data/lib/gli/app.rb +286 -0
- data/lib/gli/app_support.rb +341 -0
- data/lib/gli/command.rb +171 -0
- data/lib/gli/command_finder.rb +41 -0
- data/lib/gli/command_line_option.rb +34 -0
- data/lib/gli/command_line_token.rb +63 -0
- data/lib/gli/command_support.rb +181 -0
- data/lib/gli/commands/compound_command.rb +42 -0
- data/lib/gli/commands/doc.rb +231 -0
- data/lib/gli/commands/help.rb +95 -0
- data/lib/gli/commands/help_modules/arg_name_formatter.rb +20 -0
- data/lib/gli/commands/help_modules/command_finder.rb +60 -0
- data/lib/gli/commands/help_modules/command_help_format.rb +156 -0
- data/lib/gli/commands/help_modules/global_help_format.rb +70 -0
- data/lib/gli/commands/help_modules/help_completion_format.rb +31 -0
- data/lib/gli/commands/help_modules/list_formatter.rb +23 -0
- data/lib/gli/commands/help_modules/one_line_wrapper.rb +18 -0
- data/lib/gli/commands/help_modules/options_formatter.rb +49 -0
- data/lib/gli/commands/help_modules/text_wrapper.rb +53 -0
- data/lib/gli/commands/help_modules/tty_only_wrapper.rb +23 -0
- data/lib/gli/commands/help_modules/verbatim_wrapper.rb +16 -0
- data/lib/gli/commands/initconfig.rb +74 -0
- data/lib/gli/commands/rdoc_document_listener.rb +116 -0
- data/lib/gli/commands/scaffold.rb +401 -0
- data/lib/gli/dsl.rb +226 -0
- data/lib/gli/exceptions.rb +71 -0
- data/lib/gli/flag.rb +68 -0
- data/lib/gli/gli_option_block_parser.rb +84 -0
- data/lib/gli/gli_option_parser.rb +156 -0
- data/lib/gli/option_parser_factory.rb +81 -0
- data/lib/gli/option_parsing_result.rb +21 -0
- data/lib/gli/options.rb +23 -0
- data/lib/gli/switch.rb +35 -0
- data/lib/gli/terminal.rb +101 -0
- data/lib/gli/version.rb +5 -0
- data/test/apps/README.md +2 -0
- data/test/apps/todo/Gemfile +2 -0
- data/test/apps/todo/README.rdoc +6 -0
- data/test/apps/todo/Rakefile +23 -0
- data/test/apps/todo/bin/todo +63 -0
- data/test/apps/todo/lib/todo/commands/create.rb +24 -0
- data/test/apps/todo/lib/todo/commands/list.rb +63 -0
- data/test/apps/todo/lib/todo/commands/ls.rb +47 -0
- data/test/apps/todo/lib/todo/commands/make.rb +52 -0
- data/test/apps/todo/lib/todo/version.rb +3 -0
- data/test/apps/todo/test/tc_nothing.rb +14 -0
- data/test/apps/todo/todo.gemspec +23 -0
- data/test/apps/todo/todo.rdoc +5 -0
- data/test/apps/todo_legacy/Gemfile +2 -0
- data/test/apps/todo_legacy/README.rdoc +6 -0
- data/test/apps/todo_legacy/Rakefile +23 -0
- data/test/apps/todo_legacy/bin/todo +61 -0
- data/test/apps/todo_legacy/lib/todo/commands/create.rb +24 -0
- data/test/apps/todo_legacy/lib/todo/commands/list.rb +63 -0
- data/test/apps/todo_legacy/lib/todo/commands/ls.rb +47 -0
- data/test/apps/todo_legacy/lib/todo/version.rb +3 -0
- data/test/apps/todo_legacy/test/tc_nothing.rb +14 -0
- data/test/apps/todo_legacy/todo.gemspec +23 -0
- data/test/apps/todo_legacy/todo.rdoc +5 -0
- data/test/apps/todo_plugins/commands/third.rb +1 -0
- data/test/config.yaml +10 -0
- data/test/fake_std_out.rb +30 -0
- data/test/init_simplecov.rb +8 -0
- data/test/option_test_helper.rb +13 -0
- data/test/tc_command.rb +508 -0
- data/test/tc_compound_command.rb +22 -0
- data/test/tc_doc.rb +325 -0
- data/test/tc_flag.rb +62 -0
- data/test/tc_gli.rb +773 -0
- data/test/tc_help.rb +387 -0
- data/test/tc_options.rb +43 -0
- data/test/tc_subcommand_parsing.rb +104 -0
- data/test/tc_subcommands.rb +260 -0
- data/test/tc_switch.rb +55 -0
- data/test/tc_terminal.rb +100 -0
- data/test/tc_verbatim_wrapper.rb +36 -0
- data/test/test_helper.rb +20 -0
- metadata +330 -0
@@ -0,0 +1,260 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TC_testSubCommand < Clean::Test::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@fake_stdout = FakeStdOut.new
|
8
|
+
@fake_stderr = FakeStdOut.new
|
9
|
+
|
10
|
+
@original_stdout = $stdout
|
11
|
+
$stdout = @fake_stdout
|
12
|
+
@original_stderr = $stderr
|
13
|
+
$stderr = @fake_stderr
|
14
|
+
|
15
|
+
@app = CLIApp.new
|
16
|
+
@app.reset
|
17
|
+
@app.subcommand_option_handling :legacy
|
18
|
+
@app.error_device=@fake_stderr
|
19
|
+
ENV.delete('GLI_DEBUG')
|
20
|
+
end
|
21
|
+
|
22
|
+
def teardown
|
23
|
+
$stdout = @original_stdout
|
24
|
+
$stderr = @original_stderr
|
25
|
+
end
|
26
|
+
|
27
|
+
['add','new'].each do |name|
|
28
|
+
test_that "We run the 'add' subcommand using '#{name}'" do
|
29
|
+
Given we_have_a_command_with_two_subcommands
|
30
|
+
When run_app('remote',name,'-f','foo','bar')
|
31
|
+
Then assert_command_ran_with(:add, :command_options => {:f => true}, :args => %w(foo bar))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
test_that "with subcommands, but not using one on the command-line, we run the base action" do
|
36
|
+
Given we_have_a_command_with_two_subcommands
|
37
|
+
When run_app('remote','foo','bar')
|
38
|
+
Then assert_command_ran_with(:base, :command_options => {:f => false}, :args => %w(foo bar))
|
39
|
+
end
|
40
|
+
|
41
|
+
test_that "switches and flags defined on a subcommand are available" do
|
42
|
+
Given we_have_a_command_with_two_subcommands(:switches => [:addswitch], :flags => [:addflag])
|
43
|
+
When run_app('remote','add','--addswitch','--addflag','foo','bar')
|
44
|
+
Then assert_command_ran_with(:add,:command_options => { :addswitch => true, :addflag => 'foo', :f => false },
|
45
|
+
:args => ['bar'])
|
46
|
+
end
|
47
|
+
|
48
|
+
test_that "--help works for subcommands in :normal handling mode" do
|
49
|
+
Given { @app.subcommand_option_handling :normal }
|
50
|
+
And we_have_a_command_with_two_subcommands
|
51
|
+
When { @app.run(["remote", "add", "--help"]) rescue nil }
|
52
|
+
Then { assert_no_match /^error/, @fake_stderr.to_s, "should not output an error message" }
|
53
|
+
end
|
54
|
+
|
55
|
+
test_that "--help works for subcommands in :legacy handling mode" do
|
56
|
+
Given { @app.subcommand_option_handling :legacy }
|
57
|
+
And we_have_a_command_with_two_subcommands
|
58
|
+
When { @app.run(["remote", "add", "--help"]) rescue nil }
|
59
|
+
Then { assert_no_match /^error/, @fake_stderr.to_s, "should not output an error message" }
|
60
|
+
end
|
61
|
+
|
62
|
+
test_that "we can reopen commands to add new subcommands" do
|
63
|
+
Given {
|
64
|
+
@app.command :remote do |p|
|
65
|
+
p.command :add do |c|
|
66
|
+
c.action do |global_options,command_options,args|
|
67
|
+
@ran_command = :add
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
@app.command :remote do |p|
|
72
|
+
p.command :new do |c|
|
73
|
+
c.action do |global_options,command_options,args|
|
74
|
+
@ran_command = :new
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
}
|
79
|
+
When run_app('remote','new')
|
80
|
+
Then { assert_equal(@ran_command, :new) }
|
81
|
+
When run_app('remote', 'add')
|
82
|
+
Then { assert_equal(@ran_command, :add) }
|
83
|
+
end
|
84
|
+
|
85
|
+
test_that "reopening commands doesn't re-add them to the output" do
|
86
|
+
Given {
|
87
|
+
@app.command :remote do |p|
|
88
|
+
p.command(:add) { }
|
89
|
+
end
|
90
|
+
@app.command :remote do |p|
|
91
|
+
p.command(:new) { }
|
92
|
+
end
|
93
|
+
}
|
94
|
+
command_names = @app.instance_variable_get("@commands_declaration_order").collect { |c| c.name }
|
95
|
+
assert_equal 1, command_names.grep(:remote).size
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
test_that "we can reopen commands doesn't cause conflicts" do
|
100
|
+
Given {
|
101
|
+
@app.command :remote do |p|
|
102
|
+
p.command :add do |c|
|
103
|
+
c.action do |global_options,command_options,args|
|
104
|
+
@ran_command = :remote_add
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
@app.command :local do |p|
|
109
|
+
p.command :add do |c|
|
110
|
+
c.action do |global_options,command_options,args|
|
111
|
+
@ran_command = :local_add
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
}
|
116
|
+
When run_app('remote','add')
|
117
|
+
Then { assert_equal(@ran_command, :remote_add) }
|
118
|
+
When run_app('local', 'add')
|
119
|
+
Then { assert_equal(@ran_command, :local_add) }
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
test_that "we can nest subcommands very deep" do
|
124
|
+
Given {
|
125
|
+
@run_results = { :add => nil, :rename => nil, :base => nil }
|
126
|
+
@app.command :remote do |c|
|
127
|
+
|
128
|
+
c.switch :f
|
129
|
+
c.command :add do |add|
|
130
|
+
add.command :some do |some|
|
131
|
+
some.command :cmd do |cmd|
|
132
|
+
cmd.switch :s
|
133
|
+
cmd.action do |global_options,command_options,args|
|
134
|
+
@run_results[:cmd] = [global_options,command_options,args]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
ENV['GLI_DEBUG'] = 'true'
|
141
|
+
}
|
142
|
+
When run_app('remote','add','some','cmd','-s','blah')
|
143
|
+
Then assert_command_ran_with(:cmd, :command_options => {:s => true, :f => false},:args => ['blah'])
|
144
|
+
end
|
145
|
+
|
146
|
+
test_that "when any command in the chain has no action, but there's still arguments, indicate we have an unknown command" do
|
147
|
+
Given a_very_deeply_nested_command_structure
|
148
|
+
Then {
|
149
|
+
assert_raises GLI::UnknownCommand do
|
150
|
+
When run_app('remote','add','some','foo')
|
151
|
+
end
|
152
|
+
assert_match /Unknown command 'foo'/,@fake_stderr.to_s
|
153
|
+
}
|
154
|
+
end
|
155
|
+
|
156
|
+
test_that "when a command in the chain has no action, but there's NO additional arguments, indicate we need a subcommand" do
|
157
|
+
Given a_very_deeply_nested_command_structure
|
158
|
+
Then {
|
159
|
+
assert_raises GLI::BadCommandLine do
|
160
|
+
When run_app('remote','add','some')
|
161
|
+
end
|
162
|
+
assert_match /Command 'some' requires a subcommand/,@fake_stderr.to_s
|
163
|
+
}
|
164
|
+
end
|
165
|
+
|
166
|
+
private
|
167
|
+
|
168
|
+
def run_app(*args)
|
169
|
+
lambda { @exit_code = @app.run(args) }
|
170
|
+
end
|
171
|
+
|
172
|
+
def a_very_deeply_nested_command_structure
|
173
|
+
lambda {
|
174
|
+
@run_results = { :add => nil, :rename => nil, :base => nil }
|
175
|
+
@app.command :remote do |c|
|
176
|
+
|
177
|
+
c.switch :f
|
178
|
+
c.command :add do |add|
|
179
|
+
add.command :some do |some|
|
180
|
+
some.command :cmd do |cmd|
|
181
|
+
cmd.switch :s
|
182
|
+
cmd.action do |global_options,command_options,args|
|
183
|
+
@run_results[:cmd] = [global_options,command_options,args]
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
ENV['GLI_DEBUG'] = 'true'
|
190
|
+
}
|
191
|
+
end
|
192
|
+
|
193
|
+
# expected_command - name of command exepcted to have been run
|
194
|
+
# options:
|
195
|
+
# - global_options => hash of expected options
|
196
|
+
# - command_options => hash of expected command options
|
197
|
+
# - args => array of expected args
|
198
|
+
def assert_command_ran_with(expected_command,options)
|
199
|
+
lambda {
|
200
|
+
global_options = options[:global_options] || { :help => false }
|
201
|
+
@run_results.each do |command,results|
|
202
|
+
if command == expected_command
|
203
|
+
results.map! { |r| r.reject { |k, v| k == :cli } }
|
204
|
+
assert_equal(indifferent_hash(global_options),results[0])
|
205
|
+
assert_equal(indifferent_hash(options[:command_options]),results[1])
|
206
|
+
assert_equal(options[:args],results[2])
|
207
|
+
else
|
208
|
+
assert_nil results
|
209
|
+
end
|
210
|
+
end
|
211
|
+
}
|
212
|
+
end
|
213
|
+
|
214
|
+
def indifferent_hash(possibly_nil_hash)
|
215
|
+
return {} if possibly_nil_hash.nil?
|
216
|
+
possibly_nil_hash.keys.each do |key|
|
217
|
+
if key.kind_of? Symbol
|
218
|
+
possibly_nil_hash[key.to_s] = possibly_nil_hash[key] unless possibly_nil_hash.has_key?(key.to_s)
|
219
|
+
elsif key.kind_of? String
|
220
|
+
possibly_nil_hash[key.to_sym] = possibly_nil_hash[key] unless possibly_nil_hash.has_key?(key.to_sym)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
possibly_nil_hash
|
224
|
+
end
|
225
|
+
|
226
|
+
# options -
|
227
|
+
# :flags => flags to add to :add
|
228
|
+
# :switiches => switiches to add to :add
|
229
|
+
def we_have_a_command_with_two_subcommands(options = {})
|
230
|
+
lambda {
|
231
|
+
@run_results = { :add => nil, :rename => nil, :base => nil }
|
232
|
+
@app.command :remote do |c|
|
233
|
+
|
234
|
+
c.switch :f
|
235
|
+
|
236
|
+
c.desc "add a remote"
|
237
|
+
c.command [:add,:new] do |add|
|
238
|
+
|
239
|
+
Array(options[:flags]).each { |_| add.flag _ }
|
240
|
+
Array(options[:switches]).each { |_| add.switch _ }
|
241
|
+
add.action do |global_options,command_options,args|
|
242
|
+
@run_results[:add] = [global_options,command_options,args]
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
c.desc "rename a remote"
|
247
|
+
c.command :rename do |rename|
|
248
|
+
rename.action do |global_options,command_options,args|
|
249
|
+
@run_results[:rename] = [global_options,command_options,args]
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
c.action do |global_options,command_options,args|
|
254
|
+
@run_results[:base] = [global_options,command_options,args]
|
255
|
+
end
|
256
|
+
end
|
257
|
+
ENV['GLI_DEBUG'] = 'true'
|
258
|
+
}
|
259
|
+
end
|
260
|
+
end
|
data/test/tc_switch.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TC_testSwitch < Clean::Test::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def test_basics_simple
|
7
|
+
Given switch_with_names(:filename)
|
8
|
+
Then attributes_should_be_set
|
9
|
+
And name_should_be(:filename)
|
10
|
+
And aliases_should_be(nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_basics_kinda_complex
|
14
|
+
Given switch_with_names([:f])
|
15
|
+
Then attributes_should_be_set
|
16
|
+
And name_should_be(:f)
|
17
|
+
And aliases_should_be(nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_basics_complex
|
21
|
+
Given switch_with_names([:f,:file,:filename])
|
22
|
+
Then attributes_should_be_set
|
23
|
+
And name_should_be(:f)
|
24
|
+
And aliases_should_be([:file,:filename])
|
25
|
+
And {
|
26
|
+
assert_equal ["-f","--[no-]file","--[no-]filename"],@switch.arguments_for_option_parser
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_includes_negatable
|
31
|
+
assert_equal '-a',GLI::Switch.name_as_string('a')
|
32
|
+
assert_equal '--[no-]foo',GLI::Switch.name_as_string('foo')
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def switch_with_names(names)
|
38
|
+
lambda do
|
39
|
+
@options = {
|
40
|
+
:desc => 'Filename',
|
41
|
+
:long_desc => 'The Filename',
|
42
|
+
}
|
43
|
+
@switch = GLI::Switch.new(names,@options)
|
44
|
+
@cli_option = @switch
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def attributes_should_be_set
|
49
|
+
lambda {
|
50
|
+
assert_equal(@options[:desc],@switch.description)
|
51
|
+
assert_equal(@options[:long_desc],@switch.long_description)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/test/tc_terminal.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TC_testTerminal < Clean::Test::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def test_command_exists
|
7
|
+
assert GLI::Terminal.instance.command_exists?('ls')
|
8
|
+
assert !GLI::Terminal.instance.command_exists?('asdfasfasdf')
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@old_columns = ENV['COLUMNS']
|
13
|
+
@old_lines = ENV['LINES']
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
ENV['COLUMNS'] = @old_columns
|
18
|
+
ENV['LINES'] = @old_lines
|
19
|
+
GLI::Terminal.default_size = [80,24]
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_shared_instance_is_same
|
23
|
+
assert_equal GLI::Terminal.instance,GLI::Terminal.instance
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_size_based_on_columns
|
27
|
+
ENV['COLUMNS'] = '666'
|
28
|
+
ENV['LINES'] = '777'
|
29
|
+
assert_equal [666,777],GLI::Terminal.instance.size
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_size_using_tput
|
33
|
+
terminal = GLI::Terminal.new
|
34
|
+
terminal.make_unsafe!
|
35
|
+
GLI::Terminal.instance_eval do
|
36
|
+
def run_command(command)
|
37
|
+
if command == 'tput cols'
|
38
|
+
return '888'
|
39
|
+
elsif command == 'tput lines'
|
40
|
+
return '999'
|
41
|
+
else
|
42
|
+
raise "Unexpected command called: #{command}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
def command_exists?(command); true; end
|
46
|
+
def jruby?; true; end
|
47
|
+
end
|
48
|
+
ENV['COLUMNS'] = 'foo'
|
49
|
+
assert_equal [888,999],terminal.size
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_size_using_stty
|
53
|
+
terminal = GLI::Terminal.new
|
54
|
+
terminal.make_unsafe!
|
55
|
+
GLI::Terminal.instance_eval do
|
56
|
+
def run_command(command)
|
57
|
+
|
58
|
+
if RUBY_PLATFORM == 'java'
|
59
|
+
return '5678' if command == 'tput cols'
|
60
|
+
return '1234' if command == 'tput lines'
|
61
|
+
else
|
62
|
+
return '1234 5678' if command == 'stty size'
|
63
|
+
return '1234 5678' if command == 'stty'
|
64
|
+
end
|
65
|
+
|
66
|
+
raise "Unexpected command called: #{command} for #{RUBY_PLATFORM}"
|
67
|
+
end
|
68
|
+
def command_exists?(command); true; end
|
69
|
+
def jruby?; false; end
|
70
|
+
def solaris?; false; end
|
71
|
+
end
|
72
|
+
ENV['COLUMNS'] = 'foo'
|
73
|
+
assert_equal [5678,1234],terminal.size
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_size_using_default
|
77
|
+
terminal = GLI::Terminal.new
|
78
|
+
terminal.make_unsafe!
|
79
|
+
GLI::Terminal.instance_eval do
|
80
|
+
def command_exists?(command); false; end
|
81
|
+
def jruby?; false; end
|
82
|
+
def solaris?; false; end
|
83
|
+
end
|
84
|
+
ENV['COLUMNS'] = 'foo'
|
85
|
+
assert_equal [80,24],terminal.size
|
86
|
+
# While we have this set up, lets make sure the default change falls through
|
87
|
+
GLI::Terminal.default_size = [90,45]
|
88
|
+
assert_equal [90,45],terminal.size
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_size_using_default_when_exception
|
92
|
+
terminal = GLI::Terminal.new
|
93
|
+
GLI::Terminal.instance_eval do
|
94
|
+
def jruby?; raise "Problem"; end
|
95
|
+
def solaris?; false; end
|
96
|
+
end
|
97
|
+
ENV['COLUMNS'] = 'foo'
|
98
|
+
assert_equal [80,24],terminal.size
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TC_testVerbatimWrapper < Clean::Test::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
test_that "verbatim wrapper handles nil" do
|
7
|
+
Given {
|
8
|
+
@wrapper = GLI::Commands::HelpModules::VerbatimWrapper.new(any_int,any_int)
|
9
|
+
}
|
10
|
+
When {
|
11
|
+
@result = @wrapper.wrap(nil)
|
12
|
+
}
|
13
|
+
Then {
|
14
|
+
assert_equal '',@result
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
test_that "verbatim wrapper doesn't touch the input" do
|
19
|
+
Given {
|
20
|
+
@wrapper = GLI::Commands::HelpModules::VerbatimWrapper.new(any_int,any_int)
|
21
|
+
@input = <<EOS
|
22
|
+
|This is|an ASCII|table|
|
23
|
+
+-------+--------+-----+
|
24
|
+
| foo | bar | baz |
|
25
|
+
+-------+--------+-----+
|
26
|
+
EOS
|
27
|
+
}
|
28
|
+
When {
|
29
|
+
@result = @wrapper.wrap(@input)
|
30
|
+
}
|
31
|
+
Then {
|
32
|
+
assert_equal @input,@result
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|