clone 1.0.0.alpha → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +1 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +22 -1
  6. data/VERSION +1 -1
  7. data/bin/clone +7 -0
  8. data/clone.gemspec +4 -0
  9. data/docs/readme +16 -0
  10. data/docs/readme.txt +5 -0
  11. data/lib/clone.rb +13 -2
  12. data/lib/clone/config/config.rb +19 -0
  13. data/lib/clone/config/config.yml +22 -0
  14. data/lib/clone/config/default_config.yml +20 -0
  15. data/lib/clone/config/require.rb +3 -0
  16. data/lib/clone/config/version.rb +10 -0
  17. data/lib/clone/config/yml.rb +22 -0
  18. data/lib/clone/config/z_defaults.rb +28 -0
  19. data/lib/clone/generator/engine.rb +581 -0
  20. data/lib/clone/generator/terminal.rb +104 -0
  21. data/lib/clone/helpers/helper_methods.rb +251 -0
  22. data/lib/clone/helpers/local_methods.rb +150 -0
  23. data/lib/clone/helpers/require.rb +37 -0
  24. data/module/Marshal.4.8 +0 -0
  25. data/module/Marshal.4.8.Z +0 -0
  26. data/module/gems/commander-4.1.3/.gitignore +6 -0
  27. data/module/gems/commander-4.1.3/.travis.yml +11 -0
  28. data/module/gems/commander-4.1.3/DEVELOPMENT +15 -0
  29. data/module/gems/commander-4.1.3/Gemfile +3 -0
  30. data/module/gems/commander-4.1.3/History.rdoc +345 -0
  31. data/module/gems/commander-4.1.3/Manifest +38 -0
  32. data/module/gems/commander-4.1.3/README.rdoc +375 -0
  33. data/module/gems/commander-4.1.3/Rakefile +10 -0
  34. data/module/gems/commander-4.1.3/bin/commander +55 -0
  35. data/module/gems/commander-4.1.3/commander.gemspec +26 -0
  36. data/module/gems/commander-4.1.3/lib/commander.rb +32 -0
  37. data/module/gems/commander-4.1.3/lib/commander/blank.rb +8 -0
  38. data/module/gems/commander-4.1.3/lib/commander/command.rb +213 -0
  39. data/module/gems/commander-4.1.3/lib/commander/core_ext.rb +3 -0
  40. data/module/gems/commander-4.1.3/lib/commander/core_ext/array.rb +26 -0
  41. data/module/gems/commander-4.1.3/lib/commander/core_ext/object.rb +11 -0
  42. data/module/gems/commander-4.1.3/lib/commander/delegates.rb +13 -0
  43. data/module/gems/commander-4.1.3/lib/commander/help_formatters.rb +8 -0
  44. data/module/gems/commander-4.1.3/lib/commander/help_formatters/base.rb +18 -0
  45. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal.rb +20 -0
  46. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal/command_help.erb +35 -0
  47. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal/help.erb +36 -0
  48. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact.rb +12 -0
  49. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact/command_help.erb +27 -0
  50. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact/help.erb +29 -0
  51. data/module/gems/commander-4.1.3/lib/commander/import.rb +10 -0
  52. data/module/gems/commander-4.1.3/lib/commander/platform.rb +8 -0
  53. data/module/gems/commander-4.1.3/lib/commander/runner.rb +411 -0
  54. data/module/gems/commander-4.1.3/lib/commander/user_interaction.rb +521 -0
  55. data/module/gems/commander-4.1.3/lib/commander/version.rb +3 -0
  56. data/module/gems/commander-4.1.3/spec/command_spec.rb +157 -0
  57. data/module/gems/commander-4.1.3/spec/core_ext/array_spec.rb +20 -0
  58. data/module/gems/commander-4.1.3/spec/core_ext/object_spec.rb +21 -0
  59. data/module/gems/commander-4.1.3/spec/help_formatters/terminal_spec.rb +67 -0
  60. data/module/gems/commander-4.1.3/spec/runner_spec.rb +526 -0
  61. data/module/gems/commander-4.1.3/spec/spec_helper.rb +59 -0
  62. data/module/gems/commander-4.1.3/spec/ui_spec.rb +30 -0
  63. data/module/gems/hello.rb +1 -0
  64. data/module/gems/highline-1.6.19/.gitignore +2 -0
  65. data/module/gems/highline-1.6.19/AUTHORS +3 -0
  66. data/module/gems/highline-1.6.19/CHANGELOG +346 -0
  67. data/module/gems/highline-1.6.19/COPYING +340 -0
  68. data/module/gems/highline-1.6.19/INSTALL +55 -0
  69. data/module/gems/highline-1.6.19/LICENSE +7 -0
  70. data/module/gems/highline-1.6.19/README.rdoc +63 -0
  71. data/module/gems/highline-1.6.19/Rakefile +50 -0
  72. data/module/gems/highline-1.6.19/TODO +6 -0
  73. data/module/gems/highline-1.6.19/examples/ansi_colors.rb +38 -0
  74. data/module/gems/highline-1.6.19/examples/asking_for_arrays.rb +18 -0
  75. data/module/gems/highline-1.6.19/examples/basic_usage.rb +75 -0
  76. data/module/gems/highline-1.6.19/examples/color_scheme.rb +32 -0
  77. data/module/gems/highline-1.6.19/examples/get_character.rb +12 -0
  78. data/module/gems/highline-1.6.19/examples/limit.rb +12 -0
  79. data/module/gems/highline-1.6.19/examples/menus.rb +65 -0
  80. data/module/gems/highline-1.6.19/examples/overwrite.rb +19 -0
  81. data/module/gems/highline-1.6.19/examples/page_and_wrap.rb +322 -0
  82. data/module/gems/highline-1.6.19/examples/password.rb +7 -0
  83. data/module/gems/highline-1.6.19/examples/repeat_entry.rb +21 -0
  84. data/module/gems/highline-1.6.19/examples/trapping_eof.rb +22 -0
  85. data/module/gems/highline-1.6.19/examples/using_readline.rb +17 -0
  86. data/module/gems/highline-1.6.19/highline.gemspec +37 -0
  87. data/module/gems/highline-1.6.19/lib/highline.rb +1012 -0
  88. data/module/gems/highline-1.6.19/lib/highline/color_scheme.rb +134 -0
  89. data/module/gems/highline-1.6.19/lib/highline/compatibility.rb +16 -0
  90. data/module/gems/highline-1.6.19/lib/highline/import.rb +41 -0
  91. data/module/gems/highline-1.6.19/lib/highline/menu.rb +398 -0
  92. data/module/gems/highline-1.6.19/lib/highline/question.rb +475 -0
  93. data/module/gems/highline-1.6.19/lib/highline/simulate.rb +48 -0
  94. data/module/gems/highline-1.6.19/lib/highline/string_extensions.rb +131 -0
  95. data/module/gems/highline-1.6.19/lib/highline/style.rb +181 -0
  96. data/module/gems/highline-1.6.19/lib/highline/system_extensions.rb +222 -0
  97. data/module/gems/highline-1.6.19/setup.rb +1360 -0
  98. data/module/gems/highline-1.6.19/site/.cvsignore +1 -0
  99. data/module/gems/highline-1.6.19/site/highline.css +65 -0
  100. data/module/gems/highline-1.6.19/site/images/logo.png +0 -0
  101. data/module/gems/highline-1.6.19/site/index.html +58 -0
  102. data/module/gems/highline-1.6.19/test/string_methods.rb +32 -0
  103. data/module/gems/highline-1.6.19/test/tc_color_scheme.rb +96 -0
  104. data/module/gems/highline-1.6.19/test/tc_highline.rb +1128 -0
  105. data/module/gems/highline-1.6.19/test/tc_import.rb +52 -0
  106. data/module/gems/highline-1.6.19/test/tc_menu.rb +439 -0
  107. data/module/gems/highline-1.6.19/test/tc_string_extension.rb +20 -0
  108. data/module/gems/highline-1.6.19/test/tc_string_highline.rb +38 -0
  109. data/module/gems/highline-1.6.19/test/tc_style.rb +567 -0
  110. data/module/gems/highline-1.6.19/test/ts_all.rb +16 -0
  111. data/module/latest_specs.4.8 +0 -0
  112. data/module/latest_specs.4.8.gz +0 -0
  113. data/module/prerelease_specs.4.8 +0 -0
  114. data/module/prerelease_specs.4.8.gz +0 -0
  115. data/module/specs.4.8 +0 -0
  116. data/module/specs.4.8.gz +0 -0
  117. data/samples/blather/restlike/Gemfile +4 -0
  118. data/samples/blather/restlike/cmd.yml +1 -0
  119. data/samples/blather/restlike/lib/blather.rb +9 -0
  120. data/samples/blather/restlike/lib/blather/dsl/api.rb +78 -0
  121. data/samples/blather/restlike/lib/blather/dsl/call.rb +13 -0
  122. data/samples/blather/restlike/lib/blather/dsl/client.rb +58 -0
  123. data/samples/blather/restlike/lib/blather/dsl/config.rb +11 -0
  124. data/samples/blather/restlike/lib/blather/dsl/extraDSL.rb +163 -0
  125. data/samples/blather/restlike/lib/blather/meta/require.rb +8 -0
  126. data/samples/blather/restlike/lib/blather/meta/xmpp.yml +5 -0
  127. data/samples/blather/restlike/lib/blather/vendors/xmpp_default.rb +27 -0
  128. data/samples/blather/restlike/readme +2 -0
  129. data/samples/grape/init/Gemfile +2 -0
  130. data/samples/grape/init/cmd.yml +3 -0
  131. data/samples/grape/init/config.ru +2 -0
  132. data/samples/grape/init/docs/grape/documentation.txt +939 -0
  133. data/samples/grape/init/docs/grape/generate_rest_routes.rb +37 -0
  134. data/samples/grape/init/docs/grape/ls_routes.rb +31 -0
  135. data/samples/grape/init/lib/grape.rb +4 -0
  136. data/samples/grape/init/lib/grape/meta/subclasses.rb +20 -0
  137. data/samples/grape/init/lib/grape/xpath/app.rb +30 -0
  138. data/samples/grape/init/lib/grape/xpath/ruotes.rb +6 -0
  139. data/samples/grape/init/readme +1 -0
  140. data/samples/grape/readme +29 -0
  141. data/samples/grape/vendor/lib/grape/vendors/v1/rest.rb +57 -0
  142. data/samples/mongoid/cmd.yml +1 -0
  143. data/samples/mongoid/init/Gemfile +3 -0
  144. data/samples/mongoid/init/cmd.yml +2 -0
  145. data/samples/mongoid/init/docs/mongoid/ModelsRelations.rb +11 -0
  146. data/samples/mongoid/init/docs/mongoid/documents.xls +0 -0
  147. data/samples/mongoid/init/docs/mongoid/generate_modelsToDocs.rb +25 -0
  148. data/samples/mongoid/init/docs/mongoid/modelsToDocs.rb +25 -0
  149. data/samples/mongoid/init/docs/mongoid/relations.txt +1354 -0
  150. data/samples/mongoid/init/lib/mongoid.rb +44 -0
  151. data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_CRUD.rb +446 -0
  152. data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_MP.rb +517 -0
  153. data/samples/mongoid/init/lib/mongoid/dsl/init.rb +37 -0
  154. data/samples/mongoid/init/lib/mongoid/dsl/params.rb +67 -0
  155. data/samples/mongoid/init/lib/mongoid/meta/banned.rb +147 -0
  156. data/samples/mongoid/init/lib/mongoid/meta/control.yml +13 -0
  157. data/samples/mongoid/init/lib/mongoid/meta/mongoid.yml +6 -0
  158. data/samples/mongoid/init/lib/mongoid/meta/mpatch.rb +14 -0
  159. data/samples/mongoid/model/lib/mongoid/models/model.rb +28 -0
  160. data/samples/mongoid/readme +33 -0
  161. data/samples/rack/init/Gemfile +10 -0
  162. data/samples/rack/init/cmd.yml +2 -0
  163. data/samples/rack/init/config.ru +1 -0
  164. data/samples/rack/init/docs/rack/rake introducing.txt +60 -0
  165. data/samples/rack/init/docs/rack/webservers/Thin +43 -0
  166. data/samples/rack/init/docs/rack/webservers/ebb +72 -0
  167. data/samples/rack/init/docs/rack/webservers/fcgi +103 -0
  168. data/samples/rack/init/docs/rack/webservers/mongrel +74 -0
  169. data/samples/rack/init/docs/rack/webservers/passenger +37 -0
  170. data/samples/rack/init/docs/rack/webservers/scgi +188 -0
  171. data/samples/rack/init/lib/rack.rb +1 -0
  172. data/samples/rack/init/lib/rack/meta/webserver/thin.rb +45 -0
  173. data/samples/rack/init/lib/rack/meta/webserver/thin.yml +6 -0
  174. data/samples/rack/init/server.rb +0 -0
  175. data/samples/rack/readme +13 -0
  176. data/samples/rest_client/init/Gemfile +5 -0
  177. data/samples/rest_client/init/boot.rb +2 -0
  178. data/samples/rest_client/init/cmd.yml +1 -0
  179. data/samples/rest_client/init/config/rest_client/defaults.rb +16 -0
  180. data/samples/rest_client/init/docs/rest_client/simple overlook +251 -0
  181. data/samples/rest_client/init/test/rest_client/rest_dsl.rb +5 -0
  182. data/samples/rest_client/readme +7 -0
  183. data/samples/scripts/lines_counter/lines_number.rb +32 -0
  184. data/samples/scripts/lines_counter/readme +5 -0
  185. data/samples/scripts/readme +1 -0
  186. metadata +197 -7
  187. data/lib/clone/cms.rb +0 -56
  188. data/lib/clone/ext.rb +0 -77
  189. data/sample/test.rb +0 -30
@@ -0,0 +1,52 @@
1
+ # tc_import.rb
2
+ #
3
+ # Created by James Edward Gray II on 2005-04-26.
4
+ # Copyright 2005 Gray Productions. All rights reserved.
5
+ #
6
+ # This is Free Software. See LICENSE and COPYING for details.
7
+
8
+ require "test/unit"
9
+
10
+ require "highline/import"
11
+ require "stringio"
12
+
13
+ class TestImport < Test::Unit::TestCase
14
+ def test_import
15
+ assert_respond_to(self, :agree)
16
+ assert_respond_to(self, :ask)
17
+ assert_respond_to(self, :choose)
18
+ assert_respond_to(self, :say)
19
+ end
20
+
21
+ def test_or_ask
22
+ old_terminal = $terminal
23
+
24
+ input = StringIO.new
25
+ output = StringIO.new
26
+ $terminal = HighLine.new(input, output)
27
+
28
+ input << "10\n"
29
+ input.rewind
30
+
31
+ assert_equal(10, nil.or_ask("How much? ", Integer))
32
+
33
+ input.rewind
34
+
35
+ assert_equal(20, "20".or_ask("How much? ", Integer))
36
+ assert_equal(20, 20.or_ask("How much? ", Integer))
37
+
38
+ assert_equal(10, 20.or_ask("How much? ", Integer) { |q| q.in = 1..10 })
39
+ ensure
40
+ $terminal = old_terminal
41
+ end
42
+
43
+ def test_redirection
44
+ old_terminal = $terminal
45
+
46
+ $terminal = HighLine.new(nil, (output = StringIO.new))
47
+ say("Testing...")
48
+ assert_equal("Testing...\n", output.string)
49
+ ensure
50
+ $terminal = old_terminal
51
+ end
52
+ end
@@ -0,0 +1,439 @@
1
+ # encoding: utf-8
2
+ # tc_menu.rb
3
+ #
4
+ # Created by Gregory Thomas Brown on 2005-05-10.
5
+ # Copyright 2005. All rights reserved.
6
+ #
7
+ # This is Free Software. See LICENSE and COPYING for details.
8
+
9
+ require "test/unit"
10
+
11
+ require "highline"
12
+ require "stringio"
13
+
14
+ class TestMenu < Test::Unit::TestCase
15
+ def setup
16
+ @input = StringIO.new
17
+ @output = StringIO.new
18
+ @terminal = HighLine.new(@input, @output)
19
+ end
20
+
21
+ def test_choices
22
+ @input << "2\n"
23
+ @input.rewind
24
+
25
+ output = @terminal.choose do |menu|
26
+ menu.choices("Sample1", "Sample2", "Sample3")
27
+ end
28
+ assert_equal("Sample2", output)
29
+ end
30
+
31
+ def test_flow
32
+ @input << "Sample1\n"
33
+ @input.rewind
34
+
35
+ @terminal.choose do |menu|
36
+ # Default: menu.flow = :rows
37
+
38
+ menu.choice "Sample1"
39
+ menu.choice "Sample2"
40
+ menu.choice "Sample3"
41
+ end
42
+ assert_equal("1. Sample1\n2. Sample2\n3. Sample3\n? ", @output.string)
43
+
44
+ @output.truncate(@output.rewind)
45
+ @input.rewind
46
+
47
+ @terminal.choose do |menu|
48
+ menu.flow = :columns_across
49
+
50
+ menu.choice "Sample1"
51
+ menu.choice "Sample2"
52
+ menu.choice "Sample3"
53
+ end
54
+ assert_equal("1. Sample1 2. Sample2 3. Sample3\n? ", @output.string)
55
+
56
+ @output.truncate(@output.rewind)
57
+ @input.rewind
58
+
59
+ @terminal.choose do |menu|
60
+ menu.flow = :inline
61
+ menu.index = :none
62
+
63
+ menu.choice "Sample1"
64
+ menu.choice "Sample2"
65
+ menu.choice "Sample3"
66
+ end
67
+ assert_equal("Sample1, Sample2 or Sample3? ", @output.string)
68
+ end
69
+
70
+ def test_unicode_flow
71
+ @input << "1\n"
72
+ @input.rewind
73
+
74
+ @terminal.choose do |menu|
75
+ # Default: menu.flow = :rows
76
+ menu.choice "Unicode right single quotation mark: ’"
77
+ end
78
+ assert_equal("1. Unicode right single quotation mark: ’\n? ", @output.string)
79
+ end
80
+
81
+ def test_help
82
+ @input << "help\nhelp load\nhelp rules\nhelp missing\n"
83
+ @input.rewind
84
+
85
+ 4.times do
86
+ @terminal.choose do |menu|
87
+ menu.shell = true
88
+
89
+ menu.choice(:load, "Load a file.")
90
+ menu.choice(:save, "Save data in file.")
91
+ menu.choice(:quit, "Exit program.")
92
+
93
+ menu.help("rules", "The rules of this system are as follows...")
94
+ end
95
+ end
96
+ assert_equal( "1. load\n2. save\n3. quit\n4. help\n? " +
97
+ "This command will display helpful messages about " +
98
+ "functionality, like this one. To see the help for a " +
99
+ "specific topic enter:\n" +
100
+ "\thelp [TOPIC]\n" +
101
+ "Try asking for help on any of the following:\n" +
102
+ "\nload quit rules save \n" +
103
+ "1. load\n2. save\n3. quit\n4. help\n? " +
104
+ "= load\n\n" +
105
+ "Load a file.\n" +
106
+ "1. load\n2. save\n3. quit\n4. help\n? " +
107
+ "= rules\n\n" +
108
+ "The rules of this system are as follows...\n" +
109
+ "1. load\n2. save\n3. quit\n4. help\n? " +
110
+ "= missing\n\n" +
111
+ "There's no help for that topic.\n", @output.string )
112
+ end
113
+
114
+ def test_index
115
+ @input << "Sample1\n"
116
+ @input.rewind
117
+
118
+ @terminal.choose do |menu|
119
+ # Default: menu.index = :number
120
+
121
+ menu.choice "Sample1"
122
+ menu.choice "Sample2"
123
+ menu.choice "Sample3"
124
+ end
125
+ assert_equal("1. Sample1\n2. Sample2\n3. Sample3\n? ", @output.string)
126
+
127
+ @output.truncate(@output.rewind)
128
+ @input.rewind
129
+
130
+ @terminal.choose do |menu|
131
+ menu.index = :letter
132
+ menu.index_suffix = ") "
133
+
134
+ menu.choice "Sample1"
135
+ menu.choice "Sample2"
136
+ menu.choice "Sample3"
137
+ end
138
+ assert_equal("a) Sample1\nb) Sample2\nc) Sample3\n? ", @output.string)
139
+
140
+ @output.truncate(@output.rewind)
141
+ @input.rewind
142
+
143
+ @terminal.choose do |menu|
144
+ menu.index = :none
145
+
146
+ menu.choice "Sample1"
147
+ menu.choice "Sample2"
148
+ menu.choice "Sample3"
149
+ end
150
+ assert_equal("Sample1\nSample2\nSample3\n? ", @output.string)
151
+
152
+ @output.truncate(@output.rewind)
153
+ @input.rewind
154
+
155
+ @terminal.choose do |menu|
156
+ menu.index = "*"
157
+
158
+ menu.choice "Sample1"
159
+ menu.choice "Sample2"
160
+ menu.choice "Sample3"
161
+ end
162
+ assert_equal("* Sample1\n* Sample2\n* Sample3\n? ", @output.string)
163
+ end
164
+
165
+ def test_layouts
166
+ @input << "save\n"
167
+ @input.rewind
168
+
169
+ @terminal.choose(:load, :save, :quit) # Default: layout = :list
170
+ assert_equal("1. load\n2. save\n3. quit\n? ", @output.string)
171
+
172
+ @input.rewind
173
+ @output.truncate(@output.rewind)
174
+
175
+ @terminal.choose(:load, :save, :quit) do |menu|
176
+ menu.header = "File Menu"
177
+ end
178
+ assert_equal( "File Menu:\n" +
179
+ "1. load\n2. save\n3. quit\n? ", @output.string )
180
+
181
+ @input.rewind
182
+ @output.truncate(@output.rewind)
183
+
184
+ @terminal.choose(:load, :save, :quit) do |menu|
185
+ menu.layout = :one_line
186
+ menu.header = "File Menu"
187
+ menu.prompt = "Operation? "
188
+ end
189
+ assert_equal( "File Menu: Operation? " +
190
+ "(load, save or quit) ", @output.string )
191
+
192
+ @input.rewind
193
+ @output.truncate(@output.rewind)
194
+
195
+ @terminal.choose(:load, :save, :quit) do |menu|
196
+ menu.layout = :menu_only
197
+ end
198
+ assert_equal("load, save or quit? ", @output.string)
199
+
200
+ @input.rewind
201
+ @output.truncate(@output.rewind)
202
+
203
+ @terminal.choose(:load, :save, :quit) do |menu|
204
+ menu.layout = '<%= list(@menu) %>File Menu: '
205
+ end
206
+ assert_equal("1. load\n2. save\n3. quit\nFile Menu: ", @output.string)
207
+ end
208
+
209
+ def test_list_option
210
+ @input << "l\n"
211
+ @input.rewind
212
+
213
+ @terminal.choose(:load, :save, :quit) do |menu|
214
+ menu.layout = :menu_only
215
+ menu.list_option = ", or "
216
+ end
217
+ assert_equal("load, save, or quit? ", @output.string)
218
+ end
219
+
220
+ def test_nil_on_handled
221
+ @input << "3\n3\n2\n"
222
+ @input.rewind
223
+
224
+ # Shows that by default proc results are returned.
225
+ output = @terminal.choose do |menu|
226
+ menu.choice "Sample1" do "output1" end
227
+ menu.choice "Sample2" do "output2" end
228
+ menu.choice "Sample3" do "output3" end
229
+ end
230
+ assert_equal("output3", output)
231
+
232
+ #
233
+ # Shows that they can be replaced with +nil+ by setting
234
+ # _nil_on_handled to +true+.
235
+ #
236
+ output = @terminal.choose do |menu|
237
+ menu.nil_on_handled = true
238
+ menu.choice "Sample1" do "output1" end
239
+ menu.choice "Sample2" do "output2" end
240
+ menu.choice "Sample3" do "output3" end
241
+ end
242
+ assert_equal(nil, output)
243
+
244
+ # Shows that a menu item without a proc will be returned no matter what.
245
+ output = @terminal.choose do |menu|
246
+ menu.choice "Sample1"
247
+ menu.choice "Sample2"
248
+ menu.choice "Sample3"
249
+ end
250
+ assert_equal("Sample2", output)
251
+ end
252
+
253
+ def test_passed_command
254
+ @input << "q\n"
255
+ @input.rewind
256
+
257
+ selected = nil
258
+ @terminal.choose do |menu|
259
+ menu.choices(:load, :save, :quit) { |command| selected = command }
260
+ end
261
+ assert_equal(:quit, selected)
262
+ end
263
+
264
+ def test_question_options
265
+ @input << "save\n"
266
+ @input.rewind
267
+
268
+ answer = @terminal.choose(:Load, :Save, :Quit) do |menu|
269
+ menu.case = :capitalize
270
+ end
271
+ assert_equal(:Save, answer)
272
+
273
+ @input.rewind
274
+
275
+ answer = @terminal.choose(:Load, :Save, :Quit) do |menu|
276
+ menu.case = :capitalize
277
+ menu.character = :getc
278
+ end
279
+ assert_equal(:Save, answer)
280
+ assert_equal(?a, @input.getc)
281
+ end
282
+
283
+ def test_select_by
284
+ @input << "Sample1\n2\n"
285
+ @input.rewind
286
+
287
+ selected = @terminal.choose do |menu|
288
+ menu.choice "Sample1"
289
+ menu.choice "Sample2"
290
+ menu.choice "Sample3"
291
+ end
292
+ assert_equal("Sample1", selected)
293
+
294
+ @input.rewind
295
+
296
+ selected = @terminal.choose do |menu|
297
+ menu.select_by = :index
298
+
299
+ menu.choice "Sample1"
300
+ menu.choice "Sample2"
301
+ menu.choice "Sample3"
302
+ end
303
+ assert_equal("Sample2", selected)
304
+
305
+ @input.rewind
306
+
307
+ selected = @terminal.choose do |menu|
308
+ menu.select_by = :name
309
+
310
+ menu.choice "Sample1"
311
+ menu.choice "Sample2"
312
+ menu.choice "Sample3"
313
+ end
314
+ assert_equal("Sample1", selected)
315
+ end
316
+
317
+ def test_hidden
318
+ @input << "Hidden\n4\n"
319
+ @input.rewind
320
+
321
+ selected = @terminal.choose do |menu|
322
+ menu.choice "Sample1"
323
+ menu.choice "Sample2"
324
+ menu.choice "Sample3"
325
+ menu.hidden "Hidden!"
326
+ end
327
+ assert_equal("Hidden!", selected)
328
+ assert_equal("1. Sample1\n2. Sample2\n3. Sample3\n? ", @output.string)
329
+
330
+ @input.rewind
331
+
332
+ selected = @terminal.choose do |menu|
333
+ menu.select_by = :index
334
+
335
+ menu.choice "Sample1"
336
+ menu.choice "Sample2"
337
+ menu.choice "Sample3"
338
+ menu.hidden "Hidden!"
339
+ end
340
+ assert_equal("Hidden!", selected)
341
+
342
+ @input.rewind
343
+
344
+ selected = @terminal.choose do |menu|
345
+ menu.select_by = :name
346
+
347
+ menu.choice "Sample1"
348
+ menu.choice "Sample2"
349
+ menu.choice "Sample3"
350
+ menu.hidden "Hidden!"
351
+ end
352
+ assert_equal("Hidden!", selected)
353
+
354
+ @input.rewind
355
+ end
356
+
357
+ def test_select_by_letter
358
+ @input << "b\n"
359
+ @input.rewind
360
+
361
+ selected = @terminal.choose do |menu|
362
+ menu.index = :letter
363
+ menu.choice :save
364
+ menu.choice :load
365
+ menu.choice :quit
366
+ end
367
+ assert_equal(:load, selected)
368
+ end
369
+
370
+ def test_shell
371
+ @input << "save --some-option my_file.txt\n"
372
+ @input.rewind
373
+
374
+ selected = nil
375
+ options = nil
376
+ answer = @terminal.choose do |menu|
377
+ menu.choices(:load, :quit)
378
+ menu.choice(:save) do |command, details|
379
+ selected = command
380
+ options = details
381
+
382
+ "Saved!"
383
+ end
384
+ menu.shell = true
385
+ end
386
+ assert_equal("Saved!", answer)
387
+ assert_equal(:save, selected)
388
+ assert_equal("--some-option my_file.txt", options)
389
+ end
390
+
391
+ def test_simple_menu_shortcut
392
+ @input << "3\n"
393
+ @input.rewind
394
+
395
+ selected = @terminal.choose(:save, :load, :quit)
396
+ assert_equal(:quit, selected)
397
+ end
398
+
399
+ def test_symbols
400
+ @input << "3\n"
401
+ @input.rewind
402
+
403
+ selected = @terminal.choose do |menu|
404
+ menu.choices(:save, :load, :quit)
405
+ end
406
+ assert_equal(:quit, selected)
407
+ end
408
+
409
+ def test_paged_print_infinite_loop_bug
410
+ @terminal.page_at = 5
411
+ # Will page twice, so start with two new lines
412
+ @input << "\n\n3\n"
413
+ @input.rewind
414
+
415
+ # Sadly this goes into an infinite loop without the fix to page_print
416
+ selected = @terminal.choose(* 1..10)
417
+ assert_equal(selected, 3)
418
+ end
419
+
420
+
421
+ def test_cancel_paging
422
+ # Tests that paging can be cancelled halfway through
423
+ @terminal.page_at = 5
424
+ # Will page twice, so stop after first page and make choice 3
425
+ @input << "q\n3\n"
426
+ @input.rewind
427
+
428
+ selected = @terminal.choose(* 1..10)
429
+ assert_equal(selected, 3)
430
+
431
+ # Make sure paging message appeared
432
+ assert( @output.string.index('press enter/return to continue or q to stop'),
433
+ "Paging message did not appear." )
434
+
435
+ # Make sure it only appeared once
436
+ assert( @output.string !~ /q to stop.*q to stop/m,
437
+ "Paging message appeared more than once." )
438
+ end
439
+ end