glimmer 0.1.5.470 → 0.1.8.470

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +2 -0
  5. data/README.markdown +7 -2
  6. data/Rakefile +7 -8
  7. data/TODO.md +1 -1
  8. data/VERSION +1 -1
  9. data/bin/girb +3 -0
  10. data/bin/girb_runner.rb +5 -0
  11. data/glimmer.gemspec +29 -19
  12. data/lib/glimmer_application.rb +1 -2
  13. data/lib/shine.rb +23 -21
  14. data/lib/xml_command_handlers/models/node.rb +11 -11
  15. data/lib/xml_command_handlers/models/xml_visitor.rb +12 -12
  16. data/samples/tictactoe/tic_tac_toe.rb +11 -11
  17. data/spec/lib/command_handlers/models/observable_model_spec.rb +22 -0
  18. data/spec/lib/command_handlers/models/r_widget_spec.rb +52 -0
  19. data/{test/glimmer_combo_data_binding_test.rb → spec/lib/glimmer__combo_data_binding__spec.rb} +48 -49
  20. data/spec/lib/glimmer__constant__spec.rb +30 -0
  21. data/{test/glimmer_data_binding_test.rb → spec/lib/glimmer__data_binding__spec.rb} +95 -94
  22. data/spec/lib/glimmer__list_data_binding__spec.rb +224 -0
  23. data/{test/glimmer_listeners_test.rb → spec/lib/glimmer__listeners__spec.rb} +18 -19
  24. data/spec/lib/glimmer__shine_data_binding__spec.rb +89 -0
  25. data/spec/lib/glimmer__tab_item__spec.rb +55 -0
  26. data/spec/lib/glimmer__table_data_binding__spec.rb +121 -0
  27. data/spec/lib/glimmer_spec.rb +251 -0
  28. data/spec/lib/xml/glimmer_xml_spec.rb +154 -0
  29. data/spec/samples/contactmanager/contact_manager_presenter_spec.rb +81 -0
  30. data/spec/samples/tictactoe/tic_tac_toe_spec.rb +263 -0
  31. data/spec/spec_helper.rb +123 -0
  32. metadata +50 -17
  33. data/test/glimmer_constant_test.rb +0 -30
  34. data/test/glimmer_list_data_binding_test.rb +0 -223
  35. data/test/glimmer_shine_data_binding_test.rb +0 -89
  36. data/test/glimmer_tab_item_test.rb +0 -61
  37. data/test/glimmer_table_data_binding_test.rb +0 -122
  38. data/test/glimmer_test.rb +0 -237
  39. data/test/helper.rb +0 -24
  40. data/test/observable_model_test.rb +0 -25
  41. data/test/r_widget_test.rb +0 -52
  42. data/test/samples/contactmanager/contact_manager_presenter_test.rb +0 -81
  43. data/test/samples/tictactoe/tic_tac_toe_test.rb +0 -262
  44. data/test/xml/glimmer_xml_test.rb +0 -163
@@ -0,0 +1,224 @@
1
+ require "spec_helper"
2
+
3
+ describe "Glimmer List Data Binding" do
4
+ include Glimmer
5
+
6
+ include_package 'org.eclipse.swt'
7
+ include_package 'org.eclipse.swt.widgets'
8
+ include_package 'org.eclipse.swt.layout'
9
+
10
+ SWT = org.eclipse.swt.SWT unless Object.const_defined?(:SWT)
11
+
12
+ before do
13
+ dsl :swt
14
+ end
15
+
16
+ after do
17
+ @target.display.dispose if @target.display
18
+ end
19
+
20
+ class Person
21
+ attr_accessor :country, :country_options
22
+ attr_accessor :provinces, :provinces_options
23
+
24
+ def initialize
25
+ self.country_options=[
26
+ "",
27
+ "Canada",
28
+ "US",
29
+ "Mexico"
30
+ ]
31
+ self.provinces_options=[
32
+ "",
33
+ "Quebec",
34
+ "Ontario",
35
+ "Manitoba",
36
+ "Saskatchewan",
37
+ "Alberta",
38
+ "British Columbia",
39
+ "Nova Skotia",
40
+ "Newfoundland"
41
+ ]
42
+ end
43
+ end
44
+
45
+ it "tests single selection property" do
46
+ person = Person.new
47
+
48
+ @target = shell {
49
+ @list = list {
50
+ selection bind(person, :country)
51
+ }
52
+ }
53
+
54
+ expect(@list.widget.item_count).to eq(4)
55
+ expect(@list.widget.selection_index).to eq(-1)
56
+ expect(@list.widget.selection.to_a).to eq([])
57
+
58
+ @list.widget.select(1)
59
+ @list.widget.notifyListeners(SWT::Selection, nil)
60
+ expect(person.country).to eq("Canada")
61
+
62
+ person.country_options << "France"
63
+
64
+ expect(@list.widget.item_count).to eq(5)
65
+
66
+ person.country_options=["", "Canada", "US", "Mexico", "Russia", "France"]
67
+
68
+ expect(@list.widget.item_count).to eq(6)
69
+
70
+ person.country_options << "Italy"
71
+ person.country_options << "Germany"
72
+ person.country_options << "Australia"
73
+
74
+ expect(@list.widget.item_count).to eq(9)
75
+
76
+ person.country = "Canada"
77
+
78
+ expect(@list.widget.selection_index).to eq(1)
79
+ expect(@list.widget.selection.to_a).to eq(["Canada"])
80
+
81
+ person.country = "Russia"
82
+
83
+ expect(@list.widget.selection_index).to eq(4)
84
+ expect(@list.widget.selection.to_a).to eq(["Russia"])
85
+
86
+ person.country = ""
87
+
88
+ expect(@list.widget.selection_index).to eq(0)
89
+ expect(@list.widget.selection.to_a).to eq([""])
90
+
91
+ person.country = "Japan"
92
+
93
+ expect(@list.widget.selection_index).to eq(0)
94
+ expect(@list.widget.selection.to_a).to eq([""])
95
+
96
+ @list.widget.select(2)
97
+ @list.widget.notifyListeners(SWT::Selection, nil)
98
+ expect(person.country).to eq("US")
99
+ end
100
+
101
+ it "tests single selection property with model preinitialized" do
102
+ person = Person.new
103
+ person.country = "Canada"
104
+
105
+ @target = shell {
106
+ @list = list {
107
+ selection bind(person, :country)
108
+ }
109
+ }
110
+
111
+ expect(@list.widget.item_count).to eq(4)
112
+ expect(@list.widget.selection_index).to eq(1)
113
+ expect(@list.widget.selection.to_a).to eq(["Canada"])
114
+
115
+ @list.widget.select(2)
116
+ @list.widget.notifyListeners(SWT::Selection, nil)
117
+ expect(person.country).to eq("US")
118
+
119
+ person.country_options << "France"
120
+
121
+ expect(@list.widget.item_count).to eq(5)
122
+
123
+ person.country_options=["", "Canada", "US", "Mexico", "Russia", "France"]
124
+
125
+ expect(@list.widget.item_count).to eq(6)
126
+
127
+ person.country_options << "Italy"
128
+ person.country_options << "Germany"
129
+ person.country_options << "Australia"
130
+
131
+ expect(@list.widget.item_count).to eq(9)
132
+
133
+ person.country = "Canada"
134
+
135
+ expect(@list.widget.selection_index).to eq(1)
136
+ expect(@list.widget.selection.to_a).to eq(["Canada"])
137
+
138
+ person.country = "Russia"
139
+
140
+ expect(@list.widget.selection_index).to eq(4)
141
+ expect(@list.widget.selection.to_a).to eq(["Russia"])
142
+
143
+ person.country = ""
144
+
145
+ expect(@list.widget.selection_index).to eq(0)
146
+ expect(@list.widget.selection.to_a).to eq([""])
147
+
148
+ person.country = "Japan"
149
+
150
+ expect(@list.widget.selection_index).to eq(0)
151
+ expect(@list.widget.selection.to_a).to eq([""])
152
+ end
153
+
154
+ it "tests multi selection property" do
155
+ person = Person.new
156
+
157
+ @target = shell {
158
+ @list = list(:multi) {
159
+ selection bind(person, :provinces)
160
+ }
161
+ }
162
+
163
+ expect(@list.widget.selection_count.to_i).to eq(0)
164
+ expect(@list.widget.selection.to_a).to eq([])
165
+
166
+ @list.widget.select(1)
167
+ @list.widget.notifyListeners(SWT::Selection, nil)
168
+ expect(person.provinces).to eq(["Quebec"])
169
+
170
+ @list.widget.select(2)
171
+ @list.widget.notifyListeners(SWT::Selection, nil)
172
+ expect(person.provinces).to eq(["Quebec", "Ontario"])
173
+
174
+ person.provinces=["Ontario", "Manitoba", "Alberta"]
175
+
176
+ expect(@list.widget.selection_count.to_i).to eq(3)
177
+ expect(@list.widget.selection_indices.to_a).to eq([2, 3, 5])
178
+ expect(@list.widget.selection.to_a).to eq(["Ontario", "Manitoba", "Alberta"])
179
+
180
+ person.provinces << "Quebec"
181
+ person.provinces << "Saskatchewan"
182
+ person.provinces << "British Columbia"
183
+
184
+ expect(@list.widget.selection_count.to_i).to eq(6)
185
+ expect(@list.widget.selection_indices.to_a).to eq([1, 2, 3, 4, 5, 6])
186
+ expect(@list.widget.selection.to_a).to eq(["Quebec", "Ontario", "Manitoba", "Saskatchewan", "Alberta", "British Columbia"])
187
+ end
188
+
189
+ it "tests multi selection property with model preinitialized" do
190
+ person = Person.new
191
+ person.provinces = []
192
+
193
+ @target = shell {
194
+ @list = list(:multi) {
195
+ selection bind(person, :provinces)
196
+ }
197
+ }
198
+
199
+ expect(@list.widget.selection_count.to_i).to eq(0)
200
+ expect(@list.widget.selection.to_a).to eq([])
201
+
202
+ @list.widget.select(1)
203
+ @list.widget.notifyListeners(SWT::Selection, nil)
204
+ expect(person.provinces).to eq(["Quebec"])
205
+
206
+ @list.widget.select(2)
207
+ @list.widget.notifyListeners(SWT::Selection, nil)
208
+ expect(person.provinces).to eq(["Quebec", "Ontario"])
209
+
210
+ person.provinces=["Ontario", "Manitoba", "Alberta"]
211
+
212
+ expect(@list.widget.selection_count.to_i).to eq(3)
213
+ expect(@list.widget.selection_indices.to_a).to eq([2, 3, 5])
214
+ expect(@list.widget.selection.to_a).to eq(["Ontario", "Manitoba", "Alberta"])
215
+
216
+ person.provinces << "Quebec"
217
+ person.provinces << "Saskatchewan"
218
+ person.provinces << "British Columbia"
219
+
220
+ expect(@list.widget.selection_count.to_i).to eq(6)
221
+ expect(@list.widget.selection_indices.to_a).to eq([1, 2, 3, 4, 5, 6])
222
+ expect(@list.widget.selection.to_a).to eq(["Quebec", "Ontario", "Manitoba", "Saskatchewan", "Alberta", "British Columbia"])
223
+ end
224
+ end
@@ -1,25 +1,25 @@
1
- require_relative "helper"
1
+ require "spec_helper"
2
2
 
3
- class GlimmerDataBindingTest < Test::Unit::TestCase
3
+ describe "Glimmer Listeners" do
4
4
  include Glimmer
5
5
 
6
6
  include_package 'org.eclipse.swt'
7
7
  include_package 'org.eclipse.swt.widgets'
8
8
  include_package 'org.eclipse.swt.layout'
9
-
10
- def setup
9
+
10
+ before do
11
11
  dsl :swt
12
12
  end
13
13
 
14
- def teardown
14
+ after do
15
15
  @target.display.dispose if @target.display
16
16
  end
17
-
18
- class Person
17
+
18
+ class Person
19
19
  attr_accessor :name, :age, :adult
20
20
  end
21
-
22
- def test_text_widget_verify_listener
21
+
22
+ it "tests text widget verify listener" do
23
23
  @target = shell {
24
24
  composite {
25
25
  @text = text {
@@ -30,18 +30,18 @@ class GlimmerDataBindingTest < Test::Unit::TestCase
30
30
  }
31
31
  }
32
32
  }
33
-
33
+
34
34
  @text.widget.setText("Hi")
35
- assert_equal "Hi", @text.widget.getText
36
-
35
+ expect(@text.widget.getText).to eq("Hi")
36
+
37
37
  @text.widget.setText("Hello")
38
- assert_equal "Hi", @text.widget.getText
38
+ expect(@text.widget.getText).to eq("Hi")
39
39
  end
40
-
40
+
41
41
  def test_button_widget_selection_listener
42
42
  person = Person.new
43
43
  person.name = "Bruce Ting"
44
-
44
+
45
45
  @target = shell {
46
46
  composite {
47
47
  @button = button {
@@ -51,11 +51,10 @@ class GlimmerDataBindingTest < Test::Unit::TestCase
51
51
  }
52
52
  }
53
53
  }
54
- assert_equal "Bruce Ting", person.name
54
+ expect(person.name).to eq("Bruce Ting")
55
55
  @button.widget.setSelection(true)
56
56
  @button.widget.notifyListeners(SWT::Selection, nil)
57
- assert_equal "Bruce Lao", person.name
57
+ expect(person.name).to eq("Bruce Lao")
58
58
  end
59
-
60
- end
61
59
 
60
+ end
@@ -0,0 +1,89 @@
1
+ ## NOTE: Unsupported in Ruby 2 syntax
2
+ # require "spec_helper"
3
+ #
4
+ # require_relative "../../lib/shine"
5
+ #
6
+ # describe "Glimmer Shine Data Binding" do
7
+ # include Glimmer
8
+ #
9
+ # include_package 'org.eclipse.swt'
10
+ # include_package 'org.eclipse.swt.widgets'
11
+ # include_package 'org.eclipse.swt.layout'
12
+ #
13
+ # before do
14
+ # dsl :swt
15
+ # end
16
+ #
17
+ # after do
18
+ # @target.display.dispose if @target.display
19
+ # end
20
+ #
21
+ # class Person
22
+ # attr_accessor :name, :age, :adult
23
+ # end
24
+ #
25
+ # it "tests text_widget_data_binding_string_property_spaceship" do
26
+ # person = Person.new
27
+ # person.name = "Bruce Ting"
28
+ #
29
+ # @target = shell {
30
+ # composite {
31
+ # @text = text {
32
+ # }
33
+ # }
34
+ # }
35
+ #
36
+ # [@text, :text] <=> [person, :name]
37
+ #
38
+ # expect(@text.widget.getText).to eq( "Bruce Ting")
39
+ #
40
+ # person.name = "Lady Butterfly"
41
+ # expect(@text.widget.getText).to eq( "Lady Butterfly")
42
+ #
43
+ # @text.widget.setText("Allen Cork")
44
+ # expect(person.name).to eq( "Allen Cork")
45
+ #
46
+ # comparison = ["he"] <=> ["he"]
47
+ # expect(comparison).to eq(0)
48
+ # end
49
+ #
50
+ # it "tests multiple_widget_data_bindings_to_different_model_properties_spaceship" do
51
+ # person = Person.new
52
+ # person.name = "Nancy"
53
+ # person.age = 15
54
+ # person.adult = true
55
+ #
56
+ # @target = shell {
57
+ # composite {
58
+ # @label = label {}
59
+ # @text = text {}
60
+ # @check_box = button(:check) {}
61
+ # }
62
+ # }
63
+ #
64
+ # [@label, :text] <=> [person, :name]
65
+ # [@text, :text] <=> [person, :age, :fixnum]
66
+ # [@check_box, :selection] <=> [person, :adult]
67
+ #
68
+ # expect(@label.widget.getText).to eq( "Nancy")
69
+ # expect(@text.widget.getText).to eq( "15")
70
+ # expect(@check_box.widget.getSelection).to eq( true)
71
+ #
72
+ # person.name = "Drew"
73
+ # expect(@label.widget.getText).to eq( "Drew")
74
+ #
75
+ # person.age = 27
76
+ # expect(@text.widget.getText).to eq( "27")
77
+ #
78
+ # person.adult = false
79
+ # expect(@check_box.widget.getSelection).to eq( false)
80
+ #
81
+ # @text.widget.setText("30")
82
+ # expect(person.age).to eq( 30)
83
+ #
84
+ # @check_box.widget.setSelection(true)
85
+ # @check_box.widget.notifyListeners(SWT::Selection, nil)
86
+ # expect(person.adult).to eq( true)
87
+ # end
88
+ #
89
+ # end
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+
3
+ describe "Glimmer Tab Item" do
4
+ include Glimmer
5
+
6
+ before do
7
+ dsl :swt
8
+ end
9
+
10
+ after do
11
+ @target.display.dispose if @target.display
12
+ end
13
+
14
+ it "tests tab item composite with default layout" do
15
+ @target = shell {
16
+ @tab_folder = tab_folder {
17
+ @tab_item_composite = tab_item {
18
+ text "Tab 1"
19
+ label {text "Hello"}
20
+ }
21
+ }
22
+ }
23
+
24
+ expect(@target).to_not be_nil
25
+ expect(@target.widget).to_not be_nil
26
+ expect(@tab_folder.widget.items.size).to eq(1)
27
+ expect(@tab_item_composite.widget).to be_instance_of(org.eclipse.swt.widgets.Composite)
28
+ expect(@tab_folder.widget.items[0].control).to eq(@tab_item_composite.widget)
29
+ expect(@tab_item_composite.tab_item.widget.text).to eq("Tab 1")
30
+ expect(@tab_item_composite.widget.getLayout).to_not be_nil
31
+ expect(@tab_item_composite.widget.getLayout).to be_instance_of(org.eclipse.swt.layout.GridLayout)
32
+ end
33
+
34
+ it "tests tab item composite with fill layout" do
35
+ @target = shell {
36
+ @tab_folder = tab_folder {
37
+ @tab_item_composite = tab_item {
38
+ text "Tab 2"
39
+ layout org.eclipse.swt.layout.FillLayout.new
40
+ label {text "Hello"}
41
+ }
42
+ }
43
+ }
44
+
45
+ expect(@target).to_not be_nil
46
+ expect(@target.widget).to_not be_nil
47
+ expect(@tab_folder.widget.items.size).to eq(1)
48
+ expect(@tab_item_composite.widget).to be_instance_of(org.eclipse.swt.widgets.Composite)
49
+ expect(@tab_folder.widget.items[0].control).to eq(@tab_item_composite.widget)
50
+ expect(@tab_item_composite.tab_item.widget.text).to eq("Tab 2")
51
+ expect(@tab_item_composite.widget.getLayout).to_not be_nil
52
+ expect(@tab_item_composite.widget.getLayout).to be_instance_of(org.eclipse.swt.layout.FillLayout)
53
+ end
54
+
55
+ end
@@ -0,0 +1,121 @@
1
+ require "spec_helper"
2
+
3
+ describe "Glimmer Table Data Binding" do
4
+ include Glimmer
5
+
6
+ include_package 'org.eclipse.swt'
7
+ include_package 'org.eclipse.swt.widgets'
8
+ include_package 'org.eclipse.swt.layout'
9
+
10
+ before do
11
+ dsl :swt
12
+ end
13
+
14
+ after do
15
+ @target.display.dispose if @target.display
16
+ end
17
+
18
+ class Group
19
+ def initialize
20
+ @people = []
21
+ end
22
+
23
+ attr_accessor :people
24
+ end
25
+
26
+ class Person
27
+ attr_accessor :name, :age, :adult
28
+ end
29
+
30
+ it "data binds text widget to a string property" do
31
+ person1 = Person.new
32
+ person1.name = "Bruce Ting"
33
+ person1.age = 45
34
+ person1.adult = true
35
+
36
+ person2 = Person.new
37
+ person2.name = "Julia Fang"
38
+ person2.age = 17
39
+ person2.adult = false
40
+
41
+ group = Group.new
42
+ group.people << person1
43
+ group.people << person2
44
+
45
+ @target = shell {
46
+ @table = table {
47
+ table_column {
48
+ text "Name"
49
+ width 120
50
+ }
51
+ table_column {
52
+ text "Age"
53
+ width 120
54
+ }
55
+ table_column {
56
+ text "Adult"
57
+ width 120
58
+ }
59
+ items bind(group, :people), column_properties(:name, :age, :adult)
60
+ }
61
+ }
62
+
63
+ expect(@table.widget.getColumnCount).to eq(3)
64
+ expect(@table.widget.getItems.size).to eq(2)
65
+
66
+ expect(@table.widget.getItems[0].getText(0)).to eq("Bruce Ting")
67
+ expect(@table.widget.getItems[0].getText(1)).to eq("45")
68
+ expect(@table.widget.getItems[0].getText(2)).to eq("true")
69
+
70
+ expect(@table.widget.getItems[1].getText(0)).to eq("Julia Fang")
71
+ expect(@table.widget.getItems[1].getText(1)).to eq("17")
72
+ expect(@table.widget.getItems[1].getText(2)).to eq("false")
73
+
74
+ person3 = Person.new
75
+ person3.name = "Andrea Shingle"
76
+ person3.age = 23
77
+ person3.adult = true
78
+
79
+ group.people << person3
80
+
81
+ expect(@table.widget.getItems.size).to eq(3)
82
+ expect(@table.widget.getItems[2].getText(0)).to eq("Andrea Shingle")
83
+ expect(@table.widget.getItems[2].getText(1)).to eq("23")
84
+ expect(@table.widget.getItems[2].getText(2)).to eq("true")
85
+
86
+ group.people.delete person2
87
+
88
+ expect(@table.widget.getItems.size).to eq(2)
89
+ expect(@table.widget.getItems[1].getText(0)).to eq("Andrea Shingle")
90
+ expect(@table.widget.getItems[1].getText(1)).to eq("23")
91
+ expect(@table.widget.getItems[1].getText(2)).to eq("true")
92
+
93
+ group.people.delete_at(0)
94
+
95
+ expect(@table.widget.getItems.size).to eq(1)
96
+ expect(@table.widget.getItems[0].getText(0)).to eq("Andrea Shingle")
97
+ expect(@table.widget.getItems[0].getText(1)).to eq("23")
98
+ expect(@table.widget.getItems[0].getText(2)).to eq("true")
99
+
100
+ group.people.clear
101
+
102
+ expect(0).to eq(@table.widget.getItems.size)
103
+
104
+ group.people = [person2, person1]
105
+
106
+ expect(2).to eq(@table.widget.getItems.size)
107
+
108
+ expect(@table.widget.getItems[0].getText(0)).to eq("Julia Fang")
109
+ expect(@table.widget.getItems[0].getText(1)).to eq("17")
110
+ expect(@table.widget.getItems[0].getText(2)).to eq("false")
111
+
112
+ expect(@table.widget.getItems[1].getText(0)).to eq("Bruce Ting")
113
+ expect(@table.widget.getItems[1].getText(1)).to eq("45")
114
+ expect(@table.widget.getItems[1].getText(2)).to eq("true")
115
+
116
+ person1.name = "Bruce Flee"
117
+
118
+ expect(@table.widget.getItems[1].getText(0)).to eq("Bruce Flee")
119
+ end
120
+
121
+ end