rtext 0.9.0 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +108 -98
- data/RText_Protocol +1 -1
- data/Rakefile +39 -46
- data/lib/rtext/default_completer.rb +212 -208
- data/lib/rtext/frontend/connector.rb +120 -53
- data/lib/rtext/instantiator.rb +11 -3
- data/lib/rtext/service.rb +264 -260
- data/test/completer_test.rb +606 -607
- data/test/context_builder_test.rb +952 -949
- data/test/frontend/context_test.rb +301 -302
- data/test/instantiator_test.rb +1773 -1733
- data/test/integration/test.rb +974 -968
- data/test/link_detector_test.rb +287 -288
- data/test/message_helper_test.rb +116 -117
- data/test/serializer_test.rb +1023 -1024
- data/test/tokenizer_test.rb +173 -174
- metadata +17 -19
- data/test/integration/backend.out +0 -16
- data/test/integration/frontend.log +0 -40058
data/test/message_helper_test.rb
CHANGED
@@ -1,117 +1,116 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
-
|
3
|
-
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
assert_equal "
|
73
|
-
|
74
|
-
|
75
|
-
assert_equal "
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
assert_equal "
|
81
|
-
|
82
|
-
|
83
|
-
assert_equal "
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
assert_equal "
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
assert_equal "
|
94
|
-
|
95
|
-
|
96
|
-
assert_equal "
|
97
|
-
|
98
|
-
|
99
|
-
assert_equal "
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
assert_equal "
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
assert_equal
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
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
|
+
|