glimmer 0.1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.LGPL +504 -0
- data/README +27 -0
- data/samples/contactmanager/contact.rb +12 -0
- data/samples/contactmanager/contact_manager.rb +65 -0
- data/samples/contactmanager/contact_manager_presenter.rb +23 -0
- data/samples/contactmanager/contact_repository.rb +27 -0
- data/samples/hello_world.rb +26 -0
- data/samples/login.rb +97 -0
- data/samples/tictactoe/tic_tac_toe.rb +67 -0
- data/samples/tictactoe/tic_tac_toe_board.rb +149 -0
- data/src/command_handler.rb +11 -0
- data/src/command_handler_chain_factory.rb +23 -0
- data/src/command_handler_chain_link.rb +22 -0
- data/src/command_handlers.rb +26 -0
- data/src/command_handlers/bind_command_handler.rb +29 -0
- data/src/command_handlers/data_binding_command_handler.rb +64 -0
- data/src/command_handlers/models/model_observer.rb +25 -0
- data/src/command_handlers/models/observable_array.rb +46 -0
- data/src/command_handlers/models/observable_model.rb +35 -0
- data/src/command_handlers/models/r_runnable.rb +14 -0
- data/src/command_handlers/models/r_shell.rb +27 -0
- data/src/command_handlers/models/r_widget.rb +146 -0
- data/src/command_handlers/models/r_widget_listener.rb +12 -0
- data/src/command_handlers/models/r_widget_packages.rb +9 -0
- data/src/command_handlers/models/table_items_updater.rb +39 -0
- data/src/command_handlers/models/widget_observer.rb +23 -0
- data/src/command_handlers/shell_command_handler.rb +18 -0
- data/src/command_handlers/swt_constant_command_handler.rb +22 -0
- data/src/command_handlers/table_column_properties_data_binding_command_handler.rb +24 -0
- data/src/command_handlers/table_items_data_binding_command_handler.rb +30 -0
- data/src/command_handlers/widget_command_handler.rb +26 -0
- data/src/command_handlers/widget_listener_command_handler.rb +35 -0
- data/src/command_handlers/widget_method_command_handler.rb +22 -0
- data/src/glimmer.rb +45 -0
- data/src/parent.rb +8 -0
- data/src/shine.rb +24 -0
- data/src/swt.rb +10 -0
- data/src/xml.rb +10 -0
- data/src/xml_command_handlers.rb +18 -0
- data/src/xml_command_handlers/html_command_handler.rb +49 -0
- data/src/xml_command_handlers/models/depth_first_search_iterator.rb +20 -0
- data/src/xml_command_handlers/models/name_space_visitor.rb +21 -0
- data/src/xml_command_handlers/models/node.rb +83 -0
- data/src/xml_command_handlers/models/node_visitor.rb +12 -0
- data/src/xml_command_handlers/models/xml_visitor.rb +62 -0
- data/src/xml_command_handlers/xml_command_handler.rb +22 -0
- data/src/xml_command_handlers/xml_name_space_command_handler.rb +34 -0
- data/src/xml_command_handlers/xml_tag_command_handler.rb +26 -0
- data/src/xml_command_handlers/xml_text_command_handler.rb +22 -0
- data/test/glimmer_constant_test.rb +36 -0
- data/test/glimmer_data_binding_test.rb +236 -0
- data/test/glimmer_listeners_test.rb +61 -0
- data/test/glimmer_shine_data_binding_test.rb +88 -0
- data/test/glimmer_table_data_binding_test.rb +135 -0
- data/test/glimmer_test.rb +233 -0
- data/test/observable_model_test.rb +27 -0
- data/test/r_widget_test.rb +52 -0
- data/test/samples/contactmanager/contact_manager_presenter_test.rb +60 -0
- data/test/samples/tictactoe/tic_tac_toe_test.rb +265 -0
- data/test/xml/glimmer_xml_test.rb +163 -0
- metadata +126 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright (C) 2007-2008 Annas Al Maleh
|
2
|
+
# Licensed under the LGPL. See /COPYING.LGPL for more details.
|
3
|
+
|
4
|
+
require "test/unit"
|
5
|
+
require File.dirname(__FILE__) + "/../src/command_handlers/models/observable_model"
|
6
|
+
|
7
|
+
require "test/unit"
|
8
|
+
class ObservableModelTest < Test::Unit::TestCase
|
9
|
+
class Person
|
10
|
+
attr_accessor :name
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_observe_model
|
14
|
+
person = Person.new
|
15
|
+
person.name = "Marty"
|
16
|
+
assert_equal "Marty", person.name
|
17
|
+
person.extend ObservableModel
|
18
|
+
person.add_observer(:name, self)
|
19
|
+
person.name = "Julia"
|
20
|
+
assert_equal "Julia", @observed_name
|
21
|
+
assert_equal "Julia", person.name
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(name)
|
25
|
+
@observed_name = name
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Copyright (C) 2007-2008 Annas Al Maleh
|
2
|
+
# Licensed under the LGPL. See /COPYING.LGPL for more details.
|
3
|
+
|
4
|
+
require "test/unit"
|
5
|
+
require File.dirname(__FILE__) + "/../src/swt"
|
6
|
+
|
7
|
+
class RWidgetTest < Test::Unit::TestCase
|
8
|
+
include Glimmer
|
9
|
+
|
10
|
+
def test_async_exec
|
11
|
+
@target = shell {
|
12
|
+
@text = text {
|
13
|
+
text "text1"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
@target.async_exec do
|
18
|
+
@text.widget.setText("text2")
|
19
|
+
end
|
20
|
+
|
21
|
+
@target.async_exec do
|
22
|
+
assert_equal "text2", @text.widget.getText
|
23
|
+
@target.widget.close
|
24
|
+
end
|
25
|
+
|
26
|
+
@target.open
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_sync_exec
|
30
|
+
@target = shell {
|
31
|
+
@text = text {
|
32
|
+
text "text1"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
@target.async_exec do
|
37
|
+
assert_equal "text2", @text.widget.getText
|
38
|
+
@text.widget.setText("text3")
|
39
|
+
end
|
40
|
+
|
41
|
+
@target.sync_exec do
|
42
|
+
@text.widget.setText("text2")
|
43
|
+
end
|
44
|
+
|
45
|
+
@target.async_exec do
|
46
|
+
@target.widget.close
|
47
|
+
end
|
48
|
+
|
49
|
+
@target.open
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Copyright (C) 2007-2008 Nick Malnick and Annas Al Maleh
|
2
|
+
# Licensed under the LGPL. See /COPYING.LGPL for more details.
|
3
|
+
|
4
|
+
require "test/unit"
|
5
|
+
require File.dirname(__FILE__) + "/../../../samples/contactmanager/contact_manager_presenter"
|
6
|
+
|
7
|
+
class ContactManagerPresenterTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def test_find_specify_all_fields_for_one_result
|
10
|
+
contact_manager_presenter = ContactManagerPresenter.new
|
11
|
+
contact_manager_presenter.first_name = "Frank"
|
12
|
+
contact_manager_presenter.last_name = "Deelio"
|
13
|
+
contact_manager_presenter.email = "frank@deelio.com"
|
14
|
+
contact_manager_presenter.find
|
15
|
+
contacts = contact_manager_presenter.results
|
16
|
+
assert_not_nil contacts
|
17
|
+
assert_equal 1, contacts.size
|
18
|
+
contact = contacts[0]
|
19
|
+
assert contact.is_a?(Contact)
|
20
|
+
assert_equal "Frank", contact.first_name
|
21
|
+
assert_equal "Deelio", contact.last_name
|
22
|
+
assert_equal "frank@deelio.com", contact.email
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_find_specify_one_field_for_two_results
|
26
|
+
contact_manager_presenter = ContactManagerPresenter.new
|
27
|
+
contact_manager_presenter.first_name = "Frank"
|
28
|
+
contact_manager_presenter.find
|
29
|
+
contacts = contact_manager_presenter.results
|
30
|
+
assert_not_nil contacts
|
31
|
+
assert_equal 2, contacts.size
|
32
|
+
contact1 = contacts[0]
|
33
|
+
contact2 = contacts[1]
|
34
|
+
assert_equal "Frank", contact1.first_name
|
35
|
+
assert_equal "Deelio", contact1.last_name
|
36
|
+
assert_equal "frank@deelio.com", contact1.email
|
37
|
+
assert_equal "franky", contact2.first_name
|
38
|
+
assert_equal "miller", contact2.last_name
|
39
|
+
assert_equal "frank@miller.com", contact2.email
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_find_specify_all_fields_for_no_results
|
43
|
+
contact_manager_presenter = ContactManagerPresenter.new
|
44
|
+
contact_manager_presenter.first_name = "Julia"
|
45
|
+
contact_manager_presenter.last_name = "Big"
|
46
|
+
contact_manager_presenter.email = "julia@big.com"
|
47
|
+
contact_manager_presenter.find
|
48
|
+
contacts = contact_manager_presenter.results
|
49
|
+
assert_not_nil contacts
|
50
|
+
assert_equal 0, contacts.size
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_initial_results
|
54
|
+
contact_manager_presenter = ContactManagerPresenter.new
|
55
|
+
contacts = contact_manager_presenter.results
|
56
|
+
assert_not_nil contacts
|
57
|
+
assert_equal 0, contacts.size
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,265 @@
|
|
1
|
+
# Copyright (C) 2007-2008 Nick Malnick and Annas Al Maleh
|
2
|
+
# Licensed under the LGPL. See /COPYING.LGPL for more details.
|
3
|
+
|
4
|
+
require "test/unit"
|
5
|
+
require File.dirname(__FILE__) + "/../../../samples/tictactoe/tic_tac_toe_board"
|
6
|
+
|
7
|
+
class TicTacToeTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@board = TicTacToeBoard.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_mark_center_x
|
14
|
+
assert_equal("", @board.box(2, 2).sign)
|
15
|
+
@board.mark_box(2, 2)
|
16
|
+
assert ! @board.box(2, 2).empty
|
17
|
+
assert_equal("X", @board.box(2, 2).sign)
|
18
|
+
assert @board.box(1, 1).empty
|
19
|
+
assert @board.box(1, 2).empty
|
20
|
+
assert @board.box(1, 3).empty
|
21
|
+
assert @board.box(2, 1).empty
|
22
|
+
assert @board.box(2, 3).empty
|
23
|
+
assert @board.box(3, 1).empty
|
24
|
+
assert @board.box(3, 2).empty
|
25
|
+
assert @board.box(3, 3).empty
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_mark_center_x_top_center_o_bottom_right_x
|
29
|
+
@board.mark_box(2, 2)
|
30
|
+
@board.mark_box(1, 2)
|
31
|
+
@board.mark_box(3, 3)
|
32
|
+
assert ! @board.box(2, 2).empty
|
33
|
+
assert ! @board.box(1, 2).empty
|
34
|
+
assert ! @board.box(3, 3).empty
|
35
|
+
assert_equal("X", @board.box(2, 2).sign)
|
36
|
+
assert_equal("O", @board.box(1, 2).sign)
|
37
|
+
assert_equal("X", @board.box(3, 3).sign)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_top_center_not_marked
|
41
|
+
assert @board.box(1, 2).empty
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_top_right_marked
|
45
|
+
@board.mark_box(1, 3)
|
46
|
+
assert ! @board.box(1, 3).empty
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_lower_right_marked
|
50
|
+
@board.mark_box(3, 3)
|
51
|
+
assert ! @board.box(3, 3).empty
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_game_over_false
|
55
|
+
assert ! @board.game_over?
|
56
|
+
assert_equal "X", @board.current_sign
|
57
|
+
assert_equal TicTacToeBoard::IN_PROGRESS, @board.game_status
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_game_over_X_wins_top_row_across
|
61
|
+
@board.mark_box(1, 1)
|
62
|
+
assert_equal("X", @board.box(1, 1).sign)
|
63
|
+
@board.mark_box(2, 1)
|
64
|
+
assert_equal("O", @board.box(2, 1).sign)
|
65
|
+
@board.mark_box(1, 2)
|
66
|
+
assert_equal("X", @board.box(1, 2).sign)
|
67
|
+
@board.mark_box(2, 2)
|
68
|
+
assert_equal("O", @board.box(2, 2).sign)
|
69
|
+
@board.mark_box(1, 3)
|
70
|
+
assert_equal("X", @board.box(1, 3).sign)
|
71
|
+
assert @board.game_over?
|
72
|
+
assert_equal "X", @board.winning_sign
|
73
|
+
assert_equal TicTacToeBoard::WIN, @board.game_status
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_game_over_O_wins_top_row_across
|
77
|
+
@board.mark_box(2, 1)
|
78
|
+
@board.mark_box(1, 1)
|
79
|
+
@board.mark_box(2, 2)
|
80
|
+
@board.mark_box(1, 2)
|
81
|
+
@board.mark_box(3, 3)
|
82
|
+
@board.mark_box(1, 3)
|
83
|
+
assert @board.game_over?
|
84
|
+
assert_equal "O", @board.winning_sign
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_game_over_X_wins_second_row_across
|
88
|
+
@board.mark_box(2, 1)
|
89
|
+
@board.mark_box(1, 1)
|
90
|
+
@board.mark_box(2, 2)
|
91
|
+
@board.mark_box(1, 2)
|
92
|
+
@board.mark_box(2, 3)
|
93
|
+
assert @board.game_over?
|
94
|
+
assert_equal "X", @board.winning_sign
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_game_over_O_wins_second_row_across
|
98
|
+
@board.mark_box(1, 1)
|
99
|
+
@board.mark_box(2, 1)
|
100
|
+
@board.mark_box(3, 1)
|
101
|
+
@board.mark_box(2, 2)
|
102
|
+
@board.mark_box(1, 2)
|
103
|
+
@board.mark_box(2, 3)
|
104
|
+
assert @board.game_over?
|
105
|
+
assert_equal "O", @board.winning_sign
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_game_over_X_wins_third_row_across
|
109
|
+
@board.mark_box(3, 1)
|
110
|
+
@board.mark_box(1, 1)
|
111
|
+
@board.mark_box(3, 2)
|
112
|
+
@board.mark_box(1, 2)
|
113
|
+
@board.mark_box(3, 3)
|
114
|
+
assert @board.game_over?
|
115
|
+
assert_equal "X", @board.winning_sign
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_game_over_O_wins_third_row_across
|
119
|
+
@board.mark_box(1, 1)
|
120
|
+
@board.mark_box(3, 1)
|
121
|
+
@board.mark_box(1, 2)
|
122
|
+
@board.mark_box(3, 2)
|
123
|
+
@board.mark_box(2, 3)
|
124
|
+
@board.mark_box(3, 3)
|
125
|
+
assert @board.game_over?
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_game_over_X_wins_first_column_down
|
129
|
+
@board.mark_box(1, 1)
|
130
|
+
@board.mark_box(2, 2)
|
131
|
+
@board.mark_box(2, 1)
|
132
|
+
@board.mark_box(3, 2)
|
133
|
+
@board.mark_box(3, 1)
|
134
|
+
assert @board.game_over?
|
135
|
+
assert_equal "X", @board.winning_sign
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_game_over_O_wins_first_column_down
|
139
|
+
@board.mark_box(2, 2)
|
140
|
+
@board.mark_box(1, 1)
|
141
|
+
@board.mark_box(3, 2)
|
142
|
+
@board.mark_box(2, 1)
|
143
|
+
@board.mark_box(3, 3)
|
144
|
+
@board.mark_box(3, 1)
|
145
|
+
assert @board.game_over?
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_game_over_X_wins_second_column_down
|
149
|
+
@board.mark_box(1, 2)
|
150
|
+
@board.mark_box(2, 1)
|
151
|
+
@board.mark_box(2, 2)
|
152
|
+
@board.mark_box(3, 1)
|
153
|
+
@board.mark_box(3, 2)
|
154
|
+
assert @board.game_over?
|
155
|
+
assert_equal "X", @board.winning_sign
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_game_over_O_wins_second_column_down
|
159
|
+
@board.mark_box(2, 1)
|
160
|
+
@board.mark_box(1, 2)
|
161
|
+
@board.mark_box(3, 1)
|
162
|
+
@board.mark_box(2, 2)
|
163
|
+
@board.mark_box(2, 3)
|
164
|
+
@board.mark_box(3, 2)
|
165
|
+
assert @board.game_over?
|
166
|
+
assert_equal "O", @board.winning_sign
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_game_over_X_wins_third_column_down
|
170
|
+
@board.mark_box(1, 3)
|
171
|
+
@board.mark_box(2, 1)
|
172
|
+
@board.mark_box(2, 3)
|
173
|
+
@board.mark_box(3, 1)
|
174
|
+
@board.mark_box(3, 3)
|
175
|
+
assert @board.game_over?
|
176
|
+
assert_equal "X", @board.winning_sign
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_game_over_O_wins_third_column_down
|
180
|
+
@board.mark_box(2, 1)
|
181
|
+
@board.mark_box(1, 3)
|
182
|
+
@board.mark_box(3, 1)
|
183
|
+
@board.mark_box(2, 3)
|
184
|
+
@board.mark_box(3, 2)
|
185
|
+
@board.mark_box(3, 3)
|
186
|
+
assert @board.game_over?
|
187
|
+
assert_equal "O", @board.winning_sign
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_game_over_X_wins_top_left_to_bottom_right
|
191
|
+
@board.mark_box(1, 1)
|
192
|
+
@board.mark_box(2, 1)
|
193
|
+
@board.mark_box(2, 2)
|
194
|
+
@board.mark_box(3, 2)
|
195
|
+
@board.mark_box(3, 3)
|
196
|
+
assert_equal "X", @board.winning_sign
|
197
|
+
assert @board.game_over?
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_game_over_O_wins_top_left_to_bottom_right
|
201
|
+
@board.mark_box(2, 1)
|
202
|
+
@board.mark_box(1, 1)
|
203
|
+
@board.mark_box(3, 2)
|
204
|
+
@board.mark_box(2, 2)
|
205
|
+
@board.mark_box(2, 3)
|
206
|
+
@board.mark_box(3, 3)
|
207
|
+
assert_equal "O", @board.winning_sign
|
208
|
+
assert @board.game_over?
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_game_over_X_wins_top_right_to_bottom_left
|
212
|
+
@board.mark_box(1, 3)
|
213
|
+
@board.mark_box(2, 1)
|
214
|
+
@board.mark_box(2, 2)
|
215
|
+
@board.mark_box(3, 2)
|
216
|
+
@board.mark_box(3, 1)
|
217
|
+
assert_equal "X", @board.winning_sign
|
218
|
+
assert @board.game_over?
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_game_over_O_wins_top_right_to_bottom_left
|
222
|
+
@board.mark_box(2, 1)
|
223
|
+
@board.mark_box(1, 3)
|
224
|
+
@board.mark_box(3, 2)
|
225
|
+
@board.mark_box(2, 2)
|
226
|
+
@board.mark_box(1, 1)
|
227
|
+
@board.mark_box(3, 1)
|
228
|
+
assert_equal "O", @board.winning_sign
|
229
|
+
assert @board.game_over?
|
230
|
+
end
|
231
|
+
|
232
|
+
# 1 2 3
|
233
|
+
#1 x o x
|
234
|
+
#2 o x x
|
235
|
+
#3 o x o
|
236
|
+
def test_game_over_draw
|
237
|
+
@board.mark_box(1, 1)
|
238
|
+
@board.mark_box(1, 2)
|
239
|
+
@board.mark_box(1, 3)
|
240
|
+
@board.mark_box(2, 1)
|
241
|
+
@board.mark_box(2, 2)
|
242
|
+
@board.mark_box(3, 1)
|
243
|
+
@board.mark_box(2, 3)
|
244
|
+
@board.mark_box(3, 3)
|
245
|
+
assert ! @board.game_over?
|
246
|
+
@board.mark_box(3, 2)
|
247
|
+
assert @board.game_over?
|
248
|
+
assert_equal TicTacToeBox::EMPTY, @board.winning_sign
|
249
|
+
assert_equal TicTacToeBoard::DRAW, @board.game_status
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_reset
|
253
|
+
@board.mark_box(1, 3)
|
254
|
+
@board.mark_box(2, 1)
|
255
|
+
@board.mark_box(2, 2)
|
256
|
+
@board.mark_box(3, 2)
|
257
|
+
@board.mark_box(3, 1)
|
258
|
+
@board.reset
|
259
|
+
assert ! @board.game_over?
|
260
|
+
assert_equal TicTacToeBox::EMPTY, @board.winning_sign
|
261
|
+
assert_equal TicTacToeBoard::IN_PROGRESS, @board.game_status
|
262
|
+
assert_equal "X", @board.current_sign
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
# Copyright (C) 2007-2008 Annas Al Maleh
|
2
|
+
# Licensed under the LGPL. See /COPYING.LGPL for more details.
|
3
|
+
|
4
|
+
require "test/unit"
|
5
|
+
require File.dirname(__FILE__) + "/../../src/parent"
|
6
|
+
require File.dirname(__FILE__) + "/../../src/xml"
|
7
|
+
|
8
|
+
class GlimmerXmlTest < Test::Unit::TestCase
|
9
|
+
include Glimmer
|
10
|
+
|
11
|
+
def test_single_html_tag
|
12
|
+
@target = html
|
13
|
+
|
14
|
+
assert_not_nil @target
|
15
|
+
assert_equal "<html/>", @target.to_xml
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_single_document_tag_upper_case
|
19
|
+
@target = tag(:_name => "DOCUMENT")
|
20
|
+
|
21
|
+
assert_not_nil @target
|
22
|
+
assert_equal "<DOCUMENT/>", @target.to_xml
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_open_and_closed_html_tag
|
26
|
+
@target = html {}
|
27
|
+
|
28
|
+
assert_not_nil @target
|
29
|
+
assert_equal "<html></html>", @target.to_xml
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_open_and_closed_html_tag_with_contents
|
33
|
+
@target = html { "This is an HTML Document" }
|
34
|
+
|
35
|
+
assert_not_nil @target
|
36
|
+
assert_equal "<html>This is an HTML Document</html>", @target.to_xml
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_open_and_closed_html_tag_with_contents
|
40
|
+
@target = html { "This is an HTML Document" }
|
41
|
+
|
42
|
+
assert_not_nil @target
|
43
|
+
assert_equal "<html>This is an HTML Document</html>", @target.to_xml
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_open_and_closed_html_tag_with_attributes
|
47
|
+
@target = html(:id => "thesis", :class => "document") {
|
48
|
+
}
|
49
|
+
|
50
|
+
assert_not_nil @target
|
51
|
+
assert_equal '<html id="thesis" class="document"></html>', @target.to_xml
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_open_and_closed_html_tag_with_attributes_and_nested_body_with_attributes
|
55
|
+
@target = html(:id => "thesis", :class => "document") {
|
56
|
+
body(:id => "main") {
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
assert_not_nil @target
|
61
|
+
assert_equal '<html id="thesis" class="document"><body id="main"></body></html>', @target.to_xml
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_tag_with_contents_before_and_after_nested_tag
|
65
|
+
@target = html(:id => "thesis", :class => "document") {
|
66
|
+
text "Before body"
|
67
|
+
body(:id => "main") {
|
68
|
+
}
|
69
|
+
text "When a string is the last part of the tag contents, text prefix is optional"
|
70
|
+
}
|
71
|
+
|
72
|
+
assert_not_nil @target
|
73
|
+
assert_equal '<html id="thesis" class="document">Before body<body id="main"></body>When a string is the last part of the tag contents, text prefix is optional</html>', @target.to_xml
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_different_name_spaced_tags
|
77
|
+
@target = w3c.html(:id => "thesis", :class => "document") {
|
78
|
+
document.body(:id => "main") {
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
assert_not_nil @target
|
83
|
+
assert_equal '<w3c:html id="thesis" class="document"><document:body id="main"></document:body></w3c:html>', @target.to_xml
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_different_name_spaced_attributes_and_tags
|
87
|
+
@target = w3c.html(w3c.id => "thesis", :class => "document") {
|
88
|
+
document.body(document.id => "main") {
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
assert_not_nil @target
|
93
|
+
assert_equal '<w3c:html w3c:id="thesis" class="document"><document:body document:id="main"></document:body></w3c:html>', @target.to_xml
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_name_space_context
|
97
|
+
@target = name_space(:w3c) {
|
98
|
+
html(:id => "thesis", :class => "document") {
|
99
|
+
body(:id => "main") {
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
assert_not_nil @target
|
105
|
+
assert_equal '<w3c:html id="thesis" class="document"><w3c:body id="main"></w3c:body></w3c:html>', @target.to_xml
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_two_name_space_contexts
|
109
|
+
@target = name_space(:w3c) {
|
110
|
+
html(:id => "thesis", :class => "document") {
|
111
|
+
name_space(:document) {
|
112
|
+
sectionDivider(:id => "main") {
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
assert_not_nil @target
|
119
|
+
assert_equal '<w3c:html id="thesis" class="document"><document:sectionDivider id="main"></document:sectionDivider></w3c:html>', @target.to_xml
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_two_name_space_contexts_including_contents
|
123
|
+
@target = name_space(:w3c) {
|
124
|
+
html(:id => "thesis", :class => "document") {
|
125
|
+
text "before section divider"
|
126
|
+
name_space(:document) {
|
127
|
+
sectionDivider(:id => "main") {
|
128
|
+
"section divider"
|
129
|
+
}
|
130
|
+
}
|
131
|
+
text "after section divider"
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
assert_not_nil @target
|
136
|
+
assert_equal '<w3c:html id="thesis" class="document">before section divider<document:sectionDivider id="main">section divider</document:sectionDivider>after section divider</w3c:html>', @target.to_xml
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_mixed_contents_custom_syntax
|
140
|
+
@target = html{"before section divider#strong{section divider}after section divider"}
|
141
|
+
|
142
|
+
assert_not_nil @target
|
143
|
+
assert_equal '<html>before section divider<strong>section divider</strong>after section divider</html>', @target.to_xml
|
144
|
+
end
|
145
|
+
|
146
|
+
#TODO handle special characters such as #, {, }, and .
|
147
|
+
#TODO CDATA support
|
148
|
+
#TODO encode special characters
|
149
|
+
|
150
|
+
def test_html_alternative_syntax_for_id_and_class_attributes
|
151
|
+
@target = html_thesis_document {
|
152
|
+
body_main {
|
153
|
+
h1__title
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
assert_not_nil @target
|
158
|
+
assert_equal '<html id="thesis" class="document"><body id="main"><h1 class="title" /></body></html>', @target.to_xml
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
|