rtext 0.8.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG +102 -84
- data/RText_Protocol +46 -3
- data/Rakefile +46 -46
- data/lib/rtext/context_builder.rb +49 -8
- data/lib/rtext/default_completer.rb +212 -163
- data/lib/rtext/default_service_provider.rb +3 -3
- data/lib/rtext/frontend/context.rb +12 -12
- data/lib/rtext/language.rb +5 -5
- data/lib/rtext/serializer.rb +1 -1
- data/lib/rtext/service.rb +264 -253
- data/lib/rtext/tokenizer.rb +1 -1
- data/test/completer_test.rb +606 -606
- data/test/context_builder_test.rb +948 -948
- data/test/frontend/context_test.rb +301 -205
- data/test/instantiator_test.rb +1732 -1691
- data/test/integration/frontend.log +401 -36030
- data/test/integration/model/test_metamodel3.ect4 +7 -0
- data/test/integration/test.rb +967 -918
- data/test/link_detector_test.rb +287 -287
- data/test/message_helper_test.rb +116 -118
- data/test/serializer_test.rb +1023 -1004
- data/test/tokenizer_test.rb +173 -173
- metadata +18 -19
- data/test/integration/backend.out +0 -13
data/test/message_helper_test.rb
CHANGED
@@ -1,118 +1,116 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
-
|
3
|
-
require '
|
4
|
-
require 'rtext/message_helper'
|
5
|
-
|
6
|
-
class MessageHelperTest < Test
|
7
|
-
include RText::MessageHelper
|
8
|
-
|
9
|
-
def test_serialize
|
10
|
-
str = serialize_message({"key" => 1})
|
11
|
-
assert_equal '9{"key":1}', str
|
12
|
-
str = serialize_message({"key" => true})
|
13
|
-
assert_equal '12{"key":true}', str
|
14
|
-
str = serialize_message({"key" => "value"})
|
15
|
-
assert_equal '15{"key":"value"}', str
|
16
|
-
str = serialize_message({"key" => {"nested" => "value"}})
|
17
|
-
assert_equal '26{"key":{"nested":"value"}}', str
|
18
|
-
str = serialize_message({"key" => ["value1", "value2"]})
|
19
|
-
assert_equal '27{"key":["value1","value2"]}', str
|
20
|
-
|
21
|
-
# a iso-8859-1 '
|
22
|
-
str = serialize_message({"key" => "umlaut\xe4".force_encoding("binary")})
|
23
|
-
assert_equal '19{"key":"umlaut%e4"}', str
|
24
|
-
str = serialize_message({"key" => "umlaut\xe4".force_encoding("iso-8859-1")})
|
25
|
-
assert_equal '19{"key":"umlaut%e4"}', str
|
26
|
-
str = serialize_message({"key" => "umlaut\xe4".force_encoding("cp850")})
|
27
|
-
assert_equal '19{"key":"umlaut%e4"}', str
|
28
|
-
str = serialize_message({"key" => "umlaut\xe4".force_encoding("utf-8")})
|
29
|
-
assert_equal '19{"key":"umlaut%e4"}', str
|
30
|
-
|
31
|
-
# a utf-8 '
|
32
|
-
str = serialize_message({"key" => "umlaut\xc3\xa4".force_encoding("binary")})
|
33
|
-
assert_equal '22{"key":"umlaut%c3%a4"}', str
|
34
|
-
str = serialize_message({"key" => "umlaut\xc3\xa4".force_encoding("iso-8859-1")})
|
35
|
-
assert_equal '22{"key":"umlaut%c3%a4"}', str
|
36
|
-
str = serialize_message({"key" => "umlaut\xc3\xa4".force_encoding("cp850")})
|
37
|
-
assert_equal '22{"key":"umlaut%c3%a4"}', str
|
38
|
-
str = serialize_message({"key" => "umlaut\xc3\xa4".force_encoding("utf-8")})
|
39
|
-
assert_equal '22{"key":"umlaut%c3%a4"}', str
|
40
|
-
|
41
|
-
# %
|
42
|
-
str = serialize_message({"key" => "%"})
|
43
|
-
assert_equal '13{"key":"%25"}', str
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_extract
|
47
|
-
# specified length too short
|
48
|
-
|
49
|
-
extract_message('8{"key":1}')
|
50
|
-
end
|
51
|
-
# specified length too long
|
52
|
-
|
53
|
-
extract_message('10{"key":1}x')
|
54
|
-
end
|
55
|
-
# message data shorter than length specifie, waits for more data
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
obj = extract_message('
|
61
|
-
assert_equal({"key" =>
|
62
|
-
obj = extract_message('
|
63
|
-
assert_equal({"key" =>
|
64
|
-
obj = extract_message('
|
65
|
-
assert_equal({"key" => "value"}, obj)
|
66
|
-
obj = extract_message('
|
67
|
-
assert_equal({"key" =>
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
assert_equal "
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
assert_equal "
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
assert_equal "
|
96
|
-
|
97
|
-
|
98
|
-
assert_equal "
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
118
|
-
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'rtext/message_helper'
|
5
|
+
|
6
|
+
class MessageHelperTest < MiniTest::Test
|
7
|
+
include RText::MessageHelper
|
8
|
+
|
9
|
+
def test_serialize
|
10
|
+
str = serialize_message({"key" => 1})
|
11
|
+
assert_equal '9{"key":1}', str
|
12
|
+
str = serialize_message({"key" => true})
|
13
|
+
assert_equal '12{"key":true}', str
|
14
|
+
str = serialize_message({"key" => "value"})
|
15
|
+
assert_equal '15{"key":"value"}', str
|
16
|
+
str = serialize_message({"key" => {"nested" => "value"}})
|
17
|
+
assert_equal '26{"key":{"nested":"value"}}', str
|
18
|
+
str = serialize_message({"key" => ["value1", "value2"]})
|
19
|
+
assert_equal '27{"key":["value1","value2"]}', str
|
20
|
+
|
21
|
+
# a iso-8859-1 'ä'
|
22
|
+
str = serialize_message({"key" => "umlaut\xe4".force_encoding("binary")})
|
23
|
+
assert_equal '19{"key":"umlaut%e4"}', str
|
24
|
+
str = serialize_message({"key" => "umlaut\xe4".force_encoding("iso-8859-1")})
|
25
|
+
assert_equal '19{"key":"umlaut%e4"}', str
|
26
|
+
str = serialize_message({"key" => "umlaut\xe4".force_encoding("cp850")})
|
27
|
+
assert_equal '19{"key":"umlaut%e4"}', str
|
28
|
+
str = serialize_message({"key" => "umlaut\xe4".force_encoding("utf-8")})
|
29
|
+
assert_equal '19{"key":"umlaut%e4"}', str
|
30
|
+
|
31
|
+
# a utf-8 'ä'
|
32
|
+
str = serialize_message({"key" => "umlaut\xc3\xa4".force_encoding("binary")})
|
33
|
+
assert_equal '22{"key":"umlaut%c3%a4"}', str
|
34
|
+
str = serialize_message({"key" => "umlaut\xc3\xa4".force_encoding("iso-8859-1")})
|
35
|
+
assert_equal '22{"key":"umlaut%c3%a4"}', str
|
36
|
+
str = serialize_message({"key" => "umlaut\xc3\xa4".force_encoding("cp850")})
|
37
|
+
assert_equal '22{"key":"umlaut%c3%a4"}', str
|
38
|
+
str = serialize_message({"key" => "umlaut\xc3\xa4".force_encoding("utf-8")})
|
39
|
+
assert_equal '22{"key":"umlaut%c3%a4"}', str
|
40
|
+
|
41
|
+
# %
|
42
|
+
str = serialize_message({"key" => "%"})
|
43
|
+
assert_equal '13{"key":"%25"}', str
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_extract
|
47
|
+
# specified length too short
|
48
|
+
assert_raises JSON::ParserError do
|
49
|
+
extract_message('8{"key":1}')
|
50
|
+
end
|
51
|
+
# specified length too long
|
52
|
+
assert_raises JSON::ParserError do
|
53
|
+
extract_message('10{"key":1}x')
|
54
|
+
end
|
55
|
+
# message data shorter than length specifie, waits for more data
|
56
|
+
extract_message('10{"key":1}')
|
57
|
+
|
58
|
+
obj = extract_message('9{"key":1}')
|
59
|
+
assert_equal({"key" => 1}, obj)
|
60
|
+
obj = extract_message('12{"key":true}')
|
61
|
+
assert_equal({"key" => true}, obj)
|
62
|
+
obj = extract_message('15{"key":"value"}')
|
63
|
+
assert_equal({"key" => "value"}, obj)
|
64
|
+
obj = extract_message('26{"key":{"nested":"value"}}')
|
65
|
+
assert_equal({"key" => {"nested" => "value"}}, obj)
|
66
|
+
obj = extract_message('27{"key":["value1","value2"]}')
|
67
|
+
assert_equal({"key" => ["value1", "value2"]}, obj)
|
68
|
+
|
69
|
+
# a iso-8859-1 'ä'
|
70
|
+
obj = extract_message('19{"key":"umlaut%e4"}'.force_encoding("binary"))
|
71
|
+
assert_equal "ASCII-8BIT", obj["key"].encoding.name
|
72
|
+
assert_equal "umlaut\xe4".force_encoding("ascii-8bit"), obj["key"]
|
73
|
+
obj = extract_message('19{"key":"umlaut%e4"}'.force_encoding("utf-8"))
|
74
|
+
assert_equal "ASCII-8BIT", obj["key"].encoding.name
|
75
|
+
assert_equal "umlaut\xe4".force_encoding("ascii-8bit"), obj["key"]
|
76
|
+
|
77
|
+
# a utf-8 'ä'
|
78
|
+
obj = extract_message('22{"key":"umlaut%c3%a4"}'.force_encoding("binary"))
|
79
|
+
assert_equal "ASCII-8BIT", obj["key"].encoding.name
|
80
|
+
assert_equal "umlaut\xc3\xa4".force_encoding("ascii-8bit"), obj["key"]
|
81
|
+
obj = extract_message('22{"key":"umlaut%c3%a4"}'.force_encoding("utf-8"))
|
82
|
+
assert_equal "ASCII-8BIT", obj["key"].encoding.name
|
83
|
+
assert_equal "umlaut\xc3\xa4".force_encoding("ascii-8bit"), obj["key"]
|
84
|
+
|
85
|
+
# %
|
86
|
+
obj = extract_message('13{"key":"%25"}')
|
87
|
+
assert_equal "ASCII-8BIT", obj["key"].encoding.name
|
88
|
+
assert_equal "%", obj["key"]
|
89
|
+
|
90
|
+
# invalid escape sequence
|
91
|
+
obj = extract_message('11{"key":"%"}')
|
92
|
+
assert_equal "ASCII-8BIT", obj["key"].encoding.name
|
93
|
+
assert_equal "%", obj["key"]
|
94
|
+
obj = extract_message('13{"key":"%xx"}')
|
95
|
+
assert_equal "ASCII-8BIT", obj["key"].encoding.name
|
96
|
+
assert_equal "%xx", obj["key"]
|
97
|
+
obj = extract_message('14{"key":"%%25"}')
|
98
|
+
assert_equal "ASCII-8BIT", obj["key"].encoding.name
|
99
|
+
assert_equal "%%", obj["key"]
|
100
|
+
|
101
|
+
# invalid characters (protocol should use 7-bit ascii only)
|
102
|
+
obj = extract_message(%Q(14{"key":"\xe4345"}).force_encoding("binary"))
|
103
|
+
assert_equal "ASCII-8BIT", obj["key"].encoding.name
|
104
|
+
assert_equal "?345", obj["key"]
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_roundtrip
|
108
|
+
value = (0..255).collect{|b| b.chr("binary")}.join
|
109
|
+
str = serialize_message({"key" => value})
|
110
|
+
obj = extract_message(str)
|
111
|
+
assert_equal "ASCII-8BIT", obj["key"].encoding.name
|
112
|
+
assert_equal (0..255).collect{|i| i}, obj["key"].bytes.to_a
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|