scarpe 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.yardopts +11 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +112 -0
- data/README.md +31 -24
- data/Rakefile +13 -1
- data/docs/yard/catscradle.md +44 -0
- data/docs/yard/template/default/fulldoc/html/setup.rb +13 -0
- data/docs/yard/template/default/layout/html/setup.rb +9 -0
- data/examples/background_with_image.rb +16 -0
- data/examples/bloopsaphone/working/bronx_army_knife.rb +66 -0
- data/examples/bloopsaphone/working/morning_serenity.rb +21 -0
- data/examples/bloopsaphone/working/simpsons_theme_song_by_why.rb +6 -4
- data/examples/button_go_away.rb +1 -1
- data/examples/check.rb +18 -0
- data/examples/clear_and_append.rb +24 -0
- data/examples/download_and_show_image.rb +28 -0
- data/examples/edit_box.rb +3 -5
- data/examples/fonts.rb +2 -2
- data/examples/get_headers.rb +10 -0
- data/examples/highlander.rb +2 -0
- data/examples/link.rb +2 -2
- data/examples/local_fonts.rb +4 -0
- data/examples/local_images.rb +4 -0
- data/examples/motion_events.rb +20 -0
- data/examples/parse_xl_funnies.rb +58 -0
- data/examples/radio/radio.rb +16 -0
- data/examples/radio/radio_groups.rb +18 -0
- data/examples/radio/radio_same_slot.rb +6 -0
- data/examples/ruby_racer.rb +13 -15
- data/examples/selfitude.rb +18 -0
- data/examples/shapes/shapes_fill.rb +4 -3
- data/examples/shoes_school.rb +2 -4
- data/examples/show_hide.rb +6 -0
- data/examples/skip_ci/change_my_audio_source.rb +21 -0
- data/examples/skip_ci/guitar_fretboard.rb +137 -0
- data/examples/video.rb +10 -0
- data/exe/scarpe +42 -66
- data/fonts/Pacifico.ttf +0 -0
- data/lacci/Gemfile +22 -0
- data/lacci/Gemfile.lock +72 -0
- data/lacci/Rakefile +12 -0
- data/lacci/lacci.gemspec +37 -0
- data/lacci/lib/lacci/scarpe_cli.rb +70 -0
- data/lacci/lib/lacci/scarpe_core.rb +21 -0
- data/lacci/lib/lacci/version.rb +13 -0
- data/lacci/lib/shoes/app.rb +264 -0
- data/{lib/scarpe → lacci/lib/shoes}/background.rb +1 -1
- data/{lib/scarpe → lacci/lib/shoes}/border.rb +1 -1
- data/{lib/scarpe → lacci/lib/shoes}/colors.rb +1 -1
- data/lacci/lib/shoes/constants.rb +29 -0
- data/{lib/scarpe → lacci/lib/shoes}/display_service.rb +40 -45
- data/lacci/lib/shoes/download.rb +123 -0
- data/lacci/lib/shoes/log.rb +71 -0
- data/lacci/lib/shoes/spacing.rb +9 -0
- data/{lib/scarpe → lacci/lib/shoes}/widget.rb +63 -43
- data/{lib/scarpe → lacci/lib/shoes/widgets}/alert.rb +3 -3
- data/{lib/scarpe → lacci/lib/shoes/widgets}/arc.rb +7 -5
- data/{lib/scarpe → lacci/lib/shoes/widgets}/button.rb +3 -3
- data/lacci/lib/shoes/widgets/check.rb +28 -0
- data/lacci/lib/shoes/widgets/document_root.rb +20 -0
- data/{lib/scarpe → lacci/lib/shoes/widgets}/edit_box.rb +10 -5
- data/{lib/scarpe → lacci/lib/shoes/widgets}/edit_line.rb +2 -2
- data/lacci/lib/shoes/widgets/flow.rb +22 -0
- data/lacci/lib/shoes/widgets/font.rb +14 -0
- data/{lib/scarpe → lacci/lib/shoes/widgets}/image.rb +3 -7
- data/lacci/lib/shoes/widgets/line.rb +18 -0
- data/{lib/scarpe → lacci/lib/shoes/widgets}/link.rb +2 -2
- data/{lib/scarpe → lacci/lib/shoes/widgets}/list_box.rb +2 -2
- data/{lib/scarpe → lacci/lib/shoes/widgets}/para.rb +4 -26
- data/lacci/lib/shoes/widgets/radio.rb +35 -0
- data/lacci/lib/shoes/widgets/shape.rb +37 -0
- data/lacci/lib/shoes/widgets/slot.rb +75 -0
- data/{lib/scarpe → lacci/lib/shoes/widgets}/span.rb +2 -2
- data/lacci/lib/shoes/widgets/stack.rb +24 -0
- data/{lib/scarpe → lacci/lib/shoes/widgets}/star.rb +6 -9
- data/lacci/lib/shoes/widgets/subscription_item.rb +60 -0
- data/lacci/lib/shoes/widgets/text_widget.rb +51 -0
- data/lacci/lib/shoes/widgets/video.rb +15 -0
- data/lacci/lib/shoes/widgets.rb +29 -0
- data/lacci/lib/shoes.rb +127 -0
- data/lacci/test/test_colors.rb +39 -0
- data/lacci/test/test_helper.rb +9 -0
- data/lacci/test/test_lacci.rb +9 -0
- data/lib/scarpe/cats_cradle.rb +249 -0
- data/lib/scarpe/evented_assertions.rb +88 -0
- data/lib/scarpe/version.rb +1 -1
- data/lib/scarpe/wv/alert.rb +3 -2
- data/lib/scarpe/wv/app.rb +30 -8
- data/lib/scarpe/wv/arc.rb +5 -6
- data/lib/scarpe/wv/background.rb +10 -1
- data/lib/scarpe/wv/border.rb +5 -3
- data/lib/scarpe/wv/button.rb +11 -9
- data/lib/scarpe/wv/check.rb +29 -0
- data/lib/scarpe/wv/control_interface.rb +14 -20
- data/lib/scarpe/wv/control_interface_test.rb +13 -28
- data/lib/scarpe/wv/document_root.rb +3 -45
- data/lib/scarpe/wv/edit_box.rb +5 -7
- data/lib/scarpe/wv/edit_line.rb +2 -2
- data/lib/scarpe/wv/flow.rb +10 -20
- data/lib/scarpe/wv/font.rb +36 -0
- data/lib/scarpe/wv/html.rb +3 -2
- data/lib/scarpe/wv/image.rb +7 -2
- data/lib/scarpe/wv/line.rb +4 -7
- data/lib/scarpe/wv/link.rb +1 -0
- data/lib/scarpe/wv/list_box.rb +3 -3
- data/lib/scarpe/wv/para.rb +16 -14
- data/lib/scarpe/wv/radio.rb +34 -0
- data/lib/scarpe/wv/shape.rb +44 -8
- data/lib/scarpe/wv/slot.rb +81 -0
- data/lib/scarpe/wv/spacing.rb +1 -1
- data/lib/scarpe/wv/span.rb +10 -8
- data/lib/scarpe/wv/stack.rb +10 -30
- data/lib/scarpe/wv/star.rb +11 -12
- data/lib/scarpe/wv/subscription_item.rb +50 -0
- data/lib/scarpe/wv/video.rb +34 -0
- data/lib/scarpe/wv/web_wrangler.rb +238 -58
- data/lib/scarpe/wv/webview_local_display.rb +27 -5
- data/lib/scarpe/wv/webview_relay_display.rb +18 -119
- data/lib/scarpe/wv/webview_relay_util.rb +143 -0
- data/lib/scarpe/wv/widget.rb +80 -11
- data/lib/scarpe/wv/wv_display_worker.rb +17 -4
- data/lib/scarpe/wv.rb +33 -4
- data/lib/scarpe/wv_local.rb +1 -1
- data/lib/scarpe/wv_relay.rb +1 -1
- data/lib/scarpe.rb +3 -32
- data/scarpe-components/.gitignore +1 -0
- data/scarpe-components/Gemfile +22 -0
- data/scarpe-components/README.md +35 -0
- data/scarpe-components/Rakefile +12 -0
- data/scarpe-components/lib/scarpe/components/base64.rb +29 -0
- data/scarpe-components/lib/scarpe/components/file_helpers.rb +65 -0
- data/scarpe-components/lib/scarpe/components/modular_logger.rb +113 -0
- data/scarpe-components/lib/scarpe/components/print_logger.rb +43 -0
- data/{lib/scarpe → scarpe-components/lib/scarpe/components}/promises.rb +102 -35
- data/scarpe-components/lib/scarpe/components/segmented_file_loader.rb +170 -0
- data/scarpe-components/lib/scarpe/components/unit_test_helpers.rb +217 -0
- data/scarpe-components/lib/scarpe/components/version.rb +7 -0
- data/scarpe-components/scarpe-components.gemspec +38 -0
- data/scarpe-components/test/test_components.rb +9 -0
- data/scarpe-components/test/test_helper.rb +23 -0
- data/scarpe-components/test/test_promises.rb +260 -0
- data/scarpe-components/test/test_segmented_app_files.rb +182 -0
- data/{lib/scarpe → spikes}/glibui/widget.rb +2 -2
- data/{lib/scarpe → spikes}/glibui.rb +1 -1
- data/templates/basic_class_template.erb +1 -1
- data/templates/class_template_with_event_bind.erb +1 -1
- data/templates/class_template_with_shapes.erb +1 -1
- data/templates/webview_template.erb +0 -3
- metadata +165 -117
- data/examples/fill.rb +0 -25
- data/examples/legacy/not_checked/shoes-contrib/basic/class-book.yaml +0 -387
- data/examples/legacy/not_checked/shoes-contrib/good/good-clock.rb +0 -51
- data/examples/legacy/not_checked/shoes-contrib/good/good-follow.rb +0 -26
- data/examples/legacy/not_checked/shoes-contrib/good/good-reminder.rb +0 -174
- data/examples/legacy/not_checked/shoes-contrib/good/good-vjot.rb +0 -56
- data/examples/legacy/not_checked/shoes-contrib/simple/simple-timer.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/good-clock.rb +0 -51
- data/examples/legacy/not_checked/shoes-dep-samples/good-follow.rb +0 -26
- data/examples/legacy/not_checked/shoes-dep-samples/good-reminder.rb +0 -174
- data/examples/legacy/not_checked/shoes-dep-samples/good-vjot.rb +0 -56
- data/examples/legacy/not_checked/shoes-dep-samples/simple-accordion.rb +0 -75
- data/examples/legacy/not_checked/shoes-dep-samples/simple-anim-shapes.rb +0 -17
- data/examples/legacy/not_checked/shoes-dep-samples/simple-anim-text.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/simple-arc.rb +0 -23
- data/examples/legacy/not_checked/shoes-dep-samples/simple-bounce.rb +0 -24
- data/examples/legacy/not_checked/shoes-dep-samples/simple-calc.rb +0 -70
- data/examples/legacy/not_checked/shoes-dep-samples/simple-chipmunk.rb +0 -26
- data/examples/legacy/not_checked/shoes-dep-samples/simple-control-sizes.rb +0 -24
- data/examples/legacy/not_checked/shoes-dep-samples/simple-curve.rb +0 -26
- data/examples/legacy/not_checked/shoes-dep-samples/simple-dialogs.rb +0 -29
- data/examples/legacy/not_checked/shoes-dep-samples/simple-draw.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/simple-editor.rb +0 -28
- data/examples/legacy/not_checked/shoes-dep-samples/simple-form.rb +0 -28
- data/examples/legacy/not_checked/shoes-dep-samples/simple-form.shy +0 -0
- data/examples/legacy/not_checked/shoes-dep-samples/simple-mask.rb +0 -21
- data/examples/legacy/not_checked/shoes-dep-samples/simple-menu.rb +0 -31
- data/examples/legacy/not_checked/shoes-dep-samples/simple-menu1.rb +0 -35
- data/examples/legacy/not_checked/shoes-dep-samples/simple-rubygems.rb +0 -29
- data/examples/legacy/not_checked/shoes-dep-samples/simple-slide.rb +0 -45
- data/examples/legacy/not_checked/shoes-dep-samples/simple-sphere.rb +0 -28
- data/examples/legacy/not_checked/shoes-dep-samples/simple-sqlite3.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/simple-timer.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/simple-video.rb +0 -13
- data/examples/legacy/not_checked/simple/anim-text.rb +0 -13
- data/examples/legacy/not_checked/simple/arc.rb +0 -23
- data/examples/legacy/not_checked/simple/bounce.rb +0 -24
- data/examples/legacy/not_checked/simple/chipmunk.rb +0 -26
- data/examples/legacy/not_checked/simple/curve.rb +0 -26
- data/examples/legacy/not_checked/simple/dialogs.rb +0 -29
- data/examples/legacy/not_checked/simple/downloader.rb +0 -40
- data/examples/legacy/not_checked/simple/draw.rb +0 -13
- data/examples/legacy/not_checked/simple/mask.rb +0 -21
- data/examples/legacy/not_checked/simple/slide.rb +0 -45
- data/examples/legacy/not_checked/simple/sphere.rb +0 -28
- data/lib/constants.rb +0 -5
- data/lib/scarpe/app.rb +0 -78
- data/lib/scarpe/document_root.rb +0 -20
- data/lib/scarpe/fill.rb +0 -23
- data/lib/scarpe/flow.rb +0 -19
- data/lib/scarpe/line.rb +0 -25
- data/lib/scarpe/logger.rb +0 -155
- data/lib/scarpe/shape.rb +0 -19
- data/lib/scarpe/spacing.rb +0 -9
- data/lib/scarpe/stack.rb +0 -70
- data/lib/scarpe/text_widget.rb +0 -42
- data/lib/scarpe/unit_test_helpers.rb +0 -163
- data/lib/scarpe/widgets.rb +0 -30
- data/lib/scarpe/wv/fill.rb +0 -30
- data/lib/scarpe/wv/shape_helper.rb +0 -44
- /data/{lib/scarpe → spikes}/glibui/README.md +0 -0
- /data/{lib/scarpe → spikes}/glibui/alert.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/app.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/background.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/border.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/button.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/dimensions.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/document_root.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/edit_box.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/edit_line.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/flow.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/html.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/image.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/link.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/local_display.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/para.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/spacing.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/stack.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/text_widget.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/alert.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/button.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/colors.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/core.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/flow.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/libui.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/notepad.md +0 -0
- /data/{lib/scarpe → spikes}/libui/para.rb +0 -0
- /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 <
|
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?(
|
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
|
-
|
29
|
+
Shoes::DisplayService.set_display_service_class(Scarpe::GlimmerLibUIDisplayService)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Scarpe
|
4
|
-
class <%= argument %> <
|
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)
|