highline 1.6.1 → 1.6.14
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/.gitignore +2 -0
- data/AUTHORS +3 -0
- data/CHANGELOG +76 -0
- data/COPYING +340 -0
- data/Rakefile +9 -41
- data/doc/.cvsignore +1 -0
- data/examples/ansi_colors.rb +1 -1
- data/examples/asking_for_arrays.rb +1 -1
- data/examples/basic_usage.rb +1 -1
- data/examples/menus.rb +1 -1
- data/examples/overwrite.rb +1 -1
- data/examples/page_and_wrap.rb +1 -1
- data/examples/password.rb +1 -1
- data/examples/repeat_entry.rb +21 -0
- data/examples/trapping_eof.rb +1 -1
- data/examples/using_readline.rb +1 -1
- data/highline.gemspec +36 -0
- data/lib/highline/color_scheme.rb +20 -4
- data/lib/highline/import.rb +0 -2
- data/lib/highline/menu.rb +7 -6
- data/lib/highline/question.rb +17 -7
- data/lib/highline/simulate.rb +48 -0
- data/lib/highline/string_extensions.rb +131 -0
- data/lib/highline/style.rb +181 -0
- data/lib/highline/system_extensions.rb +106 -100
- data/lib/highline.rb +406 -202
- data/site/.cvsignore +1 -0
- data/site/highline.css +65 -0
- data/site/images/logo.png +0 -0
- data/site/index.html +58 -0
- data/test/string_methods.rb +32 -0
- data/test/tc_color_scheme.rb +42 -2
- data/test/tc_highline.rb +215 -11
- data/test/tc_import.rb +0 -2
- data/test/tc_menu.rb +0 -2
- data/test/tc_string_extension.rb +20 -0
- data/test/tc_string_highline.rb +38 -0
- data/test/tc_style.rb +567 -0
- data/test/ts_all.rb +3 -2
- metadata +62 -52
- /data/{README → README.rdoc} +0 -0
data/site/.cvsignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.DS_Store
|
data/site/highline.css
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
body {
|
|
2
|
+
margin: 0;
|
|
3
|
+
padding: 0;
|
|
4
|
+
text-align: center;
|
|
5
|
+
background: #abc;
|
|
6
|
+
font: 13px Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
#container {
|
|
10
|
+
margin: 0 auto;
|
|
11
|
+
margin-top: 10px;
|
|
12
|
+
position: relative;
|
|
13
|
+
width: 785px;
|
|
14
|
+
background: #fff repeat;
|
|
15
|
+
padding-top: 20px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
#container #header {
|
|
19
|
+
padding-top: 20px;
|
|
20
|
+
height: 141px;
|
|
21
|
+
width: 785px;
|
|
22
|
+
background: url(images/logo.png) center no-repeat;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#container #content {
|
|
26
|
+
text-align: left;
|
|
27
|
+
margin-left: 230px;
|
|
28
|
+
width: 500px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
#container #sidebar {
|
|
32
|
+
text-align: left;
|
|
33
|
+
position: absolute;
|
|
34
|
+
top: 181px;
|
|
35
|
+
left: 0;
|
|
36
|
+
width: 170px;
|
|
37
|
+
margin-right: 25px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#container #footer {
|
|
41
|
+
font: 9px Arial;
|
|
42
|
+
padding: 4px;
|
|
43
|
+
border-top: 1px solid;
|
|
44
|
+
color: #aaa;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
ul {
|
|
48
|
+
list-style: none;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
li {
|
|
52
|
+
border-bottom: 1px solid #e8e8e8;
|
|
53
|
+
padding-top: 10px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
a {
|
|
57
|
+
text-decoration: none;
|
|
58
|
+
color: #15528a;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
pre {
|
|
62
|
+
padding: 5px;
|
|
63
|
+
padding-left: 20px;
|
|
64
|
+
font: 11px Courier;
|
|
65
|
+
}
|
|
Binary file
|
data/site/index.html
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<title> HighLine </title>
|
|
4
|
+
<style type="text/css"> @import url(highline.css); </style>
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
7
|
+
<div id="container">
|
|
8
|
+
<div id="header"></div>
|
|
9
|
+
<div id="content">
|
|
10
|
+
<h2>HighLine is about…</h2>
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
<h3>Saving time.</h3>
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
<p>Command line interfaces are meant to be easy. So why shouldn’t building
|
|
17
|
+
them be easy, too? HighLine provides a solid toolset to help you get
|
|
18
|
+
the job done cleanly so you can focus on the real task at hand,
|
|
19
|
+
<em>your task.</em></p>
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
<h3>Clean and intuitive design.</h3>
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
<p>Want to get a taste for how HighLine is used? Take a look at this simple
|
|
26
|
+
example, which asks a user for a zip code, automatically does validation,
|
|
27
|
+
and returns the result:</p>
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
<pre><code>zip = ask("Zip? ") { |q| q.validate = /\A\d{5}(?:-?\d{4})?\Z/ }</code></pre>
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
<h3>Hassle-free Installation.</h3>
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
<p>Installation is easy via RubyGems. Simply enter the command:</p>
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
<pre><code>sudo gem install highline</code></pre>
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
<p>and you’ll be on your way! Of course, manual installation is an option,
|
|
43
|
+
too.</p>
|
|
44
|
+
</div>
|
|
45
|
+
<div id="sidebar">
|
|
46
|
+
<ul>
|
|
47
|
+
<li><a href="http://rubyforge.org/projects/highline">Project Page</a></li>
|
|
48
|
+
<li><a href="http://highline.rubyforge.org/doc">Documentation</a></li>
|
|
49
|
+
<li><a href="https://github.com/JEG2/highline">Source</a></li>
|
|
50
|
+
<li><a href="mailto:james@grayproductions.net">Contact</a></li>
|
|
51
|
+
</ul>
|
|
52
|
+
</div>
|
|
53
|
+
<div id="footer">
|
|
54
|
+
Created by James Edward Gray II and Gregory Brown
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</body>
|
|
58
|
+
</html>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# string_methods.rb
|
|
2
|
+
#
|
|
3
|
+
# Created by Richard LeBer 2011-06-27
|
|
4
|
+
#
|
|
5
|
+
# This is Free Software. See LICENSE and COPYING for details.
|
|
6
|
+
#
|
|
7
|
+
# String class convenience methods
|
|
8
|
+
|
|
9
|
+
module StringMethods
|
|
10
|
+
def test_color
|
|
11
|
+
assert_equal("\e[34mstring\e[0m", @string.color(:blue))
|
|
12
|
+
assert_equal("\e[1m\e[47mstring\e[0m", @string.color(:bold,:on_white))
|
|
13
|
+
assert_equal("\e[45mstring\e[0m", @string.on(:magenta))
|
|
14
|
+
assert_equal("\e[36mstring\e[0m", @string.cyan)
|
|
15
|
+
assert_equal("\e[41m\e[5mstring\e[0m\e[0m", @string.blink.on_red)
|
|
16
|
+
assert_equal("\e[38;5;137mstring\e[0m", @string.color(:rgb_906030))
|
|
17
|
+
assert_equal("\e[38;5;101mstring\e[0m", @string.rgb('606030'))
|
|
18
|
+
assert_equal("\e[38;5;107mstring\e[0m", @string.rgb('60','90','30'))
|
|
19
|
+
assert_equal("\e[38;5;107mstring\e[0m", @string.rgb(96,144,48))
|
|
20
|
+
assert_equal("\e[38;5;173mstring\e[0m", @string.rgb_c06030)
|
|
21
|
+
assert_equal("\e[48;5;137mstring\e[0m", @string.color(:on_rgb_906030))
|
|
22
|
+
assert_equal("\e[48;5;101mstring\e[0m", @string.on_rgb('606030'))
|
|
23
|
+
assert_equal("\e[48;5;107mstring\e[0m", @string.on_rgb('60','90','30'))
|
|
24
|
+
assert_equal("\e[48;5;107mstring\e[0m", @string.on_rgb(96,144,48))
|
|
25
|
+
assert_equal("\e[48;5;173mstring\e[0m", @string.on_rgb_c06030)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_uncolor
|
|
29
|
+
colored_string = HighLine::String("\e[38;5;137mstring\e[0m")
|
|
30
|
+
assert_equal "string", colored_string.uncolor
|
|
31
|
+
end
|
|
32
|
+
end
|
data/test/tc_color_scheme.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#!/usr/local/bin/ruby -w
|
|
2
|
-
|
|
3
1
|
# tc_color_scheme.rb
|
|
4
2
|
#
|
|
5
3
|
# Created by Jeremy Hinegardner on 2007-01-24.
|
|
@@ -46,6 +44,48 @@ class TestColorScheme < Test::Unit::TestCase
|
|
|
46
44
|
@terminal.say("This should be <%= color('warning yellow', 'WarNing') %>.")
|
|
47
45
|
assert_equal("This should be \e[1m\e[33mwarning yellow\e[0m.\n",@output.string)
|
|
48
46
|
@output.rewind
|
|
47
|
+
|
|
48
|
+
# Check that keys are available, and as expected
|
|
49
|
+
assert_equal ["critical", "error", "warning", "notice", "info", "debug", "row_even", "row_odd"].sort,
|
|
50
|
+
HighLine.color_scheme.keys.sort
|
|
51
|
+
|
|
52
|
+
# Color scheme doesn't care if we use symbols or strings, and is case-insensitive
|
|
53
|
+
warning1 = HighLine.color_scheme[:warning]
|
|
54
|
+
warning2 = HighLine.color_scheme["warning"]
|
|
55
|
+
warning3 = HighLine.color_scheme[:wArning]
|
|
56
|
+
warning4 = HighLine.color_scheme["warniNg"]
|
|
57
|
+
assert_instance_of HighLine::Style, warning1
|
|
58
|
+
assert_instance_of HighLine::Style, warning2
|
|
59
|
+
assert_instance_of HighLine::Style, warning3
|
|
60
|
+
assert_instance_of HighLine::Style, warning4
|
|
61
|
+
assert_equal warning1, warning2
|
|
62
|
+
assert_equal warning1, warning3
|
|
63
|
+
assert_equal warning1, warning4
|
|
64
|
+
|
|
65
|
+
# Nonexistent keys return nil
|
|
66
|
+
assert_nil HighLine.color_scheme[:nonexistent]
|
|
67
|
+
|
|
68
|
+
# Same as above, for definitions
|
|
69
|
+
defn1 = HighLine.color_scheme.definition(:warning)
|
|
70
|
+
defn2 = HighLine.color_scheme.definition("warning")
|
|
71
|
+
defn3 = HighLine.color_scheme.definition(:wArning)
|
|
72
|
+
defn4 = HighLine.color_scheme.definition("warniNg")
|
|
73
|
+
assert_instance_of Array, defn1
|
|
74
|
+
assert_instance_of Array, defn2
|
|
75
|
+
assert_instance_of Array, defn3
|
|
76
|
+
assert_instance_of Array, defn4
|
|
77
|
+
assert_equal [:bold, :yellow], defn1
|
|
78
|
+
assert_equal [:bold, :yellow], defn2
|
|
79
|
+
assert_equal [:bold, :yellow], defn3
|
|
80
|
+
assert_equal [:bold, :yellow], defn4
|
|
81
|
+
assert_nil HighLine.color_scheme.definition(:nonexistent)
|
|
82
|
+
|
|
83
|
+
color_scheme_hash = HighLine.color_scheme.to_hash
|
|
84
|
+
assert_instance_of Hash, color_scheme_hash
|
|
85
|
+
assert_equal ["critical", "error", "warning", "notice", "info", "debug", "row_even", "row_odd"].sort,
|
|
86
|
+
color_scheme_hash.keys.sort
|
|
87
|
+
assert_instance_of Array, HighLine.color_scheme.definition(:warning)
|
|
88
|
+
assert_equal [:bold, :yellow], HighLine.color_scheme.definition(:warning)
|
|
49
89
|
|
|
50
90
|
# turn it back off, should raise an exception
|
|
51
91
|
HighLine.color_scheme = @old_color_scheme
|
data/test/tc_highline.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#!/usr/local/bin/ruby -w
|
|
2
|
-
|
|
3
1
|
# tc_highline.rb
|
|
4
2
|
#
|
|
5
3
|
# Created by James Edward Gray II on 2005-04-26.
|
|
@@ -62,6 +60,16 @@ class TestHighLine < Test::Unit::TestCase
|
|
|
62
60
|
assert_raise(EOFError) { @terminal.ask("Any input left? ") }
|
|
63
61
|
end
|
|
64
62
|
|
|
63
|
+
def test_ask_string
|
|
64
|
+
name = "James Edward Gray II"
|
|
65
|
+
@input << name << "\n"
|
|
66
|
+
@input.rewind
|
|
67
|
+
|
|
68
|
+
assert_equal(name, @terminal.ask("What is your name? ", String))
|
|
69
|
+
|
|
70
|
+
assert_raise(EOFError) { @terminal.ask("Any input left? ", String) }
|
|
71
|
+
end
|
|
72
|
+
|
|
65
73
|
def test_bug_fixes
|
|
66
74
|
# auto-complete bug
|
|
67
75
|
@input << "ruby\nRuby\n"
|
|
@@ -198,6 +206,28 @@ class TestHighLine < Test::Unit::TestCase
|
|
|
198
206
|
|
|
199
207
|
@output.truncate(@output.rewind)
|
|
200
208
|
|
|
209
|
+
@terminal.say("This should be <%= NONE %>none<%= CLEAR %>!")
|
|
210
|
+
assert_equal("This should be \e[38mnone\e[0m!\n", @output.string)
|
|
211
|
+
|
|
212
|
+
@output.truncate(@output.rewind)
|
|
213
|
+
|
|
214
|
+
@terminal.say("This should be <%= RGB_906030 %>rgb_906030<%= CLEAR %>!")
|
|
215
|
+
assert_equal("This should be \e[38;5;137mrgb_906030\e[0m!\n", @output.string)
|
|
216
|
+
|
|
217
|
+
@output.truncate(@output.rewind)
|
|
218
|
+
|
|
219
|
+
@terminal.say("This should be <%= ON_RGB_C06030 %>on_rgb_c06030<%= CLEAR %>!")
|
|
220
|
+
assert_equal("This should be \e[48;5;173mon_rgb_c06030\e[0m!\n", @output.string)
|
|
221
|
+
|
|
222
|
+
@output.truncate(@output.rewind)
|
|
223
|
+
|
|
224
|
+
# Does class method work, too?
|
|
225
|
+
@terminal.say("This should be <%= HighLine.color('reverse underlined magenta', :reverse, :underline, :magenta) %>!")
|
|
226
|
+
assert_equal( "This should be \e[7m\e[4m\e[35mreverse underlined magenta\e[0m!\n",
|
|
227
|
+
@output.string )
|
|
228
|
+
|
|
229
|
+
@output.truncate(@output.rewind)
|
|
230
|
+
|
|
201
231
|
# turn off color
|
|
202
232
|
old_setting = HighLine.use_color?
|
|
203
233
|
assert_nothing_raised(Exception) { HighLine.use_color = false }
|
|
@@ -205,6 +235,27 @@ class TestHighLine < Test::Unit::TestCase
|
|
|
205
235
|
assert_equal("This should be cyan!\n", @output.string)
|
|
206
236
|
HighLine.use_color = old_setting
|
|
207
237
|
end
|
|
238
|
+
|
|
239
|
+
def test_uncolor
|
|
240
|
+
# instance method
|
|
241
|
+
assert_equal( "This should be reverse underlined magenta!\n",
|
|
242
|
+
@terminal.uncolor("This should be \e[7m\e[4m\e[35mreverse underlined magenta\e[0m!\n")
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
@output.truncate(@output.rewind)
|
|
246
|
+
|
|
247
|
+
# class method
|
|
248
|
+
assert_equal( "This should be reverse underlined magenta!\n",
|
|
249
|
+
HighLine.uncolor("This should be \e[7m\e[4m\e[35mreverse underlined magenta\e[0m!\n")
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
@output.truncate(@output.rewind)
|
|
253
|
+
|
|
254
|
+
# RGB color
|
|
255
|
+
assert_equal( "This should be rgb_906030!\n",
|
|
256
|
+
@terminal.uncolor("This should be \e[38;5;137mrgb_906030\e[0m!\n")
|
|
257
|
+
)
|
|
258
|
+
end
|
|
208
259
|
|
|
209
260
|
def test_confirm
|
|
210
261
|
@input << "junk.txt\nno\nsave.txt\ny\n"
|
|
@@ -257,7 +308,19 @@ class TestHighLine < Test::Unit::TestCase
|
|
|
257
308
|
assert_equal( "Are you sexually active? |No Comment| ",
|
|
258
309
|
@output.string )
|
|
259
310
|
end
|
|
260
|
-
|
|
311
|
+
|
|
312
|
+
def test_string_preservation
|
|
313
|
+
@input << "Maybe\nYes\n"
|
|
314
|
+
@input.rewind
|
|
315
|
+
|
|
316
|
+
my_string = "Is that your final answer? "
|
|
317
|
+
|
|
318
|
+
@terminal.ask(my_string) { |q| q.default = "Possibly" }
|
|
319
|
+
@terminal.ask(my_string) { |q| q.default = "Maybe" }
|
|
320
|
+
|
|
321
|
+
assert_equal("Is that your final answer? ", my_string)
|
|
322
|
+
end
|
|
323
|
+
|
|
261
324
|
def test_empty
|
|
262
325
|
@input << "\n"
|
|
263
326
|
@input.rewind
|
|
@@ -284,14 +347,15 @@ class TestHighLine < Test::Unit::TestCase
|
|
|
284
347
|
def test_files
|
|
285
348
|
@input << "#{File.basename(__FILE__)[0, 5]}\n"
|
|
286
349
|
@input.rewind
|
|
350
|
+
|
|
351
|
+
assert_equal "tc_hi\n",@input.read
|
|
352
|
+
@input.rewind
|
|
287
353
|
|
|
288
354
|
file = @terminal.ask("Select a file: ", File) do |q|
|
|
289
355
|
q.directory = File.expand_path(File.dirname(__FILE__))
|
|
290
356
|
q.glob = "*.rb"
|
|
291
357
|
end
|
|
292
358
|
assert_instance_of(File, file)
|
|
293
|
-
assert_equal("#!/usr/local/bin/ruby -w\n", file.gets)
|
|
294
|
-
assert_equal("\n", file.gets)
|
|
295
359
|
assert_equal("# tc_highline.rb\n", file.gets)
|
|
296
360
|
file.close
|
|
297
361
|
|
|
@@ -342,15 +406,72 @@ class TestHighLine < Test::Unit::TestCase
|
|
|
342
406
|
answers )
|
|
343
407
|
assert_equal("Age: Father's Age: Wife's Age: ", @output.string)
|
|
344
408
|
end
|
|
345
|
-
|
|
409
|
+
|
|
410
|
+
def test_typing_verification
|
|
411
|
+
@input << "all work and no play makes jack a dull boy\n" * 3
|
|
412
|
+
@input.rewind
|
|
413
|
+
|
|
414
|
+
answer = @terminal.ask("How's work? ") do |q|
|
|
415
|
+
q.gather = 3
|
|
416
|
+
q.verify_match = true
|
|
417
|
+
end
|
|
418
|
+
assert_equal("all work and no play makes jack a dull boy", answer)
|
|
419
|
+
|
|
420
|
+
@input.truncate(@input.rewind)
|
|
421
|
+
@input << "all play and no work makes jack a mere toy\n"
|
|
422
|
+
@input << "all work and no play makes jack a dull boy\n" * 5
|
|
423
|
+
@input.rewind
|
|
424
|
+
@output.truncate(@output.rewind)
|
|
425
|
+
|
|
426
|
+
answer = @terminal.ask("How are things going? ") do |q|
|
|
427
|
+
q.gather = 3
|
|
428
|
+
q.verify_match = true
|
|
429
|
+
q.responses[:mismatch] = 'Typing mismatch!'
|
|
430
|
+
q.responses[:ask_on_error] = ''
|
|
431
|
+
end
|
|
432
|
+
assert_equal("all work and no play makes jack a dull boy", answer)
|
|
433
|
+
|
|
434
|
+
# now try using a hash for gather
|
|
435
|
+
|
|
436
|
+
@input.truncate(@input.rewind)
|
|
437
|
+
@input << "Password\nPassword\n"
|
|
438
|
+
@input.rewind
|
|
439
|
+
@output.truncate(@output.rewind)
|
|
440
|
+
|
|
441
|
+
answer = @terminal.ask("<%= @key %>: ") do |q|
|
|
442
|
+
q.verify_match = true
|
|
443
|
+
q.gather = {"Enter a password" => '', "Please type it again" => ''}
|
|
444
|
+
end
|
|
445
|
+
assert_equal("Password", answer)
|
|
446
|
+
|
|
447
|
+
@input.truncate(@input.rewind)
|
|
448
|
+
@input << "Password\nMistake\nPassword\nPassword\n"
|
|
449
|
+
@input.rewind
|
|
450
|
+
@output.truncate(@output.rewind)
|
|
451
|
+
|
|
452
|
+
answer = @terminal.ask("<%= @key %>: ") do |q|
|
|
453
|
+
q.verify_match = true
|
|
454
|
+
q.responses[:mismatch] = 'Typing mismatch!'
|
|
455
|
+
q.responses[:ask_on_error] = ''
|
|
456
|
+
q.gather = {"Enter a password" => '', "Please type it again" => ''}
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
assert_equal("Password", answer)
|
|
460
|
+
assert_equal( "Enter a password: " +
|
|
461
|
+
"Please type it again: " +
|
|
462
|
+
"Typing mismatch!\n" +
|
|
463
|
+
"Enter a password: " +
|
|
464
|
+
"Please type it again: ", @output.string )
|
|
465
|
+
end
|
|
466
|
+
|
|
346
467
|
def test_lists
|
|
347
468
|
digits = %w{Zero One Two Three Four Five Six Seven Eight Nine}
|
|
348
469
|
erb_digits = digits.dup
|
|
349
470
|
erb_digits[erb_digits.index("Five")] = "<%= color('Five', :blue) %%>"
|
|
350
|
-
|
|
471
|
+
|
|
351
472
|
@terminal.say("<%= list(#{digits.inspect}) %>")
|
|
352
473
|
assert_equal(digits.map { |d| "#{d}\n" }.join, @output.string)
|
|
353
|
-
|
|
474
|
+
|
|
354
475
|
@output.truncate(@output.rewind)
|
|
355
476
|
|
|
356
477
|
@terminal.say("<%= list(#{digits.inspect}, :inline) %>")
|
|
@@ -368,7 +489,7 @@ class TestHighLine < Test::Unit::TestCase
|
|
|
368
489
|
@terminal.say("<%= list(#{digits.inspect}, :columns_down, 3) %>")
|
|
369
490
|
assert_equal( "Zero Four Eight\n" +
|
|
370
491
|
"One Five Nine \n" +
|
|
371
|
-
"Two Six \n"
|
|
492
|
+
"Two Six \n" +
|
|
372
493
|
"Three Seven\n",
|
|
373
494
|
@output.string )
|
|
374
495
|
|
|
@@ -387,7 +508,7 @@ class TestHighLine < Test::Unit::TestCase
|
|
|
387
508
|
|
|
388
509
|
@terminal.say("<%= list(#{colums_of_twenty.inspect}, :columns_down) %>")
|
|
389
510
|
assert_equal( "12345678901234567890 12345678901234567890 " +
|
|
390
|
-
"12345678901234567890\n"
|
|
511
|
+
"12345678901234567890\n" +
|
|
391
512
|
"12345678901234567890 12345678901234567890\n",
|
|
392
513
|
@output.string )
|
|
393
514
|
|
|
@@ -409,6 +530,89 @@ class TestHighLine < Test::Unit::TestCase
|
|
|
409
530
|
"12345678901234567890\n" +
|
|
410
531
|
"12345678901234567890\n",
|
|
411
532
|
@output.string )
|
|
533
|
+
|
|
534
|
+
@output.truncate(@output.rewind)
|
|
535
|
+
|
|
536
|
+
wide = %w[0123456789 a b c d e f g h i j k l m n o p q r s t u v w x y z]
|
|
537
|
+
|
|
538
|
+
@terminal.say("<%= list( #{wide.inspect}, :uneven_columns_across ) %>")
|
|
539
|
+
assert_equal( "0123456789 a b c d e f g h i j k l m n o " +
|
|
540
|
+
"p q r s t u v w\n" +
|
|
541
|
+
"x y z\n",
|
|
542
|
+
@output.string )
|
|
543
|
+
|
|
544
|
+
@output.truncate(@output.rewind)
|
|
545
|
+
|
|
546
|
+
@terminal.say("<%= list( #{wide.inspect}, :uneven_columns_across, 10 ) %>")
|
|
547
|
+
assert_equal( "0123456789 a b c d e f g h i\n" +
|
|
548
|
+
"j k l m n o p q r s\n" +
|
|
549
|
+
"t u v w x y z\n",
|
|
550
|
+
@output.string )
|
|
551
|
+
|
|
552
|
+
@output.truncate(@output.rewind)
|
|
553
|
+
|
|
554
|
+
@terminal.say("<%= list( #{wide.inspect}, :uneven_columns_down ) %>")
|
|
555
|
+
assert_equal( "0123456789 b d f h j l n p r t v x z\n" +
|
|
556
|
+
"a c e g i k m o q s u w y\n",
|
|
557
|
+
@output.string )
|
|
558
|
+
|
|
559
|
+
@output.truncate(@output.rewind)
|
|
560
|
+
|
|
561
|
+
@terminal.say("<%= list( #{wide.inspect}, :uneven_columns_down, 10 ) %>")
|
|
562
|
+
assert_equal( "0123456789 c f i l o r u x\n" +
|
|
563
|
+
"a d g j m p s v y\n" +
|
|
564
|
+
"b e h k n q t w z\n",
|
|
565
|
+
@output.string )
|
|
566
|
+
end
|
|
567
|
+
|
|
568
|
+
def test_lists_with_zero_items
|
|
569
|
+
modes = [nil, :rows, :inline, :columns_across, :columns_down]
|
|
570
|
+
modes.each do |mode|
|
|
571
|
+
result = @terminal.list([], mode)
|
|
572
|
+
assert_equal("", result)
|
|
573
|
+
end
|
|
574
|
+
end
|
|
575
|
+
|
|
576
|
+
def test_lists_with_one_item
|
|
577
|
+
items = ['Zero']
|
|
578
|
+
modes = { nil => "Zero\n",
|
|
579
|
+
:rows => "Zero\n",
|
|
580
|
+
:inline => "Zero",
|
|
581
|
+
:columns_across => "Zero\n",
|
|
582
|
+
:columns_down => "Zero\n" }
|
|
583
|
+
|
|
584
|
+
modes.each do |mode, expected|
|
|
585
|
+
result = @terminal.list(items, mode)
|
|
586
|
+
assert_equal(expected, result)
|
|
587
|
+
end
|
|
588
|
+
end
|
|
589
|
+
|
|
590
|
+
def test_lists_with_two_items
|
|
591
|
+
items = ['Zero', 'One']
|
|
592
|
+
modes = { nil => "Zero\nOne\n",
|
|
593
|
+
:rows => "Zero\nOne\n",
|
|
594
|
+
:inline => "Zero or One",
|
|
595
|
+
:columns_across => "Zero One \n",
|
|
596
|
+
:columns_down => "Zero One \n" }
|
|
597
|
+
|
|
598
|
+
modes.each do |mode, expected|
|
|
599
|
+
result = @terminal.list(items, mode)
|
|
600
|
+
assert_equal(expected, result)
|
|
601
|
+
end
|
|
602
|
+
end
|
|
603
|
+
|
|
604
|
+
def test_lists_with_three_items
|
|
605
|
+
items = ['Zero', 'One', 'Two']
|
|
606
|
+
modes = { nil => "Zero\nOne\nTwo\n",
|
|
607
|
+
:rows => "Zero\nOne\nTwo\n",
|
|
608
|
+
:inline => "Zero, One or Two",
|
|
609
|
+
:columns_across => "Zero One Two \n",
|
|
610
|
+
:columns_down => "Zero One Two \n" }
|
|
611
|
+
|
|
612
|
+
modes.each do |mode, expected|
|
|
613
|
+
result = @terminal.list(items, mode)
|
|
614
|
+
assert_equal(expected, result)
|
|
615
|
+
end
|
|
412
616
|
end
|
|
413
617
|
|
|
414
618
|
def test_mode
|
|
@@ -818,6 +1022,6 @@ class TestHighLine < Test::Unit::TestCase
|
|
|
818
1022
|
assert_not_nil(HighLine::VERSION)
|
|
819
1023
|
assert_instance_of(String, HighLine::VERSION)
|
|
820
1024
|
assert(HighLine::VERSION.frozen?)
|
|
821
|
-
assert_match(/\A\d
|
|
1025
|
+
assert_match(/\A\d+\.\d+\.\d+\Z/, HighLine::VERSION)
|
|
822
1026
|
end
|
|
823
1027
|
end
|
data/test/tc_import.rb
CHANGED
data/test/tc_menu.rb
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# tc_string_extension.rb
|
|
2
|
+
#
|
|
3
|
+
# Created by Richard LeBer 2011-06-27
|
|
4
|
+
#
|
|
5
|
+
# This is Free Software. See LICENSE and COPYING for details.
|
|
6
|
+
|
|
7
|
+
require "test/unit"
|
|
8
|
+
|
|
9
|
+
require "highline"
|
|
10
|
+
require "stringio"
|
|
11
|
+
require "string_methods"
|
|
12
|
+
|
|
13
|
+
class TestStringExtension < Test::Unit::TestCase
|
|
14
|
+
def setup
|
|
15
|
+
HighLine.colorize_strings
|
|
16
|
+
@string = "string"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
include StringMethods
|
|
20
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# tc_highline_string.rb
|
|
2
|
+
#
|
|
3
|
+
# Created by Richard LeBer 2011-06-27
|
|
4
|
+
#
|
|
5
|
+
# This is Free Software. See LICENSE and COPYING for details.
|
|
6
|
+
|
|
7
|
+
require "test/unit"
|
|
8
|
+
|
|
9
|
+
require "highline"
|
|
10
|
+
require "stringio"
|
|
11
|
+
require "string_methods"
|
|
12
|
+
|
|
13
|
+
class TestHighLineString < Test::Unit::TestCase
|
|
14
|
+
def setup
|
|
15
|
+
@string = HighLine::String.new("string")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_string_class
|
|
19
|
+
# Basic constructor
|
|
20
|
+
assert_equal HighLine::String, @string.class
|
|
21
|
+
assert_equal "string", @string
|
|
22
|
+
|
|
23
|
+
# Alternative constructor method
|
|
24
|
+
new_string = HighLine::String("string")
|
|
25
|
+
assert_equal HighLine::String, new_string.class
|
|
26
|
+
assert_equal @string, new_string
|
|
27
|
+
|
|
28
|
+
# String methods work
|
|
29
|
+
assert_equal 6, @string.size
|
|
30
|
+
assert_equal "STRING", @string.upcase
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
include StringMethods
|
|
34
|
+
|
|
35
|
+
def test_string_class_is_unchanged
|
|
36
|
+
assert_raise(::NoMethodError) { "string".color(:blue) }
|
|
37
|
+
end
|
|
38
|
+
end
|