scarpe 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/.yardopts +11 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +112 -0
  6. data/README.md +31 -24
  7. data/Rakefile +13 -1
  8. data/docs/yard/catscradle.md +44 -0
  9. data/docs/yard/template/default/fulldoc/html/setup.rb +13 -0
  10. data/docs/yard/template/default/layout/html/setup.rb +9 -0
  11. data/examples/background_with_image.rb +16 -0
  12. data/examples/bloopsaphone/working/bronx_army_knife.rb +66 -0
  13. data/examples/bloopsaphone/working/morning_serenity.rb +21 -0
  14. data/examples/bloopsaphone/working/simpsons_theme_song_by_why.rb +6 -4
  15. data/examples/button_go_away.rb +1 -1
  16. data/examples/check.rb +18 -0
  17. data/examples/clear_and_append.rb +24 -0
  18. data/examples/download_and_show_image.rb +28 -0
  19. data/examples/edit_box.rb +3 -5
  20. data/examples/fonts.rb +2 -2
  21. data/examples/get_headers.rb +10 -0
  22. data/examples/highlander.rb +2 -0
  23. data/examples/link.rb +2 -2
  24. data/examples/local_fonts.rb +4 -0
  25. data/examples/local_images.rb +4 -0
  26. data/examples/motion_events.rb +20 -0
  27. data/examples/parse_xl_funnies.rb +58 -0
  28. data/examples/radio/radio.rb +16 -0
  29. data/examples/radio/radio_groups.rb +18 -0
  30. data/examples/radio/radio_same_slot.rb +6 -0
  31. data/examples/ruby_racer.rb +13 -15
  32. data/examples/selfitude.rb +18 -0
  33. data/examples/shapes/shapes_fill.rb +4 -3
  34. data/examples/shoes_school.rb +2 -4
  35. data/examples/show_hide.rb +6 -0
  36. data/examples/skip_ci/change_my_audio_source.rb +21 -0
  37. data/examples/skip_ci/guitar_fretboard.rb +137 -0
  38. data/examples/video.rb +10 -0
  39. data/exe/scarpe +42 -66
  40. data/fonts/Pacifico.ttf +0 -0
  41. data/lacci/Gemfile +22 -0
  42. data/lacci/Gemfile.lock +72 -0
  43. data/lacci/Rakefile +12 -0
  44. data/lacci/lacci.gemspec +37 -0
  45. data/lacci/lib/lacci/scarpe_cli.rb +70 -0
  46. data/lacci/lib/lacci/scarpe_core.rb +21 -0
  47. data/lacci/lib/lacci/version.rb +13 -0
  48. data/lacci/lib/shoes/app.rb +264 -0
  49. data/{lib/scarpe → lacci/lib/shoes}/background.rb +1 -1
  50. data/{lib/scarpe → lacci/lib/shoes}/border.rb +1 -1
  51. data/{lib/scarpe → lacci/lib/shoes}/colors.rb +1 -1
  52. data/lacci/lib/shoes/constants.rb +29 -0
  53. data/{lib/scarpe → lacci/lib/shoes}/display_service.rb +40 -45
  54. data/lacci/lib/shoes/download.rb +123 -0
  55. data/lacci/lib/shoes/log.rb +71 -0
  56. data/lacci/lib/shoes/spacing.rb +9 -0
  57. data/{lib/scarpe → lacci/lib/shoes}/widget.rb +63 -43
  58. data/{lib/scarpe → lacci/lib/shoes/widgets}/alert.rb +3 -3
  59. data/{lib/scarpe → lacci/lib/shoes/widgets}/arc.rb +7 -5
  60. data/{lib/scarpe → lacci/lib/shoes/widgets}/button.rb +3 -3
  61. data/lacci/lib/shoes/widgets/check.rb +28 -0
  62. data/lacci/lib/shoes/widgets/document_root.rb +20 -0
  63. data/{lib/scarpe → lacci/lib/shoes/widgets}/edit_box.rb +10 -5
  64. data/{lib/scarpe → lacci/lib/shoes/widgets}/edit_line.rb +2 -2
  65. data/lacci/lib/shoes/widgets/flow.rb +22 -0
  66. data/lacci/lib/shoes/widgets/font.rb +14 -0
  67. data/{lib/scarpe → lacci/lib/shoes/widgets}/image.rb +3 -7
  68. data/lacci/lib/shoes/widgets/line.rb +18 -0
  69. data/{lib/scarpe → lacci/lib/shoes/widgets}/link.rb +2 -2
  70. data/{lib/scarpe → lacci/lib/shoes/widgets}/list_box.rb +2 -2
  71. data/{lib/scarpe → lacci/lib/shoes/widgets}/para.rb +4 -26
  72. data/lacci/lib/shoes/widgets/radio.rb +35 -0
  73. data/lacci/lib/shoes/widgets/shape.rb +37 -0
  74. data/lacci/lib/shoes/widgets/slot.rb +75 -0
  75. data/{lib/scarpe → lacci/lib/shoes/widgets}/span.rb +2 -2
  76. data/lacci/lib/shoes/widgets/stack.rb +24 -0
  77. data/{lib/scarpe → lacci/lib/shoes/widgets}/star.rb +6 -9
  78. data/lacci/lib/shoes/widgets/subscription_item.rb +60 -0
  79. data/lacci/lib/shoes/widgets/text_widget.rb +51 -0
  80. data/lacci/lib/shoes/widgets/video.rb +15 -0
  81. data/lacci/lib/shoes/widgets.rb +29 -0
  82. data/lacci/lib/shoes.rb +127 -0
  83. data/lacci/test/test_colors.rb +39 -0
  84. data/lacci/test/test_helper.rb +9 -0
  85. data/lacci/test/test_lacci.rb +9 -0
  86. data/lib/scarpe/cats_cradle.rb +249 -0
  87. data/lib/scarpe/evented_assertions.rb +88 -0
  88. data/lib/scarpe/version.rb +1 -1
  89. data/lib/scarpe/wv/alert.rb +3 -2
  90. data/lib/scarpe/wv/app.rb +30 -8
  91. data/lib/scarpe/wv/arc.rb +5 -6
  92. data/lib/scarpe/wv/background.rb +10 -1
  93. data/lib/scarpe/wv/border.rb +5 -3
  94. data/lib/scarpe/wv/button.rb +11 -9
  95. data/lib/scarpe/wv/check.rb +29 -0
  96. data/lib/scarpe/wv/control_interface.rb +14 -20
  97. data/lib/scarpe/wv/control_interface_test.rb +13 -28
  98. data/lib/scarpe/wv/document_root.rb +3 -45
  99. data/lib/scarpe/wv/edit_box.rb +5 -7
  100. data/lib/scarpe/wv/edit_line.rb +2 -2
  101. data/lib/scarpe/wv/flow.rb +10 -20
  102. data/lib/scarpe/wv/font.rb +36 -0
  103. data/lib/scarpe/wv/html.rb +3 -2
  104. data/lib/scarpe/wv/image.rb +7 -2
  105. data/lib/scarpe/wv/line.rb +4 -7
  106. data/lib/scarpe/wv/link.rb +1 -0
  107. data/lib/scarpe/wv/list_box.rb +3 -3
  108. data/lib/scarpe/wv/para.rb +16 -14
  109. data/lib/scarpe/wv/radio.rb +34 -0
  110. data/lib/scarpe/wv/shape.rb +44 -8
  111. data/lib/scarpe/wv/slot.rb +81 -0
  112. data/lib/scarpe/wv/spacing.rb +1 -1
  113. data/lib/scarpe/wv/span.rb +10 -8
  114. data/lib/scarpe/wv/stack.rb +10 -30
  115. data/lib/scarpe/wv/star.rb +11 -12
  116. data/lib/scarpe/wv/subscription_item.rb +50 -0
  117. data/lib/scarpe/wv/video.rb +34 -0
  118. data/lib/scarpe/wv/web_wrangler.rb +238 -58
  119. data/lib/scarpe/wv/webview_local_display.rb +27 -5
  120. data/lib/scarpe/wv/webview_relay_display.rb +18 -119
  121. data/lib/scarpe/wv/webview_relay_util.rb +143 -0
  122. data/lib/scarpe/wv/widget.rb +80 -11
  123. data/lib/scarpe/wv/wv_display_worker.rb +17 -4
  124. data/lib/scarpe/wv.rb +33 -4
  125. data/lib/scarpe/wv_local.rb +1 -1
  126. data/lib/scarpe/wv_relay.rb +1 -1
  127. data/lib/scarpe.rb +3 -32
  128. data/scarpe-components/.gitignore +1 -0
  129. data/scarpe-components/Gemfile +22 -0
  130. data/scarpe-components/README.md +35 -0
  131. data/scarpe-components/Rakefile +12 -0
  132. data/scarpe-components/lib/scarpe/components/base64.rb +29 -0
  133. data/scarpe-components/lib/scarpe/components/file_helpers.rb +65 -0
  134. data/scarpe-components/lib/scarpe/components/modular_logger.rb +113 -0
  135. data/scarpe-components/lib/scarpe/components/print_logger.rb +43 -0
  136. data/{lib/scarpe → scarpe-components/lib/scarpe/components}/promises.rb +102 -35
  137. data/scarpe-components/lib/scarpe/components/segmented_file_loader.rb +170 -0
  138. data/scarpe-components/lib/scarpe/components/unit_test_helpers.rb +217 -0
  139. data/scarpe-components/lib/scarpe/components/version.rb +7 -0
  140. data/scarpe-components/scarpe-components.gemspec +38 -0
  141. data/scarpe-components/test/test_components.rb +9 -0
  142. data/scarpe-components/test/test_helper.rb +23 -0
  143. data/scarpe-components/test/test_promises.rb +260 -0
  144. data/scarpe-components/test/test_segmented_app_files.rb +182 -0
  145. data/{lib/scarpe → spikes}/glibui/widget.rb +2 -2
  146. data/{lib/scarpe → spikes}/glibui.rb +1 -1
  147. data/templates/basic_class_template.erb +1 -1
  148. data/templates/class_template_with_event_bind.erb +1 -1
  149. data/templates/class_template_with_shapes.erb +1 -1
  150. data/templates/webview_template.erb +0 -3
  151. metadata +165 -117
  152. data/examples/fill.rb +0 -25
  153. data/examples/legacy/not_checked/shoes-contrib/basic/class-book.yaml +0 -387
  154. data/examples/legacy/not_checked/shoes-contrib/good/good-clock.rb +0 -51
  155. data/examples/legacy/not_checked/shoes-contrib/good/good-follow.rb +0 -26
  156. data/examples/legacy/not_checked/shoes-contrib/good/good-reminder.rb +0 -174
  157. data/examples/legacy/not_checked/shoes-contrib/good/good-vjot.rb +0 -56
  158. data/examples/legacy/not_checked/shoes-contrib/simple/simple-timer.rb +0 -13
  159. data/examples/legacy/not_checked/shoes-dep-samples/good-clock.rb +0 -51
  160. data/examples/legacy/not_checked/shoes-dep-samples/good-follow.rb +0 -26
  161. data/examples/legacy/not_checked/shoes-dep-samples/good-reminder.rb +0 -174
  162. data/examples/legacy/not_checked/shoes-dep-samples/good-vjot.rb +0 -56
  163. data/examples/legacy/not_checked/shoes-dep-samples/simple-accordion.rb +0 -75
  164. data/examples/legacy/not_checked/shoes-dep-samples/simple-anim-shapes.rb +0 -17
  165. data/examples/legacy/not_checked/shoes-dep-samples/simple-anim-text.rb +0 -13
  166. data/examples/legacy/not_checked/shoes-dep-samples/simple-arc.rb +0 -23
  167. data/examples/legacy/not_checked/shoes-dep-samples/simple-bounce.rb +0 -24
  168. data/examples/legacy/not_checked/shoes-dep-samples/simple-calc.rb +0 -70
  169. data/examples/legacy/not_checked/shoes-dep-samples/simple-chipmunk.rb +0 -26
  170. data/examples/legacy/not_checked/shoes-dep-samples/simple-control-sizes.rb +0 -24
  171. data/examples/legacy/not_checked/shoes-dep-samples/simple-curve.rb +0 -26
  172. data/examples/legacy/not_checked/shoes-dep-samples/simple-dialogs.rb +0 -29
  173. data/examples/legacy/not_checked/shoes-dep-samples/simple-draw.rb +0 -13
  174. data/examples/legacy/not_checked/shoes-dep-samples/simple-editor.rb +0 -28
  175. data/examples/legacy/not_checked/shoes-dep-samples/simple-form.rb +0 -28
  176. data/examples/legacy/not_checked/shoes-dep-samples/simple-form.shy +0 -0
  177. data/examples/legacy/not_checked/shoes-dep-samples/simple-mask.rb +0 -21
  178. data/examples/legacy/not_checked/shoes-dep-samples/simple-menu.rb +0 -31
  179. data/examples/legacy/not_checked/shoes-dep-samples/simple-menu1.rb +0 -35
  180. data/examples/legacy/not_checked/shoes-dep-samples/simple-rubygems.rb +0 -29
  181. data/examples/legacy/not_checked/shoes-dep-samples/simple-slide.rb +0 -45
  182. data/examples/legacy/not_checked/shoes-dep-samples/simple-sphere.rb +0 -28
  183. data/examples/legacy/not_checked/shoes-dep-samples/simple-sqlite3.rb +0 -13
  184. data/examples/legacy/not_checked/shoes-dep-samples/simple-timer.rb +0 -13
  185. data/examples/legacy/not_checked/shoes-dep-samples/simple-video.rb +0 -13
  186. data/examples/legacy/not_checked/simple/anim-text.rb +0 -13
  187. data/examples/legacy/not_checked/simple/arc.rb +0 -23
  188. data/examples/legacy/not_checked/simple/bounce.rb +0 -24
  189. data/examples/legacy/not_checked/simple/chipmunk.rb +0 -26
  190. data/examples/legacy/not_checked/simple/curve.rb +0 -26
  191. data/examples/legacy/not_checked/simple/dialogs.rb +0 -29
  192. data/examples/legacy/not_checked/simple/downloader.rb +0 -40
  193. data/examples/legacy/not_checked/simple/draw.rb +0 -13
  194. data/examples/legacy/not_checked/simple/mask.rb +0 -21
  195. data/examples/legacy/not_checked/simple/slide.rb +0 -45
  196. data/examples/legacy/not_checked/simple/sphere.rb +0 -28
  197. data/lib/constants.rb +0 -5
  198. data/lib/scarpe/app.rb +0 -78
  199. data/lib/scarpe/document_root.rb +0 -20
  200. data/lib/scarpe/fill.rb +0 -23
  201. data/lib/scarpe/flow.rb +0 -19
  202. data/lib/scarpe/line.rb +0 -25
  203. data/lib/scarpe/logger.rb +0 -155
  204. data/lib/scarpe/shape.rb +0 -19
  205. data/lib/scarpe/spacing.rb +0 -9
  206. data/lib/scarpe/stack.rb +0 -70
  207. data/lib/scarpe/text_widget.rb +0 -42
  208. data/lib/scarpe/unit_test_helpers.rb +0 -163
  209. data/lib/scarpe/widgets.rb +0 -30
  210. data/lib/scarpe/wv/fill.rb +0 -30
  211. data/lib/scarpe/wv/shape_helper.rb +0 -44
  212. /data/{lib/scarpe → spikes}/glibui/README.md +0 -0
  213. /data/{lib/scarpe → spikes}/glibui/alert.rb +0 -0
  214. /data/{lib/scarpe → spikes}/glibui/app.rb +0 -0
  215. /data/{lib/scarpe → spikes}/glibui/background.rb +0 -0
  216. /data/{lib/scarpe → spikes}/glibui/border.rb +0 -0
  217. /data/{lib/scarpe → spikes}/glibui/button.rb +0 -0
  218. /data/{lib/scarpe → spikes}/glibui/dimensions.rb +0 -0
  219. /data/{lib/scarpe → spikes}/glibui/document_root.rb +0 -0
  220. /data/{lib/scarpe → spikes}/glibui/edit_box.rb +0 -0
  221. /data/{lib/scarpe → spikes}/glibui/edit_line.rb +0 -0
  222. /data/{lib/scarpe → spikes}/glibui/flow.rb +0 -0
  223. /data/{lib/scarpe → spikes}/glibui/html.rb +0 -0
  224. /data/{lib/scarpe → spikes}/glibui/image.rb +0 -0
  225. /data/{lib/scarpe → spikes}/glibui/link.rb +0 -0
  226. /data/{lib/scarpe → spikes}/glibui/local_display.rb +0 -0
  227. /data/{lib/scarpe → spikes}/glibui/para.rb +0 -0
  228. /data/{lib/scarpe → spikes}/glibui/spacing.rb +0 -0
  229. /data/{lib/scarpe → spikes}/glibui/stack.rb +0 -0
  230. /data/{lib/scarpe → spikes}/glibui/text_widget.rb +0 -0
  231. /data/{lib/scarpe → spikes}/libui/alert.rb +0 -0
  232. /data/{lib/scarpe → spikes}/libui/button.rb +0 -0
  233. /data/{lib/scarpe → spikes}/libui/colors.rb +0 -0
  234. /data/{lib/scarpe → spikes}/libui/core.rb +0 -0
  235. /data/{lib/scarpe → spikes}/libui/flow.rb +0 -0
  236. /data/{lib/scarpe → spikes}/libui/libui.rb +0 -0
  237. /data/{lib/scarpe → spikes}/libui/notepad.md +0 -0
  238. /data/{lib/scarpe → spikes}/libui/para.rb +0 -0
  239. /data/{lib/scarpe → spikes}/libui/stack.rb +0 -0
@@ -0,0 +1,260 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ require "scarpe/components/promises"
6
+
7
+ class TestPromises < Minitest::Test
8
+ Promise = Scarpe::Promise
9
+
10
+ def setup
11
+ # Save so we can restore it post-test
12
+ @normal_log_config = Shoes::Log.current_log_config
13
+
14
+ # For these tests, don't log anything
15
+ Shoes::Log.configure_logger("default" => "fatal")
16
+ end
17
+
18
+ def teardown
19
+ # Restore previous log config
20
+ Shoes::Log.configure_logger(@normal_log_config)
21
+ end
22
+
23
+ def empty_promise_with_checker(state: nil, parents: [])
24
+ # Initially, no handlers have been called
25
+ called = {
26
+ fulfilled: false,
27
+ rejected: false,
28
+ scheduled: false,
29
+ }
30
+ p = Promise.new(state: state, parents: parents)
31
+ p.on_fulfilled { called[:fulfilled] = true }
32
+ p.on_rejected { called[:rejected] = true }
33
+ p.on_scheduled { called[:scheduled] = true }
34
+
35
+ [p, called]
36
+ end
37
+
38
+ def promise_that_immediately_returns(val, parents: [])
39
+ Promise.fulfilled(val, parents: parents)
40
+ end
41
+
42
+ def test_simple_promise_fulfillment
43
+ p, called = empty_promise_with_checker
44
+
45
+ p.fulfilled!
46
+
47
+ assert_equal true, called[:fulfilled], "Promise fulfilled handler wasn't called successfully on simple fulfillment!"
48
+ assert_equal false, called[:rejected], "Promise rejection handler was called on simple fulfillment!"
49
+ assert_equal true, called[:scheduled], "Promise scheduled handler wasn't called on simple fulfillment!"
50
+ end
51
+
52
+ def test_simple_promise_fulfillment_accessor
53
+ p = Promise.new
54
+
55
+ p.fulfilled!
56
+
57
+ assert_equal true, p.fulfilled?, "Promise fulfilled? accessor failed!"
58
+ assert_equal false, p.rejected?, "Promise rejected? accessor failed!"
59
+ end
60
+
61
+ def test_simple_promise_rejection_accessor
62
+ p = Promise.new
63
+
64
+ p.rejected!
65
+
66
+ assert_equal false, p.fulfilled?, "Promise fulfilled? accessor failed!"
67
+ assert_equal true, p.rejected?, "Promise rejected? accessor failed!"
68
+ end
69
+
70
+ def test_simple_promise_rejection
71
+ p, called = empty_promise_with_checker
72
+
73
+ p.rejected!
74
+
75
+ assert_equal false, called[:fulfilled], "Promise wasn't called successfully on simple rejection!"
76
+ assert_equal true, called[:rejected], "Promise rejection handler wasn't called on simple rejection!"
77
+
78
+ # Here's a fun thing - the on_scheduled handler *will* be called, but only if there's no incomplete
79
+ # parent, because effectively the promise will be scheduled during construction.
80
+ assert_equal true, called[:scheduled], "Promise scheduled handler wasn't called on simple rejection!"
81
+ end
82
+
83
+ def test_dependent_promise_fulfillment
84
+ parent_promise = Promise.new
85
+ promise, called = empty_promise_with_checker(parents: [parent_promise])
86
+
87
+ # If a promise has an incomplete parent, it will start as unscheduled
88
+ assert_equal :unscheduled, promise.state
89
+ assert_equal false, called[:scheduled]
90
+
91
+ parent_promise.fulfilled!
92
+
93
+ # After the parent is complete, it will be scheduled
94
+ assert_equal :pending, promise.state
95
+ assert_equal true, called[:scheduled]
96
+ end
97
+
98
+ def test_dependent_promise_rejection
99
+ parent_promise = Promise.new
100
+ promise, called = empty_promise_with_checker(parents: [parent_promise])
101
+
102
+ # If a promise has an incomplete parent, it will start as unscheduled
103
+ assert_equal :unscheduled, promise.state
104
+ assert_equal false, called[:scheduled]
105
+
106
+ parent_promise.rejected!
107
+
108
+ # After the parent is rejected, it will be rejected
109
+ assert_equal :rejected, promise.state
110
+ assert_equal false, called[:scheduled]
111
+ assert_equal true, called[:rejected]
112
+ end
113
+
114
+ def test_promise_with_initial_rejected_parent
115
+ parent1_promise = Promise.new
116
+ parent2_promise = Promise.rejected
117
+ promise, called = empty_promise_with_checker(parents: [parent1_promise, parent2_promise])
118
+
119
+ assert_equal :rejected, promise.state
120
+
121
+ assert_equal false, called[:scheduled]
122
+ assert_equal false, called[:fulfilled]
123
+ assert_equal true, called[:rejected]
124
+ end
125
+
126
+ def test_multiparent_fulfillment
127
+ parent1_promise = Promise.new
128
+ parent2_promise = Promise.new
129
+ promise, called = empty_promise_with_checker(parents: [parent1_promise, parent2_promise])
130
+
131
+ parent1_promise.fulfilled!
132
+
133
+ assert_equal :unscheduled, promise.state
134
+ assert_equal false, called[:scheduled]
135
+
136
+ parent2_promise.fulfilled!
137
+
138
+ # After the parents are complete, it will be scheduled
139
+ assert_equal :pending, promise.state
140
+ assert_equal true, called[:scheduled]
141
+ end
142
+
143
+ def test_multiparent_rejection
144
+ parent1_promise = Promise.new
145
+ parent2_promise = Promise.new
146
+ promise, called = empty_promise_with_checker(parents: [parent1_promise, parent2_promise])
147
+
148
+ parent1_promise.rejected!
149
+
150
+ assert_equal :rejected, promise.state
151
+ assert_equal false, called[:scheduled]
152
+ assert_equal true, called[:rejected]
153
+ end
154
+
155
+ def test_instant_fulfillment
156
+ p = promise_that_immediately_returns(7)
157
+ assert_equal :fulfilled, p.state
158
+ assert_equal 7, p.returned_value, "The promise should be fulfilled with a value of 7!"
159
+ end
160
+
161
+ def test_multiparent_instant_fulfillment_with_args
162
+ parents = [
163
+ promise_that_immediately_returns(7),
164
+ promise_that_immediately_returns(5),
165
+ promise_that_immediately_returns(8),
166
+ ]
167
+ assert_equal true, parents.all? { |p| p.complete? && p.returned_value.is_a?(Integer) }
168
+ sum_up_promise = Promise.new(parents: parents)
169
+ sum_up_promise.to_execute { |*args| args.sum }
170
+
171
+ assert_equal :fulfilled, sum_up_promise.state
172
+ assert_equal 20, sum_up_promise.returned_value
173
+ end
174
+
175
+ def test_multiparent_delayed_fulfillment_with_args
176
+ parents = [
177
+ Promise.new,
178
+ promise_that_immediately_returns(10),
179
+ Promise.new,
180
+ Promise.new,
181
+ ]
182
+ sum_up_promise = Promise.new(parents: parents)
183
+ sum_up_promise.to_execute { |*args| args.sum }
184
+
185
+ parents[0].fulfilled!(3)
186
+ parents[2].fulfilled!(8)
187
+
188
+ assert_equal false, sum_up_promise.complete?
189
+
190
+ parents[3].fulfilled!(9)
191
+
192
+ assert_equal :fulfilled, sum_up_promise.state
193
+ assert_equal 30, sum_up_promise.returned_value
194
+ end
195
+
196
+ def test_simple_executor_success
197
+ p = Promise.new
198
+ p.to_execute { 7 }
199
+
200
+ assert_equal :fulfilled, p.state
201
+ assert_equal 7, p.returned_value
202
+ end
203
+
204
+ def test_simple_executor_failure
205
+ expected_err = RuntimeError.new "Yup, that's an error"
206
+ p = Promise.new
207
+ p.to_execute { raise expected_err }
208
+
209
+ assert_equal :rejected, p.state
210
+ assert_equal expected_err, p.reason
211
+ end
212
+
213
+ def test_delayed_executor_success
214
+ parent = Promise.new
215
+ p = Promise.new(parents: [parent])
216
+ p.to_execute { 7 }
217
+
218
+ assert_equal :unscheduled, p.state
219
+
220
+ parent.fulfilled!
221
+
222
+ assert_equal :fulfilled, p.state
223
+ assert_equal 7, p.returned_value
224
+ end
225
+
226
+ def test_scheduler_raise_error
227
+ expected_err = StandardError.new "Yup, that's an error"
228
+ p = Promise.new { raise expected_err }
229
+
230
+ assert_equal :rejected, p.state
231
+ assert_equal expected_err, p.reason, "Promise should record the raised error as the reason for rejection!"
232
+ end
233
+
234
+ def test_explicit_rejected_error
235
+ expected_err = StandardError.new "Yup, that's an error"
236
+ p = Promise.new
237
+
238
+ p.rejected!(expected_err)
239
+
240
+ assert_equal expected_err, p.reason, "Promise should record the raised error as the reason for rejection!"
241
+ end
242
+
243
+ def test_then_with_success
244
+ called = {
245
+ p1_scheduled: false,
246
+ p2_scheduled: false,
247
+ p3_scheduled: false,
248
+ }
249
+ p1 = Promise.new { called[:p1_scheduled] = true }
250
+ p1.then { called[:p2_scheduled] = true }.then { called[:p3_scheduled] = true }
251
+
252
+ assert_equal true, called[:p1_scheduled]
253
+ assert_equal false, called[:p2_scheduled]
254
+
255
+ p1.fulfilled!
256
+
257
+ assert_equal true, called[:p2_scheduled]
258
+ assert_equal false, called[:p3_scheduled]
259
+ end
260
+ end
@@ -0,0 +1,182 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "test_helper"
4
+
5
+ require "scarpe/components/segmented_file_loader"
6
+
7
+ SEG_TEST_DATA = {}
8
+
9
+ class TestSegmentedAppFiles < Minitest::Test
10
+ def setup
11
+ @orig_file_loaders = Shoes.file_loaders
12
+ Shoes.reset_file_loaders # create new loaders array with no overlap with @orig_file_loaders
13
+ SEG_TEST_DATA.clear
14
+
15
+ @loader = Scarpe::Components::SegmentedFileLoader.new
16
+ Shoes.add_file_loader @loader
17
+ end
18
+
19
+ def teardown
20
+ Shoes.set_file_loaders(@orig_file_loaders)
21
+ end
22
+
23
+ def test_add_segment_type
24
+ @loader.add_segment_type("new_seg_type", proc { true })
25
+ end
26
+
27
+ def test_default_single_segment_with_front_matter
28
+ app = <<~SEG_TEST_FILE
29
+ ---
30
+ front_matter: yes
31
+ ----- app code
32
+ SEG_TEST_DATA[:app_ran] = true
33
+ SEG_TEST_FILE
34
+ with_tempfile(["segfile_test_app", ".scas"], app) do |app_file|
35
+ Shoes.run_app(app_file)
36
+ end
37
+
38
+ assert_equal({ app_ran: true }, SEG_TEST_DATA)
39
+ end
40
+
41
+ def test_default_single_segment_no_front_matter_with_initial_name
42
+ app = <<~SEG_TEST_FILE
43
+ ----- app code
44
+ SEG_TEST_DATA[:app_ran] = true
45
+ SEG_TEST_FILE
46
+ with_tempfile(["segfile_test_app", ".scas"], app) do |app_file|
47
+ Shoes.run_app(app_file)
48
+ end
49
+
50
+ assert_equal({ app_ran: true }, SEG_TEST_DATA)
51
+ end
52
+
53
+ def test_default_single_segment_no_front_matter_no_initial_name
54
+ app = <<~SEG_TEST_FILE
55
+ SEG_TEST_DATA[:app_ran] = true
56
+ SEG_TEST_FILE
57
+ with_tempfile(["segfile_test_app", ".scas"], app) do |app_file|
58
+ Shoes.run_app(app_file)
59
+ end
60
+
61
+ assert_equal({ app_ran: true }, SEG_TEST_DATA)
62
+ end
63
+
64
+ def test_default_double_segment_with_front_matter
65
+ app = <<~SEG_TEST_FILE
66
+ ---
67
+ front_matter: yes
68
+ ----- app code
69
+ SEG_TEST_DATA[:app_ran] = true
70
+ eval File.read(ENV['SCARPE_APP_TEST']) # run test code
71
+ ----- test code
72
+ SEG_TEST_DATA[:test_ran] = true
73
+ SEG_TEST_FILE
74
+ with_tempfile(["segfile_test_app", ".scas"], app) do |app_file|
75
+ Shoes.run_app(app_file)
76
+ end
77
+
78
+ assert_equal({ app_ran: true, test_ran: true }, SEG_TEST_DATA)
79
+ end
80
+
81
+ def test_empty_front_matter
82
+ app = <<~SEG_TEST_FILE
83
+ ---
84
+ ----- app code
85
+ SEG_TEST_DATA[:app_ran] = true
86
+ eval File.read(ENV['SCARPE_APP_TEST']) # run test code
87
+ ----- test code
88
+ SEG_TEST_DATA[:test_ran] = true
89
+ SEG_TEST_FILE
90
+ with_tempfile(["segfile_test_app", ".scas"], app) do |app_file|
91
+ Shoes.run_app(app_file)
92
+ end
93
+
94
+ assert_equal({ app_ran: true, test_ran: true }, SEG_TEST_DATA)
95
+ end
96
+
97
+ def test_default_double_segment_no_front_matter_with_initial_name
98
+ app = <<~SEG_TEST_FILE
99
+ ----- app code
100
+ SEG_TEST_DATA[:app_ran] = true
101
+ eval File.read(ENV['SCARPE_APP_TEST']) # run test code
102
+ ----- test code
103
+ SEG_TEST_DATA[:test_ran] = true
104
+ SEG_TEST_FILE
105
+ with_tempfile(["segfile_test_app", ".scas"], app) do |app_file|
106
+ Shoes.run_app(app_file)
107
+ end
108
+
109
+ assert_equal({ app_ran: true, test_ran: true }, SEG_TEST_DATA)
110
+ end
111
+
112
+ def test_unnamed_double_segments
113
+ app = <<~SEG_TEST_FILE
114
+ -----
115
+ SEG_TEST_DATA[:app_ran] = true
116
+ eval File.read(ENV['SCARPE_APP_TEST']) # run test code
117
+ -----
118
+ SEG_TEST_DATA[:test_ran] = true
119
+ SEG_TEST_FILE
120
+ with_tempfile(["segfile_test_app", ".scas"], app) do |app_file|
121
+ Shoes.run_app(app_file)
122
+ end
123
+
124
+ assert_equal({ app_ran: true, test_ran: true }, SEG_TEST_DATA)
125
+ end
126
+
127
+ def test_default_double_segment_no_front_matter_no_initial_name
128
+ app = <<~SEG_TEST_FILE
129
+ SEG_TEST_DATA[:app_ran] = true
130
+ eval File.read(ENV['SCARPE_APP_TEST']) # run test code
131
+ ----- test code
132
+ SEG_TEST_DATA[:test_ran] = true
133
+ SEG_TEST_FILE
134
+ with_tempfile(["segfile_test_app", ".scas"], app) do |app_file|
135
+ Shoes.run_app(app_file)
136
+ end
137
+
138
+ assert_equal({ app_ran: true, test_ran: true }, SEG_TEST_DATA)
139
+ end
140
+
141
+ def test_extra_dashes_in_dividers
142
+ app = <<~SEG_TEST_FILE
143
+ ---
144
+ front_matter: yes
145
+ ---------------- app code
146
+ SEG_TEST_DATA[:app_ran] = true
147
+ eval File.read(ENV['SCARPE_APP_TEST']) # run test code
148
+ ------- test code
149
+ SEG_TEST_DATA[:test_ran] = true
150
+ SEG_TEST_FILE
151
+ with_tempfile(["segfile_test_app", ".scas"], app) do |app_file|
152
+ Shoes.run_app(app_file)
153
+ end
154
+
155
+ assert_equal({ app_ran: true, test_ran: true }, SEG_TEST_DATA)
156
+ end
157
+
158
+ def test_custom_segment_types
159
+ # "shoes" type already exists and evaluates the code, don't need to add it
160
+ @loader.add_segment_type("capybara", proc { |path| load path })
161
+ @loader.add_segment_type("extra_data", proc { |path| load path })
162
+
163
+ app = <<~SEG_TEST_FILE
164
+ ---
165
+ :segments:
166
+ - shoes
167
+ - capybara
168
+ - extra_data
169
+ -----
170
+ SEG_TEST_DATA[:shoes_ran] = true
171
+ -----
172
+ SEG_TEST_DATA[:capy_ran] = true
173
+ -----
174
+ SEG_TEST_DATA[:extra_data_ran] = true
175
+ SEG_TEST_FILE
176
+ with_tempfile(["segfile_test_app", ".scas"], app) do |app_file|
177
+ Shoes.run_app(app_file)
178
+ end
179
+
180
+ assert_equal({ shoes_ran: true, capy_ran: true, extra_data_ran: true }, SEG_TEST_DATA)
181
+ end
182
+ end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Scarpe
4
- class GlimmerLibUIWidget < DisplayService::Linkable
4
+ class GlimmerLibUIWidget < Shoes::Linkable
5
5
  class << self
6
6
  def display_class_for(scarpe_class_name)
7
7
  scarpe_class = Scarpe.const_get(scarpe_class_name)
8
- unless scarpe_class.ancestors.include?(Scarpe::DisplayService::Linkable)
8
+ unless scarpe_class.ancestors.include?(Shoes::Linkable)
9
9
  raise "Scarpe GlimmerLibUI can only get display classes for Scarpe linkable widgets, not #{scarpe_class.inspect}!"
10
10
  end
11
11
 
@@ -26,4 +26,4 @@ require_relative "glibui/alert"
26
26
  require_relative "glibui/text_widget"
27
27
  require_relative "glibui/link"
28
28
 
29
- Scarpe::DisplayService.set_display_service_class(Scarpe::GlimmerLibUIDisplayService)
29
+ Shoes::DisplayService.set_display_service_class(Scarpe::GlimmerLibUIDisplayService)
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  class Scarpe
5
- class <%= argument %> < Scarpe::Widget
5
+ class <%= argument %> < Shoes::Widget
6
6
 
7
7
  # Display Properties
8
8
  # These properties determine the visual characteristics of the widget
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Scarpe
4
- class <%= argument %> < Scarpe::Widget
4
+ class <%= argument %> < Shoes::Widget
5
5
  display_properties <%= display_properties %> # Write your display proporties here
6
6
 
7
7
  def initialize(text, width: nil, height: nil, top: nil, left: nil, &block)
@@ -3,7 +3,7 @@
3
3
  class Scarpe
4
4
  class InvalidAttributeValueError < StandardError; end
5
5
 
6
- class <%= argument %> < Scarpe::Widget
6
+ class <%= argument %> < Shoes::Widget
7
7
  display_properties <%= display_properties %> # Write your display proporties here
8
8
 
9
9
  def initialize(left, top)
@@ -8,9 +8,6 @@ class Scarpe
8
8
 
9
9
  end
10
10
 
11
- super
12
- end
13
-
14
11
  def element
15
12
  HTML.render do |h|
16
13
  h.textarea(id: html_id, style: style)