highline 1.0.1 → 1.0.2
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.
- data/CHANGELOG +8 -0
- data/README +1 -1
- data/Rakefile +42 -41
- data/TODO +1 -1
- data/examples/ansi_colors.rb +15 -9
- data/examples/asking_for_arrays.rb +1 -1
- data/examples/basic_usage.rb +50 -50
- data/examples/menus.rb +28 -28
- data/examples/trapping_eof.rb +22 -0
- data/examples/using_readline.rb +5 -5
- data/lib/highline.rb +596 -569
- data/lib/highline/import.rb +2 -2
- data/lib/highline/menu.rb +356 -358
- data/lib/highline/question.rb +406 -409
- data/test/tc_highline.rb +739 -727
- data/test/tc_import.rb +12 -12
- data/test/tc_menu.rb +343 -343
- metadata +49 -45
data/test/tc_highline.rb
CHANGED
@@ -11,733 +11,745 @@ require "highline"
|
|
11
11
|
require "stringio"
|
12
12
|
|
13
13
|
class TestHighLine < Test::Unit::TestCase
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
14
|
+
def setup
|
15
|
+
@input = StringIO.new
|
16
|
+
@output = StringIO.new
|
17
|
+
@terminal = HighLine.new(@input, @output)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_agree
|
21
|
+
@input << "y\nyes\nYES\nHell no!\nNo\n"
|
22
|
+
@input.rewind
|
23
|
+
|
24
|
+
assert_equal(true, @terminal.agree("Yes or no? "))
|
25
|
+
assert_equal(true, @terminal.agree("Yes or no? "))
|
26
|
+
assert_equal(true, @terminal.agree("Yes or no? "))
|
27
|
+
assert_equal(false, @terminal.agree("Yes or no? "))
|
28
|
+
|
29
|
+
@input.truncate(@input.rewind)
|
30
|
+
@input << "yellow"
|
31
|
+
@input.rewind
|
32
|
+
|
33
|
+
assert_equal(true, @terminal.agree("Yes or no? ", :getc))
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_ask
|
37
|
+
name = "James Edward Gray II"
|
38
|
+
@input << name << "\n"
|
39
|
+
@input.rewind
|
40
|
+
|
41
|
+
assert_equal(name, @terminal.ask("What is your name? "))
|
42
|
+
|
43
|
+
assert_raise(EOFError) { @terminal.ask("Any input left? ") }
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_bug_fixes
|
47
|
+
# auto-complete bug
|
48
|
+
@input << "ruby\nRuby\n"
|
49
|
+
@input.rewind
|
50
|
+
|
51
|
+
languages = [:Perl, :Python, :Ruby]
|
52
|
+
answer = @terminal.ask( "What is your favorite programming language? ",
|
53
|
+
languages )
|
54
|
+
assert_equal(languages.last, answer)
|
55
|
+
|
56
|
+
@input.truncate(@input.rewind)
|
57
|
+
@input << "ruby\n"
|
58
|
+
@input.rewind
|
59
|
+
|
60
|
+
answer = @terminal.ask( "What is your favorite programming language? ",
|
61
|
+
languages ) do |q|
|
62
|
+
q.case = :capitalize
|
63
|
+
end
|
64
|
+
assert_equal(languages.last, answer)
|
65
|
+
|
66
|
+
# poor auto-complete error message
|
67
|
+
@input.truncate(@input.rewind)
|
68
|
+
@input << "lisp\nruby\n"
|
69
|
+
@input.rewind
|
70
|
+
@output.truncate(@output.rewind)
|
71
|
+
|
72
|
+
answer = @terminal.ask( "What is your favorite programming language? ",
|
73
|
+
languages ) do |q|
|
74
|
+
q.case = :capitalize
|
75
|
+
end
|
76
|
+
assert_equal(languages.last, answer)
|
77
|
+
assert_equal( "What is your favorite programming language? " +
|
78
|
+
"You must choose one of [:Perl, :Python, :Ruby].\n" +
|
79
|
+
"? ", @output.string )
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_case_changes
|
83
|
+
@input << "jeg2\n"
|
84
|
+
@input.rewind
|
85
|
+
|
86
|
+
answer = @terminal.ask("Enter your initials ") do |q|
|
87
|
+
q.case = :up
|
88
|
+
end
|
89
|
+
assert_equal("JEG2", answer)
|
90
|
+
|
91
|
+
@input.truncate(@input.rewind)
|
92
|
+
@input << "cRaZY\n"
|
93
|
+
@input.rewind
|
94
|
+
|
95
|
+
answer = @terminal.ask("Enter a search string: ") do |q|
|
96
|
+
q.case = :down
|
97
|
+
end
|
98
|
+
assert_equal("crazy", answer)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_character_echo
|
102
|
+
@input << "password\r"
|
103
|
+
@input.rewind
|
104
|
+
|
105
|
+
answer = @terminal.ask("Please enter your password: ") do |q|
|
106
|
+
q.echo = "*"
|
107
|
+
end
|
108
|
+
assert_equal("password", answer)
|
109
|
+
assert_equal("Please enter your password: ********\n", @output.string)
|
110
|
+
|
111
|
+
@input.truncate(@input.rewind)
|
112
|
+
@input << "2"
|
113
|
+
@input.rewind
|
114
|
+
@output.truncate(@output.rewind)
|
115
|
+
|
116
|
+
answer = @terminal.ask( "Select an option (1, 2 or 3): ",
|
117
|
+
Integer ) do |q|
|
118
|
+
q.echo = "*"
|
119
|
+
q.character = true
|
120
|
+
end
|
121
|
+
assert_equal(2, answer)
|
122
|
+
assert_equal("Select an option (1, 2 or 3): *\n", @output.string)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_character_reading
|
126
|
+
# WARNING: This method does NOT cover Unix and Windows savvy testing!
|
127
|
+
@input << "12345"
|
128
|
+
@input.rewind
|
129
|
+
|
130
|
+
answer = @terminal.ask("Enter a single digit: ", Integer) do |q|
|
131
|
+
q.character = :getc
|
132
|
+
end
|
133
|
+
assert_equal(1, answer)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_color
|
137
|
+
@terminal.say("This should be <%= BLUE %>blue<%= CLEAR %>!")
|
138
|
+
assert_equal("This should be \e[34mblue\e[0m!\n", @output.string)
|
139
|
+
|
140
|
+
@output.truncate(@output.rewind)
|
141
|
+
|
142
|
+
@terminal.say( "This should be " +
|
143
|
+
"<%= BOLD + ON_WHITE %>bold on white<%= CLEAR %>!" )
|
144
|
+
assert_equal( "This should be \e[1m\e[47mbold on white\e[0m!\n",
|
145
|
+
@output.string )
|
146
|
+
|
147
|
+
@output.truncate(@output.rewind)
|
148
|
+
|
149
|
+
@terminal.say("This should be <%= color('cyan', CYAN) %>!")
|
150
|
+
assert_equal("This should be \e[36mcyan\e[0m!\n", @output.string)
|
151
|
+
|
152
|
+
@output.truncate(@output.rewind)
|
153
|
+
|
154
|
+
@terminal.say( "This should be " +
|
155
|
+
"<%= color('blinking on red', :blink, :on_red) %>!" )
|
156
|
+
assert_equal( "This should be \e[5m\e[41mblinking on red\e[0m!\n",
|
157
|
+
@output.string )
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_confirm
|
161
|
+
@input << "junk.txt\nno\nsave.txt\ny\n"
|
162
|
+
@input.rewind
|
163
|
+
|
164
|
+
answer = @terminal.ask("Enter a filename: ") do |q|
|
165
|
+
q.confirm = "Are you sure you want to overwrite <%= @answer %>? "
|
166
|
+
q.responses[:ask_on_error] = :question
|
167
|
+
end
|
168
|
+
assert_equal("save.txt", answer)
|
169
|
+
assert_equal( "Enter a filename: " +
|
170
|
+
"Are you sure you want to overwrite junk.txt? " +
|
171
|
+
"Enter a filename: " +
|
172
|
+
"Are you sure you want to overwrite save.txt? ",
|
173
|
+
@output.string )
|
174
|
+
|
175
|
+
@input.truncate(@input.rewind)
|
176
|
+
@input << "junk.txt\nyes\nsave.txt\nn\n"
|
177
|
+
@input.rewind
|
178
|
+
@output.truncate(@output.rewind)
|
179
|
+
|
180
|
+
answer = @terminal.ask("Enter a filename: ") do |q|
|
181
|
+
q.confirm = "Are you sure you want to overwrite <%= @answer %>? "
|
182
|
+
end
|
183
|
+
assert_equal("junk.txt", answer)
|
184
|
+
assert_equal( "Enter a filename: " +
|
185
|
+
"Are you sure you want to overwrite junk.txt? ",
|
186
|
+
@output.string )
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_defaults
|
190
|
+
@input << "\nNo Comment\n"
|
191
|
+
@input.rewind
|
192
|
+
|
193
|
+
answer = @terminal.ask("Are you sexually active? ") do |q|
|
194
|
+
q.validate = /\Ay(?:es)?|no?|no comment\Z/i
|
195
|
+
end
|
196
|
+
assert_equal("No Comment", answer)
|
197
|
+
|
198
|
+
@input.truncate(@input.rewind)
|
199
|
+
@input << "\nYes\n"
|
200
|
+
@input.rewind
|
201
|
+
@output.truncate(@output.rewind)
|
202
|
+
|
203
|
+
answer = @terminal.ask("Are you sexually active? ") do |q|
|
204
|
+
q.default = "No Comment"
|
205
|
+
q.validate = /\Ay(?:es)?|no?|no comment\Z/i
|
206
|
+
end
|
207
|
+
assert_equal("No Comment", answer)
|
208
|
+
assert_equal( "Are you sexually active? |No Comment| ",
|
209
|
+
@output.string )
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_empty
|
213
|
+
@input << "\n"
|
214
|
+
@input.rewind
|
215
|
+
|
216
|
+
answer = @terminal.ask("") do |q|
|
217
|
+
q.default = "yes"
|
218
|
+
q.validate = /\Ay(?:es)?|no?\Z/i
|
219
|
+
end
|
220
|
+
assert_equal("yes", answer)
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_erb
|
224
|
+
@terminal.say( "The integers from 1 to 10 are:\n" +
|
225
|
+
"% (1...10).each do |n|\n" +
|
226
|
+
"\t<%= n %>,\n" +
|
227
|
+
"% end\n" +
|
228
|
+
"\tand 10" )
|
229
|
+
assert_equal( "The integers from 1 to 10 are:\n" +
|
230
|
+
"\t1,\n\t2,\n\t3,\n\t4,\n\t5,\n" +
|
231
|
+
"\t6,\n\t7,\n\t8,\n\t9,\n\tand 10\n",
|
232
|
+
@output.string )
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_files
|
236
|
+
@input << "#{File.basename(__FILE__)[0, 5]}\n"
|
237
|
+
@input.rewind
|
238
|
+
|
239
|
+
file = @terminal.ask("Select a file: ", File) do |q|
|
240
|
+
q.directory = File.expand_path(File.dirname(__FILE__))
|
241
|
+
q.glob = "*.rb"
|
242
|
+
end
|
243
|
+
assert_instance_of(File, file)
|
244
|
+
assert_equal("#!/usr/local/bin/ruby -w\n", file.gets)
|
245
|
+
assert_equal("\n", file.gets)
|
246
|
+
assert_equal("# tc_highline.rb\n", file.gets)
|
247
|
+
file.close
|
248
|
+
|
249
|
+
@input.rewind
|
250
|
+
|
251
|
+
pathname = @terminal.ask("Select a file: ", Pathname) do |q|
|
252
|
+
q.directory = File.expand_path(File.dirname(__FILE__))
|
253
|
+
q.glob = "*.rb"
|
254
|
+
end
|
255
|
+
assert_instance_of(Pathname, pathname)
|
256
|
+
assert_equal(File.size(__FILE__), pathname.size)
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_gather
|
260
|
+
@input << "James\nDana\nStorm\nGypsy\n\n"
|
261
|
+
@input.rewind
|
262
|
+
|
263
|
+
answers = @terminal.ask("Enter four names:") do |q|
|
264
|
+
q.gather = 4
|
265
|
+
end
|
266
|
+
assert_equal(%w{James Dana Storm Gypsy}, answers)
|
267
|
+
assert_equal("\n", @input.gets)
|
268
|
+
assert_equal("Enter four names:\n", @output.string)
|
269
|
+
|
270
|
+
@input.rewind
|
271
|
+
|
272
|
+
answers = @terminal.ask("Enter four names:") do |q|
|
273
|
+
q.gather = ""
|
274
|
+
end
|
275
|
+
assert_equal(%w{James Dana Storm Gypsy}, answers)
|
276
|
+
|
277
|
+
@input.rewind
|
278
|
+
|
279
|
+
answers = @terminal.ask("Enter four names:") do |q|
|
280
|
+
q.gather = /^\s*$/
|
281
|
+
end
|
282
|
+
assert_equal(%w{James Dana Storm Gypsy}, answers)
|
283
|
+
|
284
|
+
@input.truncate(@input.rewind)
|
285
|
+
@input << "29\n49\n30\n"
|
286
|
+
@input.rewind
|
287
|
+
@output.truncate(@output.rewind)
|
288
|
+
|
289
|
+
answers = @terminal.ask("<%= @key %>: ", Integer) do |q|
|
290
|
+
q.gather = { "Age" => 0, "Wife's Age" => 0, "Father's Age" => 0}
|
291
|
+
end
|
292
|
+
assert_equal( { "Age" => 29, "Wife's Age" => 30, "Father's Age" => 49},
|
293
|
+
answers )
|
294
|
+
assert_equal("Age: Father's Age: Wife's Age: ", @output.string)
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_lists
|
298
|
+
digits = %w{Zero One Two Three Four Five Six Seven Eight Nine}
|
299
|
+
erb_digits = digits.dup
|
300
|
+
erb_digits[erb_digits.index("Five")] = "<%= color('Five', :blue) %%>"
|
301
|
+
|
302
|
+
@terminal.say("<%= list(#{digits.inspect}) %>")
|
303
|
+
assert_equal(digits.map { |d| "#{d}\n" }.join, @output.string)
|
304
|
+
|
305
|
+
@output.truncate(@output.rewind)
|
306
|
+
|
307
|
+
@terminal.say("<%= list(#{digits.inspect}, :inline) %>")
|
308
|
+
assert_equal( digits[0..-2].join(", ") + " or #{digits.last}\n",
|
309
|
+
@output.string )
|
310
|
+
|
311
|
+
@output.truncate(@output.rewind)
|
312
|
+
|
313
|
+
@terminal.say("<%= list(#{digits.inspect}, :inline, ' and ') %>")
|
314
|
+
assert_equal( digits[0..-2].join(", ") + " and #{digits.last}\n",
|
315
|
+
@output.string )
|
316
|
+
|
317
|
+
@output.truncate(@output.rewind)
|
318
|
+
|
319
|
+
@terminal.say("<%= list(#{digits.inspect}, :columns_down, 3) %>")
|
320
|
+
assert_equal( "Zero Four Eight\n" +
|
321
|
+
"One Five Nine \n" +
|
322
|
+
"Two Six \n" +
|
323
|
+
"Three Seven\n",
|
324
|
+
@output.string )
|
325
|
+
|
326
|
+
@output.truncate(@output.rewind)
|
327
|
+
|
328
|
+
@terminal.say("<%= list(#{erb_digits.inspect}, :columns_down, 3) %>")
|
329
|
+
assert_equal( "Zero Four Eight\n" +
|
330
|
+
"One \e[34mFive\e[0m Nine \n" +
|
331
|
+
"Two Six \n" +
|
332
|
+
"Three Seven\n",
|
333
|
+
@output.string )
|
334
|
+
|
335
|
+
colums_of_twenty = ["12345678901234567890"] * 5
|
336
|
+
|
337
|
+
@output.truncate(@output.rewind)
|
338
|
+
|
339
|
+
@terminal.say("<%= list(#{colums_of_twenty.inspect}, :columns_down) %>")
|
340
|
+
assert_equal( "12345678901234567890 12345678901234567890 " +
|
341
|
+
"12345678901234567890\n" +
|
342
|
+
"12345678901234567890 12345678901234567890\n",
|
343
|
+
@output.string )
|
344
|
+
|
345
|
+
@output.truncate(@output.rewind)
|
346
|
+
|
347
|
+
@terminal.say("<%= list(#{digits.inspect}, :columns_across, 3) %>")
|
348
|
+
assert_equal( "Zero One Two \n" +
|
349
|
+
"Three Four Five \n" +
|
350
|
+
"Six Seven Eight\n" +
|
351
|
+
"Nine \n",
|
352
|
+
@output.string )
|
340
353
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
" * You're code should not mess with this...\n" +
|
354
|
+
colums_of_twenty.pop
|
355
|
+
|
356
|
+
@output.truncate(@output.rewind)
|
357
|
+
|
358
|
+
@terminal.say("<%= list( #{colums_of_twenty.inspect}, :columns_across ) %>")
|
359
|
+
assert_equal( "12345678901234567890 12345678901234567890 " +
|
360
|
+
"12345678901234567890\n" +
|
361
|
+
"12345678901234567890\n",
|
362
|
+
@output.string )
|
363
|
+
end
|
364
|
+
|
365
|
+
def test_mode
|
366
|
+
# *WARNING*: These tests wil only complete is "stty" mode!
|
367
|
+
assert_equal( "stty", HighLine::CHARACTER_MODE,
|
368
|
+
"Tests require \"stty\" mode." )
|
369
|
+
end
|
370
|
+
|
371
|
+
class NameClass
|
372
|
+
def self.parse( string )
|
373
|
+
if string =~ /^\s*(\w+),\s*(\w+)\s+(\w+)\s*$/
|
374
|
+
self.new($2, $3, $1)
|
375
|
+
else
|
376
|
+
raise ArgumentError, "Invalid name format."
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
def initialize(first, middle, last)
|
381
|
+
@first, @middle, @last = first, middle, last
|
382
|
+
end
|
383
|
+
|
384
|
+
attr_reader :first, :middle, :last
|
385
|
+
end
|
386
|
+
|
387
|
+
def test_my_class_conversion
|
388
|
+
@input << "Gray, James Edward\n"
|
389
|
+
@input.rewind
|
390
|
+
|
391
|
+
answer = @terminal.ask("Your name? ", NameClass) do |q|
|
392
|
+
q.validate = lambda do |name|
|
393
|
+
names = name.split(/,\s*/)
|
394
|
+
return false unless names.size == 2
|
395
|
+
return false if names.first =~ /\s/
|
396
|
+
names.last.split.size == 2
|
397
|
+
end
|
398
|
+
end
|
399
|
+
assert_instance_of(NameClass, answer)
|
400
|
+
assert_equal("Gray", answer.last)
|
401
|
+
assert_equal("James", answer.first)
|
402
|
+
assert_equal("Edward", answer.middle)
|
403
|
+
end
|
404
|
+
|
405
|
+
def test_no_echo
|
406
|
+
@input << "password\r"
|
407
|
+
@input.rewind
|
408
|
+
|
409
|
+
answer = @terminal.ask("Please enter your password: ") do |q|
|
410
|
+
q.echo = false
|
411
|
+
end
|
412
|
+
assert_equal("password", answer)
|
413
|
+
assert_equal("Please enter your password: \n", @output.string)
|
414
|
+
|
415
|
+
@input.rewind
|
416
|
+
@output.truncate(@output.rewind)
|
417
|
+
|
418
|
+
answer = @terminal.ask("Pick a letter or number: ") do |q|
|
419
|
+
q.character = true
|
420
|
+
q.echo = false
|
421
|
+
end
|
422
|
+
assert_equal("p", answer)
|
423
|
+
assert_equal("a", @input.getc.chr)
|
424
|
+
assert_equal("Pick a letter or number: \n", @output.string)
|
425
|
+
end
|
426
|
+
|
427
|
+
def test_paging
|
428
|
+
@terminal.page_at = 22
|
429
|
+
|
430
|
+
@input << "\n\n"
|
431
|
+
@input.rewind
|
432
|
+
|
433
|
+
@terminal.say((1..50).map { |n| "This is line #{n}.\n"}.join)
|
434
|
+
assert_equal( (1..22).map { |n| "This is line #{n}.\n"}.join +
|
435
|
+
"\n-- press enter/return to continue -- \n" +
|
436
|
+
(23..44).map { |n| "This is line #{n}.\n"}.join +
|
437
|
+
"\n-- press enter/return to continue -- \n" +
|
438
|
+
(45..50).map { |n| "This is line #{n}.\n"}.join,
|
439
|
+
@output.string )
|
440
|
+
end
|
441
|
+
|
442
|
+
def test_range_requirements
|
443
|
+
@input << "112\n-541\n28\n"
|
444
|
+
@input.rewind
|
445
|
+
|
446
|
+
answer = @terminal.ask("Tell me your age.", Integer) do |q|
|
447
|
+
q.in = 0..105
|
448
|
+
end
|
449
|
+
assert_equal(28, answer)
|
450
|
+
assert_equal( "Tell me your age.\n" +
|
451
|
+
"Your answer isn't within the expected range " +
|
452
|
+
"(included in 0..105).\n" +
|
453
|
+
"? " +
|
454
|
+
"Your answer isn't within the expected range " +
|
455
|
+
"(included in 0..105).\n" +
|
456
|
+
"? ", @output.string )
|
457
|
+
|
458
|
+
@input.truncate(@input.rewind)
|
459
|
+
@input << "1\n-541\n28\n"
|
460
|
+
@input.rewind
|
461
|
+
@output.truncate(@output.rewind)
|
462
|
+
|
463
|
+
answer = @terminal.ask("Tell me your age.", Integer) do |q|
|
464
|
+
q.above = 3
|
465
|
+
end
|
466
|
+
assert_equal(28, answer)
|
467
|
+
assert_equal( "Tell me your age.\n" +
|
468
|
+
"Your answer isn't within the expected range " +
|
469
|
+
"(above 3).\n" +
|
470
|
+
"? " +
|
471
|
+
"Your answer isn't within the expected range " +
|
472
|
+
"(above 3).\n" +
|
473
|
+
"? ", @output.string )
|
474
|
+
|
475
|
+
@input.truncate(@input.rewind)
|
476
|
+
@input << "1\n28\n-541\n"
|
477
|
+
@input.rewind
|
478
|
+
@output.truncate(@output.rewind)
|
479
|
+
|
480
|
+
answer = @terminal.ask("Lowest numer you can think of?", Integer) do |q|
|
481
|
+
q.below = 0
|
482
|
+
end
|
483
|
+
assert_equal(-541, answer)
|
484
|
+
assert_equal( "Lowest numer you can think of?\n" +
|
485
|
+
"Your answer isn't within the expected range " +
|
486
|
+
"(below 0).\n" +
|
487
|
+
"? " +
|
488
|
+
"Your answer isn't within the expected range " +
|
489
|
+
"(below 0).\n" +
|
490
|
+
"? ", @output.string )
|
491
|
+
|
492
|
+
@input.truncate(@input.rewind)
|
493
|
+
@input << "1\n-541\n6\n"
|
494
|
+
@input.rewind
|
495
|
+
@output.truncate(@output.rewind)
|
496
|
+
|
497
|
+
answer = @terminal.ask("Enter a low even number: ", Integer) do |q|
|
498
|
+
q.above = 0
|
499
|
+
q.below = 10
|
500
|
+
q.in = [2, 4, 6, 8]
|
501
|
+
end
|
502
|
+
assert_equal(6, answer)
|
503
|
+
assert_equal( "Enter a low even number: " +
|
504
|
+
"Your answer isn't within the expected range " +
|
505
|
+
"(above 0, below 10, and included in [2, 4, 6, 8]).\n" +
|
506
|
+
"? " +
|
507
|
+
"Your answer isn't within the expected range " +
|
508
|
+
"(above 0, below 10, and included in [2, 4, 6, 8]).\n" +
|
509
|
+
"? ", @output.string )
|
510
|
+
end
|
511
|
+
|
512
|
+
def test_reask
|
513
|
+
number = 61676
|
514
|
+
@input << "Junk!\n" << number << "\n"
|
515
|
+
@input.rewind
|
516
|
+
|
517
|
+
answer = @terminal.ask("Favorite number? ", Integer)
|
518
|
+
assert_kind_of(Integer, number)
|
519
|
+
assert_instance_of(Fixnum, number)
|
520
|
+
assert_equal(number, answer)
|
521
|
+
assert_equal( "Favorite number? " +
|
522
|
+
"You must enter a valid Integer.\n" +
|
523
|
+
"? ", @output.string )
|
524
|
+
|
525
|
+
@input.rewind
|
526
|
+
@output.truncate(@output.rewind)
|
527
|
+
|
528
|
+
answer = @terminal.ask("Favorite number? ", Integer) do |q|
|
529
|
+
q.responses[:ask_on_error] = :question
|
530
|
+
q.responses[:invalid_type] = "Not a valid number!"
|
531
|
+
end
|
532
|
+
assert_kind_of(Integer, number)
|
533
|
+
assert_instance_of(Fixnum, number)
|
534
|
+
assert_equal(number, answer)
|
535
|
+
assert_equal( "Favorite number? " +
|
536
|
+
"Not a valid number!\n" +
|
537
|
+
"Favorite number? ", @output.string )
|
538
|
+
|
539
|
+
@input.truncate(@input.rewind)
|
540
|
+
@input << "gen\ngene\n"
|
541
|
+
@input.rewind
|
542
|
+
@output.truncate(@output.rewind)
|
543
|
+
|
544
|
+
answer = @terminal.ask("Select a mode: ", [:generate, :gentle])
|
545
|
+
assert_instance_of(Symbol, answer)
|
546
|
+
assert_equal(:generate, answer)
|
547
|
+
assert_equal( "Select a mode: " +
|
548
|
+
"Ambiguous choice. " +
|
549
|
+
"Please choose one of [:generate, :gentle].\n" +
|
550
|
+
"? ", @output.string )
|
551
|
+
end
|
552
|
+
|
553
|
+
def test_response_embedding
|
554
|
+
@input << "112\n-541\n28\n"
|
555
|
+
@input.rewind
|
556
|
+
|
557
|
+
answer = @terminal.ask("Tell me your age.", Integer) do |q|
|
558
|
+
q.in = 0..105
|
559
|
+
q.responses[:not_in_range] = "Need a <%= @question.answer_type %>" +
|
560
|
+
" <%= @question.expected_range %>."
|
561
|
+
end
|
562
|
+
assert_equal(28, answer)
|
563
|
+
assert_equal( "Tell me your age.\n" +
|
564
|
+
"Need a Integer included in 0..105.\n" +
|
565
|
+
"? " +
|
566
|
+
"Need a Integer included in 0..105.\n" +
|
567
|
+
"? ", @output.string )
|
568
|
+
end
|
569
|
+
|
570
|
+
def test_say
|
571
|
+
@terminal.say("This will have a newline.")
|
572
|
+
assert_equal("This will have a newline.\n", @output.string)
|
573
|
+
|
574
|
+
@output.truncate(@output.rewind)
|
575
|
+
|
576
|
+
@terminal.say("This will also have one newline.\n")
|
577
|
+
assert_equal("This will also have one newline.\n", @output.string)
|
578
|
+
|
579
|
+
@output.truncate(@output.rewind)
|
580
|
+
|
581
|
+
@terminal.say("This will not have a newline. ")
|
582
|
+
assert_equal("This will not have a newline. ", @output.string)
|
583
|
+
end
|
584
|
+
|
585
|
+
def test_type_conversion
|
586
|
+
number = 61676
|
587
|
+
@input << number << "\n"
|
588
|
+
@input.rewind
|
589
|
+
|
590
|
+
answer = @terminal.ask("Favorite number? ", Integer)
|
591
|
+
assert_kind_of(Integer, answer)
|
592
|
+
assert_instance_of(Fixnum, answer)
|
593
|
+
assert_equal(number, answer)
|
594
|
+
|
595
|
+
@input.truncate(@input.rewind)
|
596
|
+
number = 1_000_000_000_000_000_000_000_000_000_000
|
597
|
+
@input << number << "\n"
|
598
|
+
@input.rewind
|
599
|
+
|
600
|
+
answer = @terminal.ask("Favorite number? ", Integer)
|
601
|
+
assert_kind_of(Integer, answer)
|
602
|
+
assert_instance_of(Bignum, answer)
|
603
|
+
assert_equal(number, answer)
|
604
|
+
|
605
|
+
@input.truncate(@input.rewind)
|
606
|
+
number = 10.5002
|
607
|
+
@input << number << "\n"
|
608
|
+
@input.rewind
|
609
|
+
|
610
|
+
answer = @terminal.ask( "Favorite number? ",
|
611
|
+
lambda { |n| n.to_f.abs.round } )
|
612
|
+
assert_kind_of(Integer, answer)
|
613
|
+
assert_instance_of(Fixnum, answer)
|
614
|
+
assert_equal(11, answer)
|
615
|
+
|
616
|
+
@input.truncate(@input.rewind)
|
617
|
+
animal = :dog
|
618
|
+
@input << animal << "\n"
|
619
|
+
@input.rewind
|
620
|
+
|
621
|
+
answer = @terminal.ask("Favorite animal? ", Symbol)
|
622
|
+
assert_instance_of(Symbol, answer)
|
623
|
+
assert_equal(animal, answer)
|
624
|
+
|
625
|
+
@input.truncate(@input.rewind)
|
626
|
+
@input << "6/16/76\n"
|
627
|
+
@input.rewind
|
628
|
+
|
629
|
+
answer = @terminal.ask("Enter your birthday.", Date)
|
630
|
+
assert_instance_of(Date, answer)
|
631
|
+
assert_equal(16, answer.day)
|
632
|
+
assert_equal(6, answer.month)
|
633
|
+
assert_equal(76, answer.year)
|
634
|
+
|
635
|
+
@input.truncate(@input.rewind)
|
636
|
+
pattern = "^yes|no$"
|
637
|
+
@input << pattern << "\n"
|
638
|
+
@input.rewind
|
639
|
+
|
640
|
+
answer = @terminal.ask("Give me a pattern to match with: ", Regexp)
|
641
|
+
assert_instance_of(Regexp, answer)
|
642
|
+
assert_equal(/#{pattern}/, answer)
|
643
|
+
|
644
|
+
@input.truncate(@input.rewind)
|
645
|
+
@input << "gen\n"
|
646
|
+
@input.rewind
|
647
|
+
|
648
|
+
answer = @terminal.ask("Select a mode: ", [:generate, :run])
|
649
|
+
assert_instance_of(Symbol, answer)
|
650
|
+
assert_equal(:generate, answer)
|
651
|
+
end
|
652
|
+
|
653
|
+
def test_validation
|
654
|
+
@input << "system 'rm -rf /'\n105\n0b101_001\n"
|
655
|
+
@input.rewind
|
656
|
+
|
657
|
+
answer = @terminal.ask("Enter a binary number: ") do |q|
|
658
|
+
q.validate = /\A(?:0b)?[01_]+\Z/
|
659
|
+
end
|
660
|
+
assert_equal("0b101_001", answer)
|
661
|
+
assert_equal( "Enter a binary number: " +
|
662
|
+
"Your answer isn't valid " +
|
663
|
+
"(must match /\\A(?:0b)?[01_]+\\Z/).\n" +
|
664
|
+
"? " +
|
665
|
+
"Your answer isn't valid " +
|
666
|
+
"(must match /\\A(?:0b)?[01_]+\\Z/).\n" +
|
667
|
+
"? ", @output.string )
|
668
|
+
|
669
|
+
@input.truncate(@input.rewind)
|
670
|
+
@input << "Gray II, James Edward\n" +
|
671
|
+
"Gray, Dana Ann Leslie\n" +
|
672
|
+
"Gray, James Edward\n"
|
673
|
+
@input.rewind
|
674
|
+
|
675
|
+
answer = @terminal.ask("Your name? ") do |q|
|
676
|
+
q.validate = lambda do |name|
|
677
|
+
names = name.split(/,\s*/)
|
678
|
+
return false unless names.size == 2
|
679
|
+
return false if names.first =~ /\s/
|
680
|
+
names.last.split.size == 2
|
681
|
+
end
|
682
|
+
end
|
683
|
+
assert_equal("Gray, James Edward", answer)
|
684
|
+
end
|
685
|
+
|
686
|
+
def test_whitespace
|
687
|
+
@input << " A lot\tof \t space\t \there! \n"
|
688
|
+
@input.rewind
|
689
|
+
|
690
|
+
answer = @terminal.ask("Enter a whitespace filled string: ") do |q|
|
691
|
+
q.whitespace = :chomp
|
692
|
+
end
|
693
|
+
assert_equal(" A lot\tof \t space\t \there! ", answer)
|
694
|
+
|
695
|
+
@input.rewind
|
696
|
+
|
697
|
+
answer = @terminal.ask("Enter a whitespace filled string: ")
|
698
|
+
assert_equal("A lot\tof \t space\t \there!", answer)
|
699
|
+
|
700
|
+
@input.rewind
|
701
|
+
|
702
|
+
answer = @terminal.ask("Enter a whitespace filled string: ") do |q|
|
703
|
+
q.whitespace = :strip_and_collapse
|
704
|
+
end
|
705
|
+
assert_equal("A lot of space here!", answer)
|
706
|
+
|
707
|
+
@input.rewind
|
708
|
+
|
709
|
+
answer = @terminal.ask("Enter a whitespace filled string: ") do |q|
|
710
|
+
q.whitespace = :remove
|
711
|
+
end
|
712
|
+
assert_equal("Alotofspacehere!", answer)
|
713
|
+
|
714
|
+
@input.rewind
|
715
|
+
|
716
|
+
answer = @terminal.ask("Enter a whitespace filled string: ") do |q|
|
717
|
+
q.whitespace = :none
|
718
|
+
end
|
719
|
+
assert_equal(" A lot\tof \t space\t \there! \n", answer)
|
720
|
+
end
|
721
|
+
|
722
|
+
def test_wrap
|
723
|
+
@terminal.wrap_at = 80
|
724
|
+
|
725
|
+
@terminal.say("This is a very short line.")
|
726
|
+
assert_equal("This is a very short line.\n", @output.string)
|
727
|
+
|
728
|
+
@output.truncate(@output.rewind)
|
729
|
+
|
730
|
+
@terminal.say( "This is a long flowing paragraph meant to span " +
|
731
|
+
"several lines. This text should definitely be " +
|
732
|
+
"wrapped at the set limit, in the result. Your code " +
|
733
|
+
"does well with things like this.\n\n" +
|
734
|
+
" * This is a simple embedded list.\n" +
|
735
|
+
" * You're code should not mess with this...\n" +
|
724
736
|
" * Because it's already formatted correctly and " +
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
737
|
+
"does not\n" +
|
738
|
+
" exceed the limit!" )
|
739
|
+
assert_equal( "This is a long flowing paragraph meant to span " +
|
740
|
+
"several lines. This text should\n" +
|
741
|
+
"definitely be wrapped at the set limit, in the " +
|
742
|
+
"result. Your code does well with\n" +
|
743
|
+
"things like this.\n\n" +
|
744
|
+
" * This is a simple embedded list.\n" +
|
745
|
+
" * You're code should not mess with this...\n" +
|
746
|
+
" * Because it's already formatted correctly and does " +
|
747
|
+
"not\n" +
|
748
|
+
" exceed the limit!\n", @output.string )
|
749
|
+
|
750
|
+
@output.truncate(@output.rewind)
|
751
|
+
|
752
|
+
@terminal.say("-=" * 50)
|
753
|
+
assert_equal(("-=" * 40 + "\n") + ("-=" * 10 + "\n"), @output.string)
|
754
|
+
end
|
743
755
|
end
|