shoes-swt 4.0.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +84 -0
  3. data/Gemfile +24 -0
  4. data/Guardfile +11 -0
  5. data/LICENSE +31 -0
  6. data/README.md +201 -0
  7. data/lib/shoes/swt.rb +118 -0
  8. data/lib/shoes/swt/animation.rb +46 -0
  9. data/lib/shoes/swt/app.rb +314 -0
  10. data/lib/shoes/swt/arc.rb +71 -0
  11. data/lib/shoes/swt/background.rb +41 -0
  12. data/lib/shoes/swt/border.rb +41 -0
  13. data/lib/shoes/swt/button.rb +18 -0
  14. data/lib/shoes/swt/check.rb +14 -0
  15. data/lib/shoes/swt/check_button.rb +19 -0
  16. data/lib/shoes/swt/color.rb +49 -0
  17. data/lib/shoes/swt/color_factory.rb +32 -0
  18. data/lib/shoes/swt/common/child.rb +16 -0
  19. data/lib/shoes/swt/common/clickable.rb +68 -0
  20. data/lib/shoes/swt/common/container.rb +28 -0
  21. data/lib/shoes/swt/common/fill.rb +38 -0
  22. data/lib/shoes/swt/common/painter.rb +92 -0
  23. data/lib/shoes/swt/common/painter_updates_position.rb +12 -0
  24. data/lib/shoes/swt/common/remove.rb +30 -0
  25. data/lib/shoes/swt/common/resource.rb +29 -0
  26. data/lib/shoes/swt/common/selection_listener.rb +14 -0
  27. data/lib/shoes/swt/common/stroke.rb +42 -0
  28. data/lib/shoes/swt/common/update_position.rb +15 -0
  29. data/lib/shoes/swt/common/visibility.rb +13 -0
  30. data/lib/shoes/swt/dialog.rb +90 -0
  31. data/lib/shoes/swt/disposed_protection.rb +23 -0
  32. data/lib/shoes/swt/download.rb +24 -0
  33. data/lib/shoes/swt/font.rb +32 -0
  34. data/lib/shoes/swt/gradient.rb +92 -0
  35. data/lib/shoes/swt/image.rb +128 -0
  36. data/lib/shoes/swt/image_pattern.rb +31 -0
  37. data/lib/shoes/swt/input_box.rb +73 -0
  38. data/lib/shoes/swt/key_listener.rb +145 -0
  39. data/lib/shoes/swt/line.rb +60 -0
  40. data/lib/shoes/swt/link.rb +31 -0
  41. data/lib/shoes/swt/link_segment.rb +111 -0
  42. data/lib/shoes/swt/list_box.rb +48 -0
  43. data/lib/shoes/swt/mouse_move_listener.rb +67 -0
  44. data/lib/shoes/swt/oval.rb +52 -0
  45. data/lib/shoes/swt/progress.rb +35 -0
  46. data/lib/shoes/swt/radio.rb +29 -0
  47. data/lib/shoes/swt/radio_group.rb +54 -0
  48. data/lib/shoes/swt/rect.rb +30 -0
  49. data/lib/shoes/swt/rect_painter.rb +23 -0
  50. data/lib/shoes/swt/redrawing_aspect.rb +123 -0
  51. data/lib/shoes/swt/shape.rb +133 -0
  52. data/lib/shoes/swt/shoes_layout.rb +43 -0
  53. data/lib/shoes/swt/slot.rb +39 -0
  54. data/lib/shoes/swt/sound.rb +119 -0
  55. data/lib/shoes/swt/star.rb +50 -0
  56. data/lib/shoes/swt/support/jl1.0.1.jar +0 -0
  57. data/lib/shoes/swt/support/jogg-0.0.7.jar +0 -0
  58. data/lib/shoes/swt/support/jorbis-0.0.15.jar +0 -0
  59. data/lib/shoes/swt/support/log4j-1.2.16.jar +0 -0
  60. data/lib/shoes/swt/support/mp3spi1.9.5.jar +0 -0
  61. data/lib/shoes/swt/support/tritonus_share.jar +0 -0
  62. data/lib/shoes/swt/support/vorbisspi1.0.3.jar +0 -0
  63. data/lib/shoes/swt/swt_button.rb +56 -0
  64. data/lib/shoes/swt/text_block.rb +124 -0
  65. data/lib/shoes/swt/text_block/centered_text_segment.rb +22 -0
  66. data/lib/shoes/swt/text_block/cursor_painter.rb +53 -0
  67. data/lib/shoes/swt/text_block/fitter.rb +212 -0
  68. data/lib/shoes/swt/text_block/painter.rb +47 -0
  69. data/lib/shoes/swt/text_block/text_font_factory.rb +50 -0
  70. data/lib/shoes/swt/text_block/text_segment.rb +108 -0
  71. data/lib/shoes/swt/text_block/text_segment_collection.rb +160 -0
  72. data/lib/shoes/swt/text_block/text_style_factory.rb +88 -0
  73. data/lib/shoes/swt/timer.rb +19 -0
  74. data/lib/shoes/swt/tooling/leak_hunter.rb +35 -0
  75. data/lib/shoes/swt/version.rb +5 -0
  76. data/manifests/common.rb +34 -0
  77. data/manifests/shoes-swt.rb +29 -0
  78. data/shoes-swt.gemspec +24 -0
  79. data/spec/code_coverage.rb +14 -0
  80. data/spec/shoes/animation_spec.rb +65 -0
  81. data/spec/shoes/app_spec.rb +484 -0
  82. data/spec/shoes/arc_spec.rb +51 -0
  83. data/spec/shoes/background_spec.rb +53 -0
  84. data/spec/shoes/border_spec.rb +47 -0
  85. data/spec/shoes/builtin_methods_spec.rb +110 -0
  86. data/spec/shoes/button_spec.rb +44 -0
  87. data/spec/shoes/check_spec.rb +35 -0
  88. data/spec/shoes/cli_spec.rb +15 -0
  89. data/spec/shoes/color_spec.rb +408 -0
  90. data/spec/shoes/common/inspect_spec.rb +26 -0
  91. data/spec/shoes/common/remove_spec.rb +38 -0
  92. data/spec/shoes/common/style_normalizer_spec.rb +28 -0
  93. data/spec/shoes/common/style_spec.rb +147 -0
  94. data/spec/shoes/configuration_spec.rb +36 -0
  95. data/spec/shoes/constants_spec.rb +38 -0
  96. data/spec/shoes/dialog_spec.rb +163 -0
  97. data/spec/shoes/dimension_spec.rb +407 -0
  98. data/spec/shoes/dimensions_spec.rb +837 -0
  99. data/spec/shoes/download_spec.rb +142 -0
  100. data/spec/shoes/flow_spec.rb +133 -0
  101. data/spec/shoes/font_spec.rb +37 -0
  102. data/spec/shoes/framework_learning_spec.rb +30 -0
  103. data/spec/shoes/gradient_spec.rb +32 -0
  104. data/spec/shoes/helpers/fake_element.rb +17 -0
  105. data/spec/shoes/helpers/inspect_helpers.rb +5 -0
  106. data/spec/shoes/helpers/sample17_helper.rb +66 -0
  107. data/spec/shoes/image_spec.rb +49 -0
  108. data/spec/shoes/images/shoe.jpg +0 -0
  109. data/spec/shoes/input_box_spec.rb +80 -0
  110. data/spec/shoes/integration_spec.rb +20 -0
  111. data/spec/shoes/internal_app_spec.rb +141 -0
  112. data/spec/shoes/keypress_spec.rb +11 -0
  113. data/spec/shoes/keyrelease_spec.rb +12 -0
  114. data/spec/shoes/line_spec.rb +49 -0
  115. data/spec/shoes/link_spec.rb +105 -0
  116. data/spec/shoes/list_box_spec.rb +74 -0
  117. data/spec/shoes/logger/ruby_spec.rb +8 -0
  118. data/spec/shoes/logger_spec.rb +45 -0
  119. data/spec/shoes/oval_spec.rb +24 -0
  120. data/spec/shoes/point_spec.rb +71 -0
  121. data/spec/shoes/progress_spec.rb +54 -0
  122. data/spec/shoes/radio_spec.rb +32 -0
  123. data/spec/shoes/rect_spec.rb +39 -0
  124. data/spec/shoes/renamed_delegate_spec.rb +70 -0
  125. data/spec/shoes/shape_spec.rb +95 -0
  126. data/spec/shoes/shared_examples/button.rb +6 -0
  127. data/spec/shoes/shared_examples/changeable.rb +26 -0
  128. data/spec/shoes/shared_examples/clickable.rb +5 -0
  129. data/spec/shoes/shared_examples/common_methods.rb +35 -0
  130. data/spec/shoes/shared_examples/dimensions.rb +32 -0
  131. data/spec/shoes/shared_examples/dsl.rb +44 -0
  132. data/spec/shoes/shared_examples/dsl/animate.rb +29 -0
  133. data/spec/shoes/shared_examples/dsl/arc.rb +45 -0
  134. data/spec/shoes/shared_examples/dsl/background.rb +26 -0
  135. data/spec/shoes/shared_examples/dsl/border.rb +10 -0
  136. data/spec/shoes/shared_examples/dsl/button.rb +5 -0
  137. data/spec/shoes/shared_examples/dsl/cap.rb +6 -0
  138. data/spec/shoes/shared_examples/dsl/check.rb +11 -0
  139. data/spec/shoes/shared_examples/dsl/edit_box.rb +8 -0
  140. data/spec/shoes/shared_examples/dsl/edit_line.rb +8 -0
  141. data/spec/shoes/shared_examples/dsl/editable_element.rb +29 -0
  142. data/spec/shoes/shared_examples/dsl/fill.rb +27 -0
  143. data/spec/shoes/shared_examples/dsl/flow.rb +15 -0
  144. data/spec/shoes/shared_examples/dsl/gradient.rb +62 -0
  145. data/spec/shoes/shared_examples/dsl/image.rb +21 -0
  146. data/spec/shoes/shared_examples/dsl/line.rb +9 -0
  147. data/spec/shoes/shared_examples/dsl/nofill.rb +6 -0
  148. data/spec/shoes/shared_examples/dsl/nostroke.rb +6 -0
  149. data/spec/shoes/shared_examples/dsl/oval.rb +88 -0
  150. data/spec/shoes/shared_examples/dsl/pattern.rb +34 -0
  151. data/spec/shoes/shared_examples/dsl/progress.rb +7 -0
  152. data/spec/shoes/shared_examples/dsl/rect.rb +92 -0
  153. data/spec/shoes/shared_examples/dsl/rgb.rb +26 -0
  154. data/spec/shoes/shared_examples/dsl/shape.rb +21 -0
  155. data/spec/shoes/shared_examples/dsl/star.rb +48 -0
  156. data/spec/shoes/shared_examples/dsl/stroke.rb +30 -0
  157. data/spec/shoes/shared_examples/dsl/strokewidth.rb +19 -0
  158. data/spec/shoes/shared_examples/dsl/style.rb +32 -0
  159. data/spec/shoes/shared_examples/dsl/text_elements.rb +81 -0
  160. data/spec/shoes/shared_examples/dsl/video.rb +5 -0
  161. data/spec/shoes/shared_examples/dsl_app_context.rb +8 -0
  162. data/spec/shoes/shared_examples/hover_leave.rb +11 -0
  163. data/spec/shoes/shared_examples/parent.rb +6 -0
  164. data/spec/shoes/shared_examples/scroll.rb +41 -0
  165. data/spec/shoes/shared_examples/shared_element_method.rb +60 -0
  166. data/spec/shoes/shared_examples/slot.rb +331 -0
  167. data/spec/shoes/shared_examples/state.rb +19 -0
  168. data/spec/shoes/shared_examples/style.rb +82 -0
  169. data/spec/shoes/slot_spec.rb +130 -0
  170. data/spec/shoes/sound_spec.rb +15 -0
  171. data/spec/shoes/span_spec.rb +112 -0
  172. data/spec/shoes/spec_helper.rb +24 -0
  173. data/spec/shoes/stack_spec.rb +79 -0
  174. data/spec/shoes/star_spec.rb +31 -0
  175. data/spec/shoes/text_block_dimensions_spec.rb +75 -0
  176. data/spec/shoes/text_block_spec.rb +270 -0
  177. data/spec/shoes/url_spec.rb +68 -0
  178. data/spec/shoes/widget_spec.rb +70 -0
  179. data/spec/shoes_spec.rb +44 -0
  180. data/spec/spec_helper.rb +18 -0
  181. data/spec/swt_shoes/animation_spec.rb +86 -0
  182. data/spec/swt_shoes/app_spec.rb +84 -0
  183. data/spec/swt_shoes/arc_spec.rb +103 -0
  184. data/spec/swt_shoes/background_spec.rb +67 -0
  185. data/spec/swt_shoes/border_spec.rb +52 -0
  186. data/spec/swt_shoes/button_spec.rb +101 -0
  187. data/spec/swt_shoes/check_spec.rb +28 -0
  188. data/spec/swt_shoes/color_factory_spec.rb +49 -0
  189. data/spec/swt_shoes/color_spec.rb +67 -0
  190. data/spec/swt_shoes/common/painter_spec.rb +49 -0
  191. data/spec/swt_shoes/common/remove_spec.rb +53 -0
  192. data/spec/swt_shoes/configuration_spec.rb +12 -0
  193. data/spec/swt_shoes/dialog_spec.rb +106 -0
  194. data/spec/swt_shoes/disposed_protection_spec.rb +49 -0
  195. data/spec/swt_shoes/flow_spec.rb +36 -0
  196. data/spec/swt_shoes/font_spec.rb +33 -0
  197. data/spec/swt_shoes/gradient_spec.rb +31 -0
  198. data/spec/swt_shoes/image_pattern_spec.rb +35 -0
  199. data/spec/swt_shoes/image_spec.rb +100 -0
  200. data/spec/swt_shoes/input_box_spec.rb +116 -0
  201. data/spec/swt_shoes/integration_spec.rb +27 -0
  202. data/spec/swt_shoes/key_listener_spec.rb +325 -0
  203. data/spec/swt_shoes/line_spec.rb +49 -0
  204. data/spec/swt_shoes/link_segment_spec.rb +120 -0
  205. data/spec/swt_shoes/link_spec.rb +54 -0
  206. data/spec/swt_shoes/list_box_spec.rb +56 -0
  207. data/spec/swt_shoes/minimal.png +0 -0
  208. data/spec/swt_shoes/mouse_move_listener_spec.rb +123 -0
  209. data/spec/swt_shoes/oval_spec.rb +51 -0
  210. data/spec/swt_shoes/progress_spec.rb +44 -0
  211. data/spec/swt_shoes/radio_group_spec.rb +73 -0
  212. data/spec/swt_shoes/radio_spec.rb +56 -0
  213. data/spec/swt_shoes/rect_painter_spec.rb +45 -0
  214. data/spec/swt_shoes/rect_spec.rb +19 -0
  215. data/spec/swt_shoes/shape_spec.rb +84 -0
  216. data/spec/swt_shoes/shared_examples/button.rb +21 -0
  217. data/spec/swt_shoes/shared_examples/clickable.rb +85 -0
  218. data/spec/swt_shoes/shared_examples/movable.rb +36 -0
  219. data/spec/swt_shoes/shared_examples/paintable.rb +7 -0
  220. data/spec/swt_shoes/shared_examples/painter.rb +83 -0
  221. data/spec/swt_shoes/shared_examples/pattern.rb +32 -0
  222. data/spec/swt_shoes/shared_examples/removable.rb +41 -0
  223. data/spec/swt_shoes/shared_examples/swt_app_context.rb +23 -0
  224. data/spec/swt_shoes/shared_examples/visibility.rb +15 -0
  225. data/spec/swt_shoes/shell_control_listener_spec.rb +23 -0
  226. data/spec/swt_shoes/slot_spec.rb +24 -0
  227. data/spec/swt_shoes/sound.rb +10 -0
  228. data/spec/swt_shoes/spec_helper.rb +31 -0
  229. data/spec/swt_shoes/star_spec.rb +47 -0
  230. data/spec/swt_shoes/text_block/centered_text_segment_spec.rb +16 -0
  231. data/spec/swt_shoes/text_block/cursor_painter_spec.rb +120 -0
  232. data/spec/swt_shoes/text_block/fitter_spec.rb +213 -0
  233. data/spec/swt_shoes/text_block/painter_spec.rb +212 -0
  234. data/spec/swt_shoes/text_block/text_font_factory_spec.rb +40 -0
  235. data/spec/swt_shoes/text_block/text_segment_collection_spec.rb +256 -0
  236. data/spec/swt_shoes/text_block/text_segment_spec.rb +135 -0
  237. data/spec/swt_shoes/text_block_spec.rb +199 -0
  238. metadata +496 -0
@@ -0,0 +1,51 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::Arc do
4
+ include_context "dsl app"
5
+ let(:parent) { app }
6
+
7
+ let(:left) { 13 }
8
+ let(:top) { 44 }
9
+ let(:width) { 200 }
10
+ let(:height) { 300 }
11
+ let(:start_angle) { 0 }
12
+ let(:end_angle) { Shoes::TWO_PI }
13
+
14
+ context "basic" do
15
+ subject(:arc) { Shoes::Arc.new(app, parent, left, top, width, height, start_angle, end_angle) }
16
+
17
+ it_behaves_like "object with style" do
18
+ let(:subject_without_style) { Shoes::Arc.new(app, parent, left, top, width, height, start_angle, end_angle) }
19
+ let(:subject_with_style) { Shoes::Arc.new(app, parent, left, top, width, height, start_angle, end_angle, arg_styles) }
20
+ end
21
+ it_behaves_like "object with dimensions"
22
+ it_behaves_like "left, top as center", :start_angle, :end_angle
23
+ it_behaves_like "object with parent"
24
+
25
+ #it_styles_with :art_styles, :center, :dimensions, :radius
26
+
27
+ it "is a Shoes::Arc" do
28
+ expect(arc.class).to be(Shoes::Arc)
29
+ end
30
+
31
+ its(:angle1) { should eq(0) }
32
+ its(:angle2) { should eq(Shoes::TWO_PI) }
33
+ its(:wedge) { should eq(false) }
34
+ end
35
+
36
+ context "relative dimensions" do
37
+ subject(:arc) { Shoes::Arc.new(app, parent, left, top, relative_width, relative_height, start_angle, end_angle) }
38
+ it_behaves_like "object with relative dimensions"
39
+ end
40
+
41
+ context "negative dimensions" do
42
+ subject(:arc) { Shoes::Arc.new(app, parent, left, top, -width, -height, 0, Shoes::TWO_PI) }
43
+ it_behaves_like "object with negative dimensions"
44
+ end
45
+
46
+ context "with wedge: true" do
47
+ subject(:arc) { Shoes::Arc.new(app, parent, left, top, width, height, start_angle, end_angle, wedge: true) }
48
+
49
+ its(:wedge) { should eq(true) }
50
+ end
51
+ end
@@ -0,0 +1,53 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::Background do
4
+ include_context "dsl app"
5
+
6
+ let(:left) { 10 }
7
+ let(:top) { 20 }
8
+ let(:width) { 100 }
9
+ let(:height) { 200 }
10
+
11
+ let(:blue) { Shoes::COLORS[:blue] }
12
+ let(:input_opts){ {left: left, top: top, width: width, height: height, color: blue} }
13
+ subject(:background) { Shoes::Background.new(app, parent, blue, input_opts) }
14
+
15
+ it "retains app" do
16
+ expect(background.app).to eq(app)
17
+ end
18
+
19
+ it "creates gui object" do
20
+ expect(background.gui).not_to be_nil
21
+ end
22
+
23
+ it_behaves_like "object with style" do
24
+ subject(:background) { Shoes::Background.new(app, parent, Shoes::COLORS[:black]) }
25
+ let(:subject_without_style) { Shoes::Background.new(app, parent, blue) }
26
+ let(:subject_with_style) { Shoes::Background.new(app, parent, blue, arg_styles) }
27
+ end
28
+
29
+ it_behaves_like "object with dimensions"
30
+
31
+ describe "relative dimensions from parent" do
32
+ subject { Shoes::Background.new(app, parent, blue, relative_opts) }
33
+ it_behaves_like "object with relative dimensions"
34
+ end
35
+
36
+ context "negative dimensions" do
37
+ subject { Shoes::Background.new(app, parent, blue, negative_opts) }
38
+ it_behaves_like "object with negative dimensions"
39
+ end
40
+
41
+ describe '#needs_to_be_positioned?' do
42
+ context 'without absolute dimensions' do
43
+ let(:input_opts) {{}}
44
+ it {is_expected.not_to be_needs_to_be_positioned}
45
+ end
46
+
47
+ context 'with absolute dimensions' do
48
+ it {is_expected.to be_needs_to_be_positioned}
49
+ end
50
+ end
51
+
52
+ it {is_expected.not_to be_takes_up_space}
53
+ end
@@ -0,0 +1,47 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ shared_examples_for "basic border" do
4
+ it "retains app" do
5
+ expect(subject.app).to eq(app)
6
+ end
7
+
8
+ it "creates gui object" do
9
+ expect(subject.gui).not_to be_nil
10
+ end
11
+ end
12
+
13
+ describe Shoes::Border do
14
+ include_context "dsl app"
15
+ let(:parent) { Shoes::FakeElement.new nil, left, top, width, height}
16
+ let(:opts){ {left: left, top: top, width: width, height: height} }
17
+
18
+ let(:left) { 10 }
19
+ let(:top) { 20 }
20
+ let(:width) { 100 }
21
+ let(:height) { 200 }
22
+
23
+ let(:blue) { Shoes::COLORS[:blue] }
24
+
25
+ subject { Shoes::Border.new(app, parent, blue, opts) }
26
+
27
+ it_behaves_like "basic border"
28
+ it_behaves_like "object with style" do
29
+ subject { Shoes::Border.new(app, parent, Shoes::COLORS[:black]) }
30
+ let(:subject_without_style) { Shoes::Border.new(app, parent, blue) }
31
+ let(:subject_with_style) { Shoes::Border.new(app, parent, blue, arg_styles) }
32
+ end
33
+ it_behaves_like "object with dimensions"
34
+
35
+ describe "relative dimensions from parent" do
36
+ subject { Shoes::Border.new(app, parent, blue, relative_opts) }
37
+ it_behaves_like "object with relative dimensions"
38
+ end
39
+
40
+ describe "negative dimensions" do
41
+ subject { Shoes::Border.new(app, parent, blue, negative_opts) }
42
+ it_behaves_like "object with negative dimensions"
43
+ end
44
+
45
+ it {is_expected.not_to be_takes_up_space}
46
+ it {is_expected.not_to be_needs_to_be_positioned}
47
+ end
@@ -0,0 +1,110 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::BuiltinMethods do
4
+ let(:input_blk) { Proc.new {} }
5
+ let(:app) { Shoes::App.new({}, &input_blk) }
6
+ let(:logger) { double("logger") }
7
+
8
+ before :each do
9
+ Shoes::LOG.clear
10
+ allow(Shoes).to receive(:logger) { logger }
11
+ end
12
+
13
+ describe 'Shoes.p' do
14
+ it 'adds a debug to the log with an inspected object' do
15
+ Shoes.p 'message'
16
+ expect(Shoes::LOG).to include ['debug', 'message'.inspect]
17
+ end
18
+
19
+ it 'also handles object the way they should be handled' do
20
+ Shoes.p []
21
+ expect(Shoes::LOG).to include ['debug', '[]']
22
+ end
23
+ end
24
+
25
+ describe "info" do
26
+ before :each do
27
+ allow(logger).to receive(:info)
28
+ app.info("test")
29
+ end
30
+
31
+ it "sets Shoes::LOG" do
32
+ expect(Shoes::LOG).to eq([["info", "test"]])
33
+ end
34
+
35
+ it "sends message to logger" do
36
+ expect(logger).to have_received(:info)
37
+ end
38
+ end
39
+
40
+ describe "debug" do
41
+ before :each do
42
+ allow(logger).to receive(:debug)
43
+ app.debug("test")
44
+ end
45
+
46
+ it "sets Shoes::LOG" do
47
+ expect(Shoes::LOG).to eq([["debug", "test"]])
48
+ end
49
+
50
+ it "sends message to logger" do
51
+ expect(logger).to have_received(:debug)
52
+ end
53
+ end
54
+
55
+ describe "warn" do
56
+ before :each do
57
+ allow(logger).to receive(:warn)
58
+ app.warn("test")
59
+ end
60
+
61
+ it "sets Shoes::LOG" do
62
+ expect(Shoes::LOG).to eq([["warn", "test"]])
63
+ end
64
+
65
+ it "sends message to logger" do
66
+ expect(logger).to have_received(:warn)
67
+ end
68
+ end
69
+
70
+ describe "error" do
71
+ before :each do
72
+ allow(logger).to receive(:error)
73
+ app.error("test")
74
+ end
75
+
76
+ it "sets Shoes::LOG" do
77
+ expect(Shoes::LOG).to eq([["error", "test"]])
78
+ end
79
+
80
+ it "sends message to logger" do
81
+ expect(logger).to have_received(:error)
82
+ end
83
+ end
84
+
85
+ # just testing responds to things since the implementation is tested
86
+ # elsewhere
87
+ describe 'are builtin methods are also available from Shoes' do
88
+ builtin_methods = [:alert, :ask, :ask_color, :ask_open_file, :ask_save_file,
89
+ :ask_open_folder, :ask_save_folder, :confirm, :color,
90
+ :debug, :error, :font, :gradient, :gray, :rgb, :info,
91
+ :pattern, :warn]
92
+
93
+ builtin_methods.each do |method|
94
+ it "responds to #{method}" do
95
+ expect(Shoes).to respond_to method
96
+ end
97
+ end
98
+
99
+
100
+ describe 'does not get to the nitty gritty helper_methods' do
101
+ helper_methods = [:image_file?, :image_pattern]
102
+
103
+ helper_methods.each do |method|
104
+ it "does not respond to #{method}" do
105
+ expect(Shoes).not_to respond_to method
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,44 @@
1
+ require "shoes/spec_helper"
2
+
3
+ describe Shoes::Button do
4
+ include_context "dsl app"
5
+ let(:input_opts) { {:left => left, :top => top, :width => width,
6
+ :height => height, :margin => margin, :state => "disabled"} }
7
+
8
+ let(:left) { 13 }
9
+ let(:top) { 44 }
10
+ let(:width) { 131 }
11
+ let(:height) { 137 }
12
+ let(:margin) { 14 }
13
+
14
+ subject(:button) { Shoes::Button.new(app, parent, "text", input_opts, input_block) }
15
+
16
+ it_behaves_like "movable object"
17
+ it_behaves_like "object with state"
18
+ it_behaves_like "object with style" do
19
+ let(:subject_without_style) { Shoes::Button.new(app, parent, "text") }
20
+ let(:subject_with_style) { Shoes::Button.new(app, parent, "text", arg_styles) }
21
+ end
22
+ it_behaves_like "object with dimensions"
23
+
24
+ it { is_expected.to respond_to :click }
25
+ it { is_expected.to respond_to :focus }
26
+
27
+ describe "initialize" do
28
+ its(:parent) { should eq(parent) }
29
+ its(:text) { should eq("text") }
30
+ its(:width) { should eq(131) }
31
+ its(:height) { should eq(137) }
32
+ its(:state) { should eq("disabled") }
33
+ end
34
+
35
+ describe "relative dimensions" do
36
+ subject { Shoes::Button.new(app, parent, "text", relative_opts, input_block) }
37
+ it_behaves_like "object with relative dimensions"
38
+ end
39
+
40
+ describe "negative dimensions" do
41
+ subject { Shoes::Button.new(app, parent, "text", negative_opts, input_block) }
42
+ it_behaves_like "object with negative dimensions"
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::Check do
4
+ include_context "dsl app"
5
+
6
+ subject { Shoes::Check.new(app, parent, input_opts, input_block) }
7
+
8
+ it_behaves_like "checkable"
9
+ it_behaves_like "object with state"
10
+ it_behaves_like "object with style" do
11
+ let(:subject_without_style) { Shoes::Check.new(app, parent) }
12
+ let(:subject_with_style) { Shoes::Check.new(app, parent, arg_styles) }
13
+ end
14
+
15
+ describe "dimensions" do
16
+ let(:left) { 10 }
17
+ let(:top) { 20 }
18
+ let(:width) { 100 }
19
+ let(:height) { 200 }
20
+ let(:input_opts){ {left: left, top: top, width: width, height: height} }
21
+ subject { Shoes::Check.new(app, parent, input_opts) }
22
+
23
+ it_behaves_like "object with dimensions"
24
+
25
+ describe "takes relative dimensions from parent" do
26
+ subject { Shoes::Check.new(app, parent, relative_opts) }
27
+ it_behaves_like "object with relative dimensions"
28
+ end
29
+
30
+ describe "negative dimensions" do
31
+ subject { Shoes::Check.new(app, parent, negative_opts) }
32
+ it_behaves_like "object with negative dimensions"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Shoes::CLI do
4
+ subject {Shoes::CLI.new}
5
+
6
+ before :each do
7
+ allow(subject).to receive :package
8
+ end
9
+
10
+ it 'does not raise an error for a normal packaging command #624' do
11
+ expect do
12
+ subject.run ['-p', 'swt:app', 'test/simple-sound.rb']
13
+ end.not_to raise_error
14
+ end
15
+ end
@@ -0,0 +1,408 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::Color do
4
+ describe ".create" do
5
+ let(:color) { Shoes::Color.new(40, 50, 60) }
6
+
7
+ it "accepts color" do
8
+ expect(Shoes::Color.create(color)).to eq(color)
9
+ end
10
+
11
+ it "accepts string" do
12
+ expect(Shoes::Color.create("28323c")).to eq(color)
13
+ end
14
+ end
15
+
16
+ shared_examples_for "black" do
17
+ its(:class) { should eq(Shoes::Color) }
18
+ its(:red) { should eq(0) }
19
+ its(:green) { should eq(0) }
20
+ its(:blue) { should eq(0) }
21
+ its(:hex) { should eq("#000000") }
22
+ it { is_expected.to be_black }
23
+ it { is_expected.not_to be_white }
24
+ end
25
+
26
+ shared_examples "color with bad arguments" do
27
+ it "raises ArgumentError" do
28
+ expect(subject).to raise_error(ArgumentError)
29
+ end
30
+ end
31
+
32
+ context "with wrong number of arguments" do
33
+ subject { lambda { Shoes::Color.new(10, 10) } }
34
+ it_behaves_like "color with bad arguments"
35
+ end
36
+
37
+ context "with too many hex chars" do
38
+ subject { lambda { Shoes::Color.new("a1b2c3d") } }
39
+ it_behaves_like "color with bad arguments"
40
+ end
41
+
42
+ context "with too few hex chars" do
43
+ subject { lambda { Shoes::Color.new("a1") } }
44
+ it_behaves_like "color with bad arguments"
45
+ end
46
+
47
+ context "with invalid hex chars" do
48
+ subject { lambda { Shoes::Color.new("#g01234") } }
49
+ it_behaves_like "color with bad arguments"
50
+ end
51
+
52
+ context "hex" do
53
+ let(:rgb) { Shoes::Color.new(0, 0, 0, 255) }
54
+
55
+ context "with '#000000'" do
56
+ subject { Shoes::Color.new("#000000") }
57
+ it { is_expected.to eq(rgb) }
58
+ end
59
+
60
+ context "with '000000'" do
61
+ subject { Shoes::Color.new("000000") }
62
+ it { is_expected.to eq(rgb) }
63
+ end
64
+
65
+ context "with '000'" do
66
+ subject { Shoes::Color.new("000") }
67
+ it { is_expected.to eq(rgb) }
68
+ end
69
+
70
+ context "with '#000'" do
71
+ subject { Shoes::Color.new("#000") }
72
+ it { is_expected.to eq(rgb) }
73
+ end
74
+
75
+ context "with '#FFF'" do
76
+ let(:rgb) { Shoes::Color.new(255, 255, 255) }
77
+ subject { Shoes::Color.new("#FFF") }
78
+ it { is_expected.to eq(rgb) }
79
+ end
80
+
81
+ context "with '#fff'" do
82
+ let(:rgb) { Shoes::Color.new(255, 255, 255) }
83
+ subject { Shoes::Color.new("#fff") }
84
+ it { is_expected.to eq(rgb) }
85
+ end
86
+ end
87
+
88
+ context "rgb" do
89
+ context "black" do
90
+ context "with optional alpha" do
91
+ subject { Shoes::Color.new(0, 0, 0, 0) }
92
+ it_behaves_like "black"
93
+ its(:alpha) { should eq(0) }
94
+ end
95
+
96
+ context "without optional alpha" do
97
+ subject { Shoes::Color.new(0, 0, 0) }
98
+ it_behaves_like "black"
99
+ its(:alpha) { should eq(255) }
100
+ end
101
+
102
+ context "using floats" do
103
+ context "with optional alpha" do
104
+ subject { Shoes::Color.new(0.0, 0.0, 0.0, 0.0) }
105
+ it_behaves_like "black"
106
+ its(:alpha) { should eq(0) }
107
+ end
108
+
109
+ context "without optional alpha" do
110
+ subject { Shoes::Color.new(0.0, 0.0, 0.0) }
111
+ it_behaves_like "black"
112
+ its(:alpha) { should eq(255) }
113
+ end
114
+ end
115
+ end
116
+
117
+ describe "inspect" do
118
+ include InspectHelpers
119
+
120
+ # Using patterns here so we can handle the variable hex string identifier
121
+ let(:rgb_pattern) { 'rgb[(]10, 20, 30[)]' }
122
+ let(:inspect_pattern) { "[(]Shoes::Color:#{shoes_object_id_pattern} #{rgb_pattern} alpha:40[)]$" }
123
+ subject(:color) { Shoes::Color.new(10, 20, 30, 40) }
124
+
125
+ its(:to_s) { should match(rgb_pattern) }
126
+ its(:inspect) { should match(inspect_pattern) }
127
+ end
128
+
129
+ context "white" do
130
+ subject { Shoes::Color.new(255, 255, 255) }
131
+ it { is_expected.to be_white }
132
+ it { is_expected.not_to be_black }
133
+ end
134
+
135
+ context "peru" do
136
+ shared_examples_for "peru" do
137
+ its(:class) { should eq(Shoes::Color) }
138
+ its(:red) { should eq(205) }
139
+ its(:green) { should eq(133) }
140
+ its(:blue) { should eq(63) }
141
+ it { is_expected.not_to be_black }
142
+ it { is_expected.not_to be_white }
143
+ end
144
+
145
+ context "with optional alpha" do
146
+ subject { Shoes::Color.new(205, 133, 63, 100) }
147
+ it_behaves_like("peru")
148
+ its(:alpha) { should eq(100) }
149
+ end
150
+
151
+ context "without optional alpha" do
152
+ subject { Shoes::Color.new(205, 133, 63) }
153
+ it_behaves_like("peru")
154
+ its(:alpha) { should eq(255) }
155
+ end
156
+
157
+ context "using floats" do
158
+ let(:red) { 0.805 }
159
+ let(:green) { 0.52 }
160
+ let(:blue) { 0.248 }
161
+ let(:alpha) { 0.392 }
162
+
163
+ context "with optional alpha" do
164
+ subject { Shoes::Color.new(red, green, blue, alpha) }
165
+ it_behaves_like "peru"
166
+ its(:alpha) { should eq(100) }
167
+ end
168
+
169
+ context "without optional alpha" do
170
+ subject { Shoes::Color.new(red, green, blue) }
171
+ it_behaves_like "peru"
172
+ its(:alpha) { should eq(255) }
173
+ end
174
+ end
175
+ end
176
+
177
+ describe "light and dark" do
178
+ let(:lightgreen) { Shoes::Color.new(144, 238, 144) }
179
+ let(:darkgreen) { Shoes::Color.new(0, 100, 0) }
180
+ let(:mediumseagreen) { Shoes::Color.new(60, 179, 113) }
181
+
182
+ specify "light color is light" do
183
+ expect(lightgreen).to be_light
184
+ expect(mediumseagreen).not_to be_light
185
+ expect(darkgreen).not_to be_light
186
+ end
187
+
188
+ specify "dark color is dark" do
189
+ expect(lightgreen).not_to be_dark
190
+ expect(mediumseagreen).not_to be_dark
191
+ expect(darkgreen).to be_dark
192
+ end
193
+ end
194
+
195
+ describe "transparency" do
196
+ let(:transparent) { Shoes::Color.new(25, 25, 112, 0) }
197
+ let(:semi) { Shoes::Color.new(25, 25, 112, 100) }
198
+ let(:opaque) { Shoes::Color.new(25, 25, 25) }
199
+
200
+ specify "only transparent colors are transparent" do
201
+ expect(transparent).to be_transparent
202
+ expect(semi).not_to be_transparent
203
+ expect(opaque).not_to be_transparent
204
+ end
205
+
206
+ specify "only opaque colors should be opaque" do
207
+ expect(transparent).not_to be_opaque
208
+ expect(semi).not_to be_opaque
209
+ expect(opaque).to be_opaque
210
+ end
211
+ end
212
+
213
+ describe "comparable" do
214
+ let(:color_1) { Shoes::Color.new(255, 69, 0) }
215
+ let(:red) {Shoes::Color.new 255, 0, 0}
216
+ let(:green) {Shoes::Color.new 0, 255, 0}
217
+
218
+ it "is equal when values are equal" do
219
+ color_2 = Shoes::Color.new(255, 69, 0)
220
+ expect(color_1).to eq(color_2)
221
+ end
222
+
223
+ it "is less than when darker" do
224
+ color_2 = Shoes::Color.new(255, 70, 0)
225
+ expect(color_1).to be < color_2
226
+ end
227
+
228
+ it "is greater than when lighter" do
229
+ color_2 = Shoes::Color.new(255, 68, 0)
230
+ expect(color_1).to be > color_2
231
+ end
232
+
233
+ it 'does not claim for full red and full green to be equal' do
234
+ expect(red).not_to eq green
235
+ end
236
+
237
+ it 'claims that a color is the same as itself' do
238
+ expect(green).to eq green
239
+ end
240
+
241
+ context "same rgb values" do
242
+ let(:color_2) { Shoes::Color.new(255, 69, 0, 254) }
243
+ it "is less than when less opaque" do
244
+ expect(color_2).to be < color_1
245
+ end
246
+
247
+ it "is greater than when more opaque" do
248
+ expect(color_1).to be > color_2
249
+ end
250
+ end
251
+ end
252
+ end
253
+ end
254
+
255
+ describe "Shoes built-in colors" do
256
+ class MockApp
257
+ include Shoes::DSL
258
+ end
259
+
260
+ subject { MockApp.new }
261
+
262
+ its(:papayawhip) { should eq(Shoes::Color.new(255, 239, 213)) }
263
+ its(:aquamarine) { should eq(Shoes::Color.new(127, 255, 212)) }
264
+ its(:tomato) { should eq(Shoes::Color.new(255, 99, 71)) }
265
+ end
266
+
267
+ describe "Shoes built in gray" do
268
+ let(:app) { Shoes::App.new }
269
+
270
+ it "creates a dsl method for gray" do
271
+ expect(app).to respond_to(:gray)
272
+ end
273
+
274
+ specify "gray with no parameters is [128, 128, 128, OPAQUE]" do
275
+ expect(app.gray).to eq(Shoes::Color.new(128, 128, 128))
276
+ end
277
+
278
+ specify "single parameter specifies the gray level" do
279
+ expect(app.gray(64)).to eq(Shoes::Color.new(64, 64, 64))
280
+ end
281
+
282
+ specify "two parameters specifies the gray level and opacity" do
283
+ expect(app.gray(13, 57)).to eq(Shoes::Color.new(13, 13, 13, 57))
284
+ end
285
+
286
+ specify "float parameters should be normalised" do
287
+ expect(app.gray(1.0, 0.5)).to eq(Shoes::Color.new( 255, 255, 255, 128 ))
288
+ end
289
+
290
+ it 'hangles 0.93 right as well' do
291
+ result_93 = (0.93 * 255).to_i
292
+ expect(app.gray(0.93)).to eq(Shoes::Color.new(result_93, result_93, result_93))
293
+ end
294
+
295
+ it 'also has a grey alias for our BE friends' do
296
+ expect(app).to respond_to :grey
297
+ end
298
+ end
299
+
300
+ # Differences between this implementation and Red Shoes
301
+ describe "differences from Red Shoes" do
302
+ let(:white) { Shoes::Color.new(255, 255, 255) }
303
+ let(:transparent_black) { Shoes::Color.new(0, 0, 0, 0) }
304
+
305
+ context "integers" do
306
+ specify "too-large values become 255" do
307
+ expect(Shoes::Color.new(256, 256, 256, 256)).to eq(white)
308
+ end
309
+
310
+ specify "too-small values become 0" do
311
+ expect(Shoes::Color.new(-1, -1, -1, -1)).to eq(transparent_black)
312
+ end
313
+ end
314
+
315
+ context "floats" do
316
+ specify "too-large values become 255" do
317
+ expect(Shoes::Color.new(1.1, 1.1, 1.1, 1.1)).to eq(white)
318
+ end
319
+
320
+ specify "too-small values become 0" do
321
+ expect(Shoes::Color.new(-0.1, -0.1, -0.1, -0.1)).to eq(transparent_black)
322
+ end
323
+ end
324
+
325
+ # These specifications describe how this implementation differs from Red Shoes.
326
+ # These are examples of what Red Shoes _does_ do, and what this implementation
327
+ # _does not_ do.
328
+ describe "unusual input" do
329
+ let(:baseline) { Shoes::Color.new(50, 0, 200) }
330
+
331
+ describe "too-large values" do
332
+ specify "red does not get modulo-256'd into bounds" do
333
+ expect(Shoes::Color.new(306, 0, 200)).not_to eq(baseline)
334
+ expect(Shoes::Color.new(1.197, 0, 200)).not_to eq(baseline)
335
+ end
336
+
337
+ specify "green does not get modulo-256'd into bounds" do
338
+ expect(Shoes::Color.new(50, 256, 200)).not_to eq(baseline)
339
+ expect(Shoes::Color.new(50, 2.005, 200)).not_to eq(baseline)
340
+ end
341
+
342
+ specify "blue does not get modulo-256'd into bounds" do
343
+ expect(Shoes::Color.new(50, 0, 456)).not_to eq(baseline)
344
+ expect(Shoes::Color.new(50, 0, 2.7913137254902)).not_to eq(baseline)
345
+ end
346
+ end
347
+
348
+ describe "negative values" do
349
+ specify "-1 does not become 255" do
350
+ expect(Shoes::Color.new(-1, -1, -1, -1)).not_to eq(Shoes::Color.new(255, 255, 255))
351
+ end
352
+
353
+ specify "256 and neighbors" do
354
+ expect(Shoes::Color.new(-256, -255, -257)).not_to eq(Shoes::Color.new(0, 1, 255))
355
+ end
356
+
357
+ specify "float behaviour" do
358
+ expect(Shoes::Color.new(-1.0, -0.5, -0.0)).not_to eq(Shoes::Color.new(0, 128, 1))
359
+ end
360
+ end
361
+
362
+ describe "edge cases" do
363
+ specify "0.0 does not become 1" do
364
+ expect(Shoes::Color.new(0.0, 0.0, 0.0)).not_to eq(Shoes::Color.new(1, 1, 1))
365
+ end
366
+
367
+ specify "1.0 does not become 0" do
368
+ expect(Shoes::Color.new(1.0, 1.0, 1.0)).not_to eq(Shoes::Color.new(0, 0, 0))
369
+ end
370
+ end
371
+ end
372
+ end
373
+
374
+ describe Shoes::Color::DSLHelpers do
375
+ class ColorDSLHelperTest
376
+ include Shoes::Color::DSLHelpers
377
+ end
378
+
379
+ subject {ColorDSLHelperTest.new}
380
+
381
+ describe '#pattern' do
382
+ it 'creates an image pattern when fed a string for which a file exists' do
383
+ allow(File).to receive_messages(exist?: true)
384
+ my_path = '/some/path/to/image.png'
385
+ image_pattern = subject.pattern(my_path)
386
+ expect(image_pattern.path).to eq my_path
387
+ end
388
+
389
+ it 'raises an argument error for bad input like a single number' do
390
+ expect {subject.pattern(1)}.to raise_error(ArgumentError)
391
+ end
392
+
393
+ it 'creates a gradient given 2 arguments' do
394
+ expect(subject).to receive(:gradient)
395
+ subject.pattern([10, 10, 10], [30, 30, 30])
396
+ end
397
+ end
398
+
399
+ describe '#gradient' do
400
+ it 'raises an argument error for no arguments supplied' do
401
+ expect{subject.gradient}.to raise_error ArgumentError
402
+ end
403
+
404
+ it 'raises an argument error for too many (> 2) args supplied' do
405
+ expect{subject.gradient 1, 2, 3}.to raise_error ArgumentError
406
+ end
407
+ end
408
+ end