highline 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +19 -1
- data/INSTALL +15 -2
- data/README +5 -5
- data/Rakefile +8 -2
- data/TODO +2 -7
- data/examples/ansi_colors.rb +32 -0
- data/examples/basic_usage.rb +22 -4
- data/lib/highline.rb +153 -22
- data/lib/highline/question.rb +95 -41
- data/setup.rb +1360 -0
- data/test/tc_highline.rb +141 -0
- metadata +4 -2
data/test/tc_highline.rb
CHANGED
@@ -28,6 +28,12 @@ class TestHighLine < Test::Unit::TestCase
|
|
28
28
|
assert_equal(true, @terminal.agree("Yes or no? "))
|
29
29
|
assert_equal(true, @terminal.agree("Yes or no? "))
|
30
30
|
assert_equal(false, @terminal.agree("Yes or no? "))
|
31
|
+
|
32
|
+
@input.truncate(@input.rewind)
|
33
|
+
@input << "yellow"
|
34
|
+
@input.rewind
|
35
|
+
|
36
|
+
assert_equal(true, @terminal.agree("Yes or no? ", :getc))
|
31
37
|
end
|
32
38
|
|
33
39
|
def test_ask
|
@@ -38,6 +44,41 @@ class TestHighLine < Test::Unit::TestCase
|
|
38
44
|
assert_equal(name, @terminal.ask("What is your name? "))
|
39
45
|
end
|
40
46
|
|
47
|
+
def test_character_reading
|
48
|
+
# WARNING: This method does NOT cover Unix and Windows savvy testing!
|
49
|
+
@input << "12345"
|
50
|
+
@input.rewind
|
51
|
+
|
52
|
+
answer = @terminal.ask("Enter a single digit: ", Integer) do |q|
|
53
|
+
q.character = :getc
|
54
|
+
end
|
55
|
+
assert_equal(1, answer)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_color
|
59
|
+
@terminal.say("This should be <%= BLUE %>blue<%= CLEAR %>!")
|
60
|
+
assert_equal("This should be \e[34mblue\e[0m!\n", @output.string)
|
61
|
+
|
62
|
+
@output.truncate(@output.rewind)
|
63
|
+
|
64
|
+
@terminal.say( "This should be " +
|
65
|
+
"<%= BOLD + ON_WHITE %>bold on white<%= CLEAR %>!" )
|
66
|
+
assert_equal( "This should be \e[1m\e[47mbold on white\e[0m!\n",
|
67
|
+
@output.string )
|
68
|
+
|
69
|
+
@output.truncate(@output.rewind)
|
70
|
+
|
71
|
+
@terminal.say("This should be <%= color('cyan', CYAN) %>!")
|
72
|
+
assert_equal("This should be \e[36mcyan\e[0m!\n", @output.string)
|
73
|
+
|
74
|
+
@output.truncate(@output.rewind)
|
75
|
+
|
76
|
+
@terminal.say( "This should be " +
|
77
|
+
"<%= color('blinking on red', :blink, :on_red) %>!" )
|
78
|
+
assert_equal( "This should be \e[5m\e[41mblinking on red\e[0m!\n",
|
79
|
+
@output.string )
|
80
|
+
end
|
81
|
+
|
41
82
|
def test_defaults
|
42
83
|
@input << "\nNo Comment\n"
|
43
84
|
@input.rewind
|
@@ -72,6 +113,53 @@ class TestHighLine < Test::Unit::TestCase
|
|
72
113
|
assert_equal("yes", answer)
|
73
114
|
end
|
74
115
|
|
116
|
+
def test_erb
|
117
|
+
@terminal.say( "The integers from 1 to 10 are:\n" +
|
118
|
+
"% (1...10).each do |n|\n" +
|
119
|
+
"\t<%= n %>,\n" +
|
120
|
+
"% end\n" +
|
121
|
+
"\tand 10" )
|
122
|
+
assert_equal( "The integers from 1 to 10 are:\n" +
|
123
|
+
"\t1,\n\t2,\n\t3,\n\t4,\n\t5,\n" +
|
124
|
+
"\t6,\n\t7,\n\t8,\n\t9,\n\tand 10\n",
|
125
|
+
@output.string )
|
126
|
+
end
|
127
|
+
|
128
|
+
class NameClass
|
129
|
+
def self.parse( string )
|
130
|
+
if string =~ /^\s*(\w+),\s*(\w+)\s+(\w+)\s*$/
|
131
|
+
self.new($2, $3, $1)
|
132
|
+
else
|
133
|
+
raise ArgumentError, "Invalid name format."
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def initialize(first, middle, last)
|
138
|
+
@first, @middle, @last = first, middle, last
|
139
|
+
end
|
140
|
+
|
141
|
+
attr_reader :first, :middle, :last
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_my_class_conversion
|
145
|
+
@input << "Gray, James Edward\n"
|
146
|
+
@input.rewind
|
147
|
+
|
148
|
+
|
149
|
+
answer = @terminal.ask("Your name? ", NameClass) do |q|
|
150
|
+
q.validate = lambda do |name|
|
151
|
+
names = name.split(/,\s*/)
|
152
|
+
return false unless names.size == 2
|
153
|
+
return false if names.first =~ /\s/
|
154
|
+
names.last.split.size == 2
|
155
|
+
end
|
156
|
+
end
|
157
|
+
assert_instance_of(NameClass, answer)
|
158
|
+
assert_equal("Gray", answer.last)
|
159
|
+
assert_equal("James", answer.first)
|
160
|
+
assert_equal("Edward", answer.middle)
|
161
|
+
end
|
162
|
+
|
75
163
|
def test_range_requirements
|
76
164
|
@input << "112\n-541\n28\n"
|
77
165
|
@input.rewind
|
@@ -183,6 +271,23 @@ class TestHighLine < Test::Unit::TestCase
|
|
183
271
|
"? ", @output.string)
|
184
272
|
end
|
185
273
|
|
274
|
+
def test_response_embedding
|
275
|
+
@input << "112\n-541\n28\n"
|
276
|
+
@input.rewind
|
277
|
+
|
278
|
+
answer = @terminal.ask("Tell me your age.", Integer) do |q|
|
279
|
+
q.in = 0..105
|
280
|
+
q.responses[:not_in_range] = "Need a <%= @question.answer_type %>" +
|
281
|
+
" <%= @question.expected_range %>."
|
282
|
+
end
|
283
|
+
assert_equal(28, answer)
|
284
|
+
assert_equal( "Tell me your age.\n" +
|
285
|
+
"Need a Integer included in 0..105.\n" +
|
286
|
+
"? " +
|
287
|
+
"Need a Integer included in 0..105.\n" +
|
288
|
+
"? ", @output.string )
|
289
|
+
end
|
290
|
+
|
186
291
|
def test_say
|
187
292
|
@terminal.say("This will have a newline.")
|
188
293
|
assert_equal("This will have a newline.\n", @output.string)
|
@@ -298,4 +403,40 @@ class TestHighLine < Test::Unit::TestCase
|
|
298
403
|
end
|
299
404
|
assert_equal("Gray, James Edward", answer)
|
300
405
|
end
|
406
|
+
|
407
|
+
def test_whitespace
|
408
|
+
@input << " A lot\tof \t space\t \there! \n"
|
409
|
+
@input.rewind
|
410
|
+
|
411
|
+
answer = @terminal.ask("Enter a whitespace filled string: ") do |q|
|
412
|
+
q.whitespace = :chomp
|
413
|
+
end
|
414
|
+
assert_equal(" A lot\tof \t space\t \there! ", answer)
|
415
|
+
|
416
|
+
@input.rewind
|
417
|
+
|
418
|
+
answer = @terminal.ask("Enter a whitespace filled string: ")
|
419
|
+
assert_equal("A lot\tof \t space\t \there!", answer)
|
420
|
+
|
421
|
+
@input.rewind
|
422
|
+
|
423
|
+
answer = @terminal.ask("Enter a whitespace filled string: ") do |q|
|
424
|
+
q.whitespace = :strip_and_collapse
|
425
|
+
end
|
426
|
+
assert_equal("A lot of space here!", answer)
|
427
|
+
|
428
|
+
@input.rewind
|
429
|
+
|
430
|
+
answer = @terminal.ask("Enter a whitespace filled string: ") do |q|
|
431
|
+
q.whitespace = :remove
|
432
|
+
end
|
433
|
+
assert_equal("Alotofspacehere!", answer)
|
434
|
+
|
435
|
+
@input.rewind
|
436
|
+
|
437
|
+
answer = @terminal.ask("Enter a whitespace filled string: ") do |q|
|
438
|
+
q.whitespace = :none
|
439
|
+
end
|
440
|
+
assert_equal(" A lot\tof \t space\t \there! \n", answer)
|
441
|
+
end
|
301
442
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: highline
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2005-04
|
6
|
+
version: 0.3.0
|
7
|
+
date: 2005-05-04
|
8
8
|
summary: HighLine is a high-level line oriented console interface.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,6 +29,7 @@ platform: ruby
|
|
29
29
|
authors:
|
30
30
|
- James Edward Gray II
|
31
31
|
files:
|
32
|
+
- examples/ansi_colors.rb
|
32
33
|
- examples/basic_usage.rb
|
33
34
|
- lib/highline.rb
|
34
35
|
- lib/highline/import.rb
|
@@ -37,6 +38,7 @@ files:
|
|
37
38
|
- test/tc_import.rb
|
38
39
|
- test/ts_all.rb
|
39
40
|
- Rakefile
|
41
|
+
- setup.rb
|
40
42
|
- README
|
41
43
|
- INSTALL
|
42
44
|
- TODO
|