rtext 0.9.0 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +113 -98
  3. data/Project.yaml +14 -0
  4. data/RText_Protocol +1 -1
  5. data/lib/rtext/default_completer.rb +212 -208
  6. data/lib/rtext/frontend/connector.rb +122 -55
  7. data/lib/rtext/instantiator.rb +11 -3
  8. data/lib/rtext/service.rb +264 -260
  9. metadata +18 -44
  10. data/Rakefile +0 -46
  11. data/test/completer_test.rb +0 -607
  12. data/test/context_builder_test.rb +0 -949
  13. data/test/frontend/context_test.rb +0 -302
  14. data/test/instantiator_test.rb +0 -1733
  15. data/test/integration/backend.out +0 -16
  16. data/test/integration/crash_on_request_editor.rb +0 -12
  17. data/test/integration/ecore_editor.rb +0 -50
  18. data/test/integration/frontend.log +0 -40058
  19. data/test/integration/model/invalid_encoding.invenc +0 -2
  20. data/test/integration/model/test.crash_on_request +0 -18
  21. data/test/integration/model/test.crashing_backend +0 -18
  22. data/test/integration/model/test.dont_open_socket +0 -0
  23. data/test/integration/model/test.invalid_cmd_line +0 -0
  24. data/test/integration/model/test.not_in_rtext +0 -0
  25. data/test/integration/model/test_large_with_errors.ect3 +0 -43523
  26. data/test/integration/model/test_metamodel.ect +0 -24
  27. data/test/integration/model/test_metamodel2.ect +0 -5
  28. data/test/integration/model/test_metamodel3.ect4 +0 -7
  29. data/test/integration/model/test_metamodel_error.ect2 +0 -3
  30. data/test/integration/model/test_metamodel_ok.ect2 +0 -18
  31. data/test/integration/test.rb +0 -968
  32. data/test/link_detector_test.rb +0 -288
  33. data/test/message_helper_test.rb +0 -117
  34. data/test/rtext_test.rb +0 -11
  35. data/test/serializer_test.rb +0 -1024
  36. data/test/tokenizer_test.rb +0 -174
@@ -1,288 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
-
3
- gem 'minitest'
4
- require 'minitest/autorun'
5
- require 'rgen/metamodel_builder'
6
- require 'rtext/language'
7
- require 'rtext/link_detector'
8
-
9
- class LinkDetectorTest < MiniTest::Test
10
-
11
- module TestMM
12
- extend RGen::MetamodelBuilder::ModuleExtension
13
- class TestNode2 < RGen::MetamodelBuilder::MMBase
14
- has_attr 'name', String
15
- end
16
- class TestNode < RGen::MetamodelBuilder::MMBase
17
- has_attr 'name', String
18
- has_attr 'id', Integer
19
- has_one 'related', TestNode
20
- has_many 'others', TestNode
21
- contains_many 'children', TestNode2, 'parent'
22
- end
23
- end
24
-
25
- def test_before_command
26
- ld = build_link_desc TestMM, <<-END
27
- |TestNode SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
28
- END
29
- assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => true, :value => "TestNode", :scol => 1, :ecol => 8
30
- end
31
-
32
- def test_in_command
33
- ld = build_link_desc TestMM, <<-END
34
- Test|Node SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
35
- END
36
- assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => true, :value => "TestNode", :scol => 1, :ecol => 8
37
- end
38
-
39
- def test_end_of_command
40
- ld = build_link_desc TestMM, <<-END
41
- TestNod|e SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
42
- END
43
- assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => true, :value => "TestNode", :scol => 1, :ecol => 8
44
- end
45
-
46
- def test_after_command
47
- ld = build_link_desc TestMM, <<-END
48
- TestNode| SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
49
- END
50
- assert_nil ld
51
- end
52
-
53
- def test_in_name
54
- ld = build_link_desc TestMM, <<-END
55
- TestNode So|meNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
56
- END
57
- assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => false, :value => "SomeNode", :scol => 10, :ecol => 17
58
- end
59
-
60
- def test_in_name_with_quotes
61
- ld = build_link_desc TestMM, <<-END
62
- TestNode "So|meNode", id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
63
- END
64
- assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => false, :value => "SomeNode", :scol => 10, :ecol => 19
65
- end
66
-
67
- def test_after_comma
68
- ld = build_link_desc TestMM, <<-END
69
- TestNode SomeNode,| id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
70
- END
71
- assert_nil ld
72
- end
73
-
74
- def test_after_label
75
- ld = build_link_desc TestMM, <<-END
76
- TestNode SomeNode, id:| 1234, related: /Other/Node, others: [/NodeA, /Node/B]
77
- END
78
- assert_nil ld
79
- end
80
-
81
- def test_beginning_of_labled_argument
82
- ld = build_link_desc TestMM, <<-END
83
- TestNode SomeNode, id: |1234, related: /Other/Node, others: [/NodeA, /Node/B]
84
- END
85
- assert_link_desc ld, :element => "TestNode", :feature => "id", :index => 0, :backward => false, :value => 1234, :scol => 24, :ecol => 27
86
- end
87
-
88
- def test_in_labled_argument
89
- ld = build_link_desc TestMM, <<-END
90
- TestNode SomeNode, id: 123|4, related: /Other/Node, others: [/NodeA, /Node/B]
91
- END
92
- assert_link_desc ld, :element => "TestNode", :feature => "id", :index => 0, :backward => false, :value => 1234, :scol => 24, :ecol => 27
93
- end
94
-
95
- def test_after_labled_argument
96
- ld = build_link_desc TestMM, <<-END
97
- TestNode SomeNode, id: 1234|, related: /Other/Node, others: [/NodeA, /Node/B]
98
- END
99
- assert_nil ld
100
- end
101
-
102
- def test_in_label
103
- ld = build_link_desc TestMM, <<-END
104
- TestNode SomeNode, id: 1234, re|lated: /Other/Node, others: [/NodeA, /Node/B]
105
- END
106
- assert_nil ld
107
- end
108
-
109
- def test_in_reference
110
- ld = build_link_desc TestMM, <<-END
111
- TestNode SomeNode, id: 1234, related: /O|ther/Node, others: [/NodeA, /Node/B]
112
- END
113
- assert_link_desc ld, :element => "TestNode", :feature => "related", :index => 0, :backward => false, :value => "/Other/Node", :scol => 39, :ecol => 49
114
- end
115
-
116
- def test_before_array
117
- ld = build_link_desc TestMM, <<-END
118
- TestNode SomeNode, id: 1234, related: /Other/Node, others: |[/NodeA, /Node/B]
119
- END
120
- assert_nil ld
121
- end
122
-
123
- def test_ref_in_array
124
- ld = build_link_desc TestMM, <<-END
125
- TestNode SomeNode, id: 1234, related: /Other/Node, others: [|/NodeA, /Node/B]
126
- END
127
- assert_link_desc ld, :element => "TestNode", :feature => "others", :index => 0, :backward => false, :value => "/NodeA", :scol => 61, :ecol => 66
128
- end
129
-
130
- def test_second_ref_in_array
131
- ld = build_link_desc TestMM, <<-END
132
- TestNode SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/|B]
133
- END
134
- assert_link_desc ld, :element => "TestNode", :feature => "others", :index => 1, :backward => false, :value => "/Node/B", :scol => 69, :ecol => 75
135
- end
136
-
137
- def test_backward_ref_name_in_command
138
- ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
139
- |TestNode SomeNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
140
- END
141
- )
142
- assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => false, :value => "TestNode", :scol => 1, :ecol => 8
143
- end
144
-
145
- def test_backward_ref_name_in_name
146
- ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
147
- TestNode Som|eNode, id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
148
- END
149
- )
150
- assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 17
151
- end
152
-
153
- def test_backward_ref_name_with_quotes
154
- ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
155
- TestNode "Som|eNode", id: 1234, related: /Other/Node, others: [/NodeA, /Node/B]
156
- END
157
- )
158
- assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 19
159
- end
160
-
161
- def test_backward_ref_id_in_id
162
- ld = build_link_desc(TestMM, {:backward_ref => "id"}, <<-END
163
- TestNode SomeNode, id: |1234, related: /Other/Node, others: [/NodeA, /Node/B]
164
- END
165
- )
166
- assert_link_desc ld, :element => "TestNode", :feature => "id", :index => 0, :backward => true, :value => 1234, :scol => 24, :ecol => 27
167
- end
168
-
169
- def test_command_only
170
- ld = build_link_desc(TestMM, <<-END
171
- Tes|tNode
172
- END
173
- )
174
- assert_link_desc ld, :element => "TestNode", :feature => nil, :backward => true, :value => "TestNode", :scol => 1, :ecol => 8
175
- end
176
-
177
- def test_command_and_name_only
178
- ld = build_link_desc(TestMM, <<-END
179
- TestNode |SomeNode
180
- END
181
- )
182
- assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => false, :value => "SomeNode", :scol => 10, :ecol => 17
183
- end
184
-
185
- def test_command_and_name_only_backward_ref_name
186
- ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
187
- TestNode |SomeNode
188
- END
189
- )
190
- assert_link_desc ld, :element => "TestNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 17
191
- end
192
-
193
- def test_command_and_name_curly_no_ws
194
- ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
195
- TestNode Some|Node{
196
- END
197
- )
198
- assert_link_desc ld, :element => "TestNode", :element_name => "SomeNode", :feature => "name", :index => 0, :backward => true, :value => "SomeNode", :scol => 10, :ecol => 17
199
- end
200
-
201
- def test_child_within_command
202
- ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
203
- TestNode SomeNode {
204
- Test|Node2 SomeOtherNode
205
- END
206
- )
207
- assert_link_desc ld, :element => "TestNode2", :feature => nil, :backward => false, :value => "TestNode2", :scol => 3, :ecol => 11
208
- end
209
-
210
- def test_child_with_label_after_command
211
- ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
212
- TestNode SomeNode {
213
- children:
214
- TestNode2 |SomeOtherNode
215
- END
216
- )
217
- assert_link_desc ld, :element => "TestNode2", :feature => "name", :index => 0, :backward => true, :value => "SomeOtherNode", :scol => 15, :ecol => 27
218
- end
219
-
220
- def test_child_with_label_within_command
221
- ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
222
- TestNode SomeNode {
223
- children:
224
- Test|Node2 SomeOtherNode
225
- END
226
- )
227
- assert_link_desc ld, :element => "TestNode2", :feature => nil, :backward => false, :value => "TestNode2", :scol => 5, :ecol => 13
228
- end
229
-
230
- def test_child_with_label_within_command_square_brackets
231
- ld = build_link_desc(TestMM, {:backward_ref => "name"}, <<-END
232
- TestNode SomeNode {
233
- children: [
234
- Test|Node2 SomeOtherNode
235
- END
236
- )
237
- assert_link_desc ld, :element => "TestNode2", :feature => nil, :backward => false, :value => "TestNode2", :scol => 5, :ecol => 13
238
- end
239
-
240
- def build_link_desc(mm, text, text2=nil)
241
- if text.is_a?(Hash)
242
- options = text
243
- context_lines = text2.split("\n")
244
- else
245
- options = {}
246
- context_lines = text.split("\n")
247
- end
248
- pos_in_line = context_lines.last.index("|")+1
249
- context_lines.last.sub!("|", "")
250
- lang = RText::Language.new(mm.ecore,
251
- :unlabled_arguments => proc {|c| ["name"]},
252
- :backward_ref_attribute => proc {|c|
253
- if options[:backward_ref]
254
- options[:backward_ref]
255
- else
256
- nil
257
- end
258
- })
259
- RText::LinkDetector.new(lang).detect(context_lines, pos_in_line)
260
- end
261
-
262
- def assert_link_desc(ld, options)
263
- if options[:element]
264
- assert_equal options[:element], ld.element.class.ecore.name
265
- else
266
- assert_nil ld.element
267
- end
268
- if options[:element_name]
269
- assert_equal options[:element_name], ld.element.name
270
- end
271
- if options[:feature]
272
- assert_equal options[:feature], ld.feature.name
273
- else
274
- assert_nil ld.feature
275
- end
276
- if options[:index]
277
- assert_equal options[:index], ld.index
278
- else
279
- assert_nil ld.index
280
- end
281
- assert_equal options[:backward], ld.backward
282
- assert_equal options[:value], ld.value
283
- assert_equal options[:scol], ld.scol
284
- assert_equal options[:ecol], ld.ecol
285
- end
286
-
287
- end
288
-
@@ -1,117 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
-
3
- gem 'minitest'
4
- require 'minitest/autorun'
5
- require 'rtext/message_helper'
6
-
7
- class MessageHelperTest < MiniTest::Test
8
- include RText::MessageHelper
9
-
10
- def test_serialize
11
- str = serialize_message({"key" => 1})
12
- assert_equal '9{"key":1}', str
13
- str = serialize_message({"key" => true})
14
- assert_equal '12{"key":true}', str
15
- str = serialize_message({"key" => "value"})
16
- assert_equal '15{"key":"value"}', str
17
- str = serialize_message({"key" => {"nested" => "value"}})
18
- assert_equal '26{"key":{"nested":"value"}}', str
19
- str = serialize_message({"key" => ["value1", "value2"]})
20
- assert_equal '27{"key":["value1","value2"]}', str
21
-
22
- # a iso-8859-1 'ä'
23
- str = serialize_message({"key" => "umlaut\xe4".force_encoding("binary")})
24
- assert_equal '19{"key":"umlaut%e4"}', str
25
- str = serialize_message({"key" => "umlaut\xe4".force_encoding("iso-8859-1")})
26
- assert_equal '19{"key":"umlaut%e4"}', str
27
- str = serialize_message({"key" => "umlaut\xe4".force_encoding("cp850")})
28
- assert_equal '19{"key":"umlaut%e4"}', str
29
- str = serialize_message({"key" => "umlaut\xe4".force_encoding("utf-8")})
30
- assert_equal '19{"key":"umlaut%e4"}', str
31
-
32
- # a utf-8 'ä'
33
- str = serialize_message({"key" => "umlaut\xc3\xa4".force_encoding("binary")})
34
- assert_equal '22{"key":"umlaut%c3%a4"}', str
35
- str = serialize_message({"key" => "umlaut\xc3\xa4".force_encoding("iso-8859-1")})
36
- assert_equal '22{"key":"umlaut%c3%a4"}', str
37
- str = serialize_message({"key" => "umlaut\xc3\xa4".force_encoding("cp850")})
38
- assert_equal '22{"key":"umlaut%c3%a4"}', str
39
- str = serialize_message({"key" => "umlaut\xc3\xa4".force_encoding("utf-8")})
40
- assert_equal '22{"key":"umlaut%c3%a4"}', str
41
-
42
- # %
43
- str = serialize_message({"key" => "%"})
44
- assert_equal '13{"key":"%25"}', str
45
- end
46
-
47
- def test_extract
48
- # specified length too short
49
- assert_raises JSON::ParserError do
50
- extract_message('8{"key":1}')
51
- end
52
- # specified length too long
53
- assert_raises JSON::ParserError do
54
- extract_message('10{"key":1}x')
55
- end
56
- # message data shorter than length specifie, waits for more data
57
- extract_message('10{"key":1}')
58
-
59
- obj = extract_message('9{"key":1}')
60
- assert_equal({"key" => 1}, obj)
61
- obj = extract_message('12{"key":true}')
62
- assert_equal({"key" => true}, obj)
63
- obj = extract_message('15{"key":"value"}')
64
- assert_equal({"key" => "value"}, obj)
65
- obj = extract_message('26{"key":{"nested":"value"}}')
66
- assert_equal({"key" => {"nested" => "value"}}, obj)
67
- obj = extract_message('27{"key":["value1","value2"]}')
68
- assert_equal({"key" => ["value1", "value2"]}, obj)
69
-
70
- # a iso-8859-1 'ä'
71
- obj = extract_message('19{"key":"umlaut%e4"}'.force_encoding("binary"))
72
- assert_equal "ASCII-8BIT", obj["key"].encoding.name
73
- assert_equal "umlaut\xe4".force_encoding("ascii-8bit"), obj["key"]
74
- obj = extract_message('19{"key":"umlaut%e4"}'.force_encoding("utf-8"))
75
- assert_equal "ASCII-8BIT", obj["key"].encoding.name
76
- assert_equal "umlaut\xe4".force_encoding("ascii-8bit"), obj["key"]
77
-
78
- # a utf-8 'ä'
79
- obj = extract_message('22{"key":"umlaut%c3%a4"}'.force_encoding("binary"))
80
- assert_equal "ASCII-8BIT", obj["key"].encoding.name
81
- assert_equal "umlaut\xc3\xa4".force_encoding("ascii-8bit"), obj["key"]
82
- obj = extract_message('22{"key":"umlaut%c3%a4"}'.force_encoding("utf-8"))
83
- assert_equal "ASCII-8BIT", obj["key"].encoding.name
84
- assert_equal "umlaut\xc3\xa4".force_encoding("ascii-8bit"), obj["key"]
85
-
86
- # %
87
- obj = extract_message('13{"key":"%25"}')
88
- assert_equal "ASCII-8BIT", obj["key"].encoding.name
89
- assert_equal "%", obj["key"]
90
-
91
- # invalid escape sequence
92
- obj = extract_message('11{"key":"%"}')
93
- assert_equal "ASCII-8BIT", obj["key"].encoding.name
94
- assert_equal "%", obj["key"]
95
- obj = extract_message('13{"key":"%xx"}')
96
- assert_equal "ASCII-8BIT", obj["key"].encoding.name
97
- assert_equal "%xx", obj["key"]
98
- obj = extract_message('14{"key":"%%25"}')
99
- assert_equal "ASCII-8BIT", obj["key"].encoding.name
100
- assert_equal "%%", obj["key"]
101
-
102
- # invalid characters (protocol should use 7-bit ascii only)
103
- obj = extract_message(%Q(14{"key":"\xe4345"}).force_encoding("binary"))
104
- assert_equal "ASCII-8BIT", obj["key"].encoding.name
105
- assert_equal "?345", obj["key"]
106
- end
107
-
108
- def test_roundtrip
109
- value = (0..255).collect{|b| b.chr("binary")}.join
110
- str = serialize_message({"key" => value})
111
- obj = extract_message(str)
112
- assert_equal "ASCII-8BIT", obj["key"].encoding.name
113
- assert_equal (0..255).collect{|i| i}, obj["key"].bytes.to_a
114
- end
115
-
116
- end
117
-
data/test/rtext_test.rb DELETED
@@ -1,11 +0,0 @@
1
- $:.unshift File.dirname(__FILE__)
2
-
3
- require 'serializer_test'
4
- require 'instantiator_test'
5
- require 'context_builder_test'
6
- require 'completer_test'
7
- require 'tokenizer_test'
8
- require 'link_detector_test'
9
- require 'integration/test'
10
- require 'message_helper_test'
11
- require 'frontend/context_test'