ircparser 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/ircparser.rb +24 -0
- data/lib/ircparser/error.rb +31 -0
- data/lib/ircparser/message.rb +184 -0
- data/lib/ircparser/source.rb +73 -0
- data/test/test_message.rb +133 -0
- data/test/test_source.rb +76 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d27e58044aaef908ff610d5883b52541731a17f5
|
4
|
+
data.tar.gz: b98d3cd5358f72580da7c937f72d8106a1015413
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 347dbaf54fe1510fcfa5201be525ee7898745b406de46fb76f13a55626e6472249c2346cfc99588dcba3b398359b3a2338976c1610b03f2c7d598f6f6bb374a6
|
7
|
+
data.tar.gz: 1337ef212d2efe665dec0e5df6019941ddb70ec1173c13a5931ca4283aface049deaa60bb5bcaa8e45ca5653a2f2588c7829959a760fc096000c65c4802a43cc
|
data/lib/ircparser.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# IRCParser - Internet Relay Chat Message Parser
|
2
|
+
#
|
3
|
+
# Copyright (C) 2015 Peter "SaberUK" Powell <petpow@saberuk.com>
|
4
|
+
#
|
5
|
+
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
|
+
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
7
|
+
# in all copies.
|
8
|
+
#
|
9
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
10
|
+
# SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
11
|
+
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
13
|
+
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
14
|
+
# OF THIS SOFTWARE.
|
15
|
+
|
16
|
+
module IRCParser
|
17
|
+
|
18
|
+
# Public: The version of IRCParser in use.
|
19
|
+
VERSION = '0.1.0'
|
20
|
+
end
|
21
|
+
|
22
|
+
require_relative 'ircparser/error'
|
23
|
+
require_relative 'ircparser/message'
|
24
|
+
require_relative 'ircparser/source'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# IRCParser - Internet Relay Chat Message Parser
|
2
|
+
#
|
3
|
+
# Copyright (C) 2015 Peter "SaberUK" Powell <petpow@saberuk.com>
|
4
|
+
#
|
5
|
+
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
|
+
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
7
|
+
# in all copies.
|
8
|
+
#
|
9
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
10
|
+
# SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
11
|
+
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
13
|
+
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
14
|
+
# OF THIS SOFTWARE.
|
15
|
+
|
16
|
+
module IRCParser
|
17
|
+
|
18
|
+
# Public: The exception which is thrown when parsing fails.
|
19
|
+
class Error < StandardError
|
20
|
+
|
21
|
+
# Public: The value which failed to parse correctly.
|
22
|
+
attr_reader :value
|
23
|
+
|
24
|
+
# Public: Initialise a new parse error with the specified invalid value.
|
25
|
+
#
|
26
|
+
# value - The value which failed to parse correctly.
|
27
|
+
def initialize value
|
28
|
+
@value = value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
# IRCParser - Internet Relay Chat Message Parser
|
2
|
+
#
|
3
|
+
# Copyright (C) 2015 Peter "SaberUK" Powell <petpow@saberuk.com>
|
4
|
+
#
|
5
|
+
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
|
+
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
7
|
+
# in all copies.
|
8
|
+
#
|
9
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
10
|
+
# SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
11
|
+
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
13
|
+
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
14
|
+
# OF THIS SOFTWARE.
|
15
|
+
|
16
|
+
module IRCParser
|
17
|
+
|
18
|
+
# Public: Represents an IRC message.
|
19
|
+
class Message
|
20
|
+
|
21
|
+
# Internal: A regular expression which matches a tag.
|
22
|
+
MATCH_TAG = /^(\S+?)(?:=(\S+))?$/
|
23
|
+
|
24
|
+
# Internal: The characters which need to be escaped in tag values.
|
25
|
+
TAG_ESCAPES = {
|
26
|
+
'\\' => '\\\\',
|
27
|
+
';' => '\:',
|
28
|
+
"\s" => '\s',
|
29
|
+
"\r" => '\r',
|
30
|
+
"\n" => '\n'
|
31
|
+
}
|
32
|
+
|
33
|
+
# Public: Command name (e.g. PRIVMSG).
|
34
|
+
attr_reader :command
|
35
|
+
|
36
|
+
# Public: An array of command parameters.
|
37
|
+
attr_reader :parameters
|
38
|
+
|
39
|
+
# Public: The source of this command or nil if unsourced.
|
40
|
+
attr_reader :source
|
41
|
+
|
42
|
+
# Public: A hash of IRCv3.2 message tags.
|
43
|
+
attr_reader :tags
|
44
|
+
|
45
|
+
# Public: Initialize a new message.
|
46
|
+
def initialize command: String.new, parameters: Array.new, source: nil, tags: Hash.new
|
47
|
+
@command = command
|
48
|
+
@parameters = parameters
|
49
|
+
@source = source
|
50
|
+
@tags = tags
|
51
|
+
end
|
52
|
+
|
53
|
+
# Public: Parses an IRC message from network form.
|
54
|
+
#
|
55
|
+
# line - The line to attempt to parse/
|
56
|
+
def self.parse line
|
57
|
+
|
58
|
+
# Ruby really needs some kind of basic type checking.
|
59
|
+
raise IRCParser::Error.new(line), "line is not a string" unless line.is_a? String
|
60
|
+
|
61
|
+
# Split the message up into an array of tokens.
|
62
|
+
tokens = line.split ' '
|
63
|
+
current_index = 0
|
64
|
+
components = Hash.new
|
65
|
+
|
66
|
+
# Have we encountered IRCv3.2 message tags?
|
67
|
+
components[:tags] = Hash.new
|
68
|
+
if current_index < tokens.size && tokens[current_index][0] == '@'
|
69
|
+
components[:tags] = __parse_tags tokens[current_index]
|
70
|
+
current_index += 1
|
71
|
+
end
|
72
|
+
|
73
|
+
# Have we encountered the source of this message?
|
74
|
+
if current_index < tokens.size && tokens[current_index][0] == ':'
|
75
|
+
components[:source] = IRCParser::Source.new tokens[current_index][1..-1]
|
76
|
+
current_index += 1
|
77
|
+
end
|
78
|
+
|
79
|
+
# The command parameter is mandatory.
|
80
|
+
if current_index < tokens.size
|
81
|
+
components[:command] = tokens[current_index]
|
82
|
+
current_index += 1
|
83
|
+
else
|
84
|
+
raise IRCParser::Error.new(line), 'message is missing the command name'
|
85
|
+
end
|
86
|
+
|
87
|
+
# Try to parse all of the remaining parameters.
|
88
|
+
components[:parameters] = __parse_parameters tokens[current_index..-1]
|
89
|
+
return IRCParser::Message.new components
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
# Public: Serializes the message to a string.
|
94
|
+
def to_s
|
95
|
+
buffer = String.new
|
96
|
+
|
97
|
+
# Serialize the tags.
|
98
|
+
unless tags.empty?
|
99
|
+
buffer += '@'
|
100
|
+
buffer += __serialize_tags
|
101
|
+
buffer += ' '
|
102
|
+
end
|
103
|
+
|
104
|
+
# Serialize the source.
|
105
|
+
unless source.nil?
|
106
|
+
buffer += ':'
|
107
|
+
buffer += source.to_s
|
108
|
+
buffer += ' '
|
109
|
+
end
|
110
|
+
|
111
|
+
# Serialize the command.
|
112
|
+
buffer += command
|
113
|
+
|
114
|
+
# Serialize the parameters
|
115
|
+
buffer += __serialize_parameters
|
116
|
+
|
117
|
+
# We're done!
|
118
|
+
return buffer
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
# Internal: Parse parameters from network form to an Array.
|
124
|
+
#
|
125
|
+
# token - A list of tags in network form.
|
126
|
+
def self.__parse_parameters tokens
|
127
|
+
parameters = Array.new
|
128
|
+
tokens.each_with_index do |token, index|
|
129
|
+
if token[0] == ':'
|
130
|
+
last_token = tokens[index..-1].join ' '
|
131
|
+
parameters << last_token[1..-1]
|
132
|
+
break
|
133
|
+
end
|
134
|
+
parameters << token
|
135
|
+
end
|
136
|
+
return parameters
|
137
|
+
end
|
138
|
+
|
139
|
+
# Internal: Parse tags from network form to a Hash.
|
140
|
+
#
|
141
|
+
# token - A list of tags in network form.
|
142
|
+
def self.__parse_tags token
|
143
|
+
tags = Hash.new
|
144
|
+
token[1..-1].split(';').each do |tag|
|
145
|
+
if tag =~ MATCH_TAG
|
146
|
+
name, value = $~[1..2]
|
147
|
+
TAG_ESCAPES.each do |unescaped, escaped|
|
148
|
+
value.gsub! escaped, Regexp.escape(unescaped)
|
149
|
+
end unless value.nil?
|
150
|
+
tags[name] = value
|
151
|
+
else
|
152
|
+
raise IRCParser::Error.new(tag), "tag is malformed"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
return tags
|
156
|
+
end
|
157
|
+
|
158
|
+
# Internal: Serializes parameters from an Array to network form.
|
159
|
+
def __serialize_parameters
|
160
|
+
buffer = String.new
|
161
|
+
@parameters.each_with_index do |parameter, index|
|
162
|
+
buffer += ' '
|
163
|
+
if parameter.include? ' '
|
164
|
+
buffer += ':'
|
165
|
+
buffer += parameters[index..-1].join ' '
|
166
|
+
break
|
167
|
+
end
|
168
|
+
buffer += parameter
|
169
|
+
end
|
170
|
+
return buffer
|
171
|
+
end
|
172
|
+
|
173
|
+
# Internal: Serializes tags from a Hash to network form.
|
174
|
+
def __serialize_tags
|
175
|
+
buffer = @tags.dup.map do |key, value|
|
176
|
+
TAG_ESCAPES.each do |unescaped, escaped|
|
177
|
+
value.gsub! unescaped, Regexp.escape(escaped)
|
178
|
+
end unless value.nil?
|
179
|
+
value.nil? ? key : key + '=' + value
|
180
|
+
end.join ';'
|
181
|
+
return buffer
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# IRCParser - Internet Relay Chat Message Parser
|
2
|
+
#
|
3
|
+
# Copyright (C) 2015 Peter "SaberUK" Powell <petpow@saberuk.com>
|
4
|
+
#
|
5
|
+
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
|
+
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
7
|
+
# in all copies.
|
8
|
+
#
|
9
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
10
|
+
# SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
11
|
+
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
13
|
+
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
14
|
+
# OF THIS SOFTWARE.
|
15
|
+
|
16
|
+
module IRCParser
|
17
|
+
|
18
|
+
# Public: Represents the source of an IRC message.
|
19
|
+
class Source
|
20
|
+
|
21
|
+
# Internal: A regular expression which matches a n!u@h mask.
|
22
|
+
MATCH_USER = /^(\S+)!(\S+)@(\S+)$/
|
23
|
+
|
24
|
+
# Internal: A regular expression which matches a server name.
|
25
|
+
MATCH_SERVER = /^(\S+\.\S+)$/
|
26
|
+
|
27
|
+
# Public: The hostname of this source.
|
28
|
+
attr_reader :host
|
29
|
+
|
30
|
+
# Public: The nickname of this user or nil if the source is a server.
|
31
|
+
attr_reader :nick
|
32
|
+
|
33
|
+
# Public: The username of this user or nil if the source is a server.
|
34
|
+
attr_reader :user
|
35
|
+
|
36
|
+
# Public: Initialise a new message source from a serialised source.
|
37
|
+
#
|
38
|
+
# source - Either a n!u@h mask or a server name.
|
39
|
+
def initialize source
|
40
|
+
if MATCH_USER =~ source
|
41
|
+
@type = :user
|
42
|
+
@nick = $~[1]
|
43
|
+
@user = $~[2]
|
44
|
+
@host = $~[3]
|
45
|
+
elsif MATCH_SERVER =~ source
|
46
|
+
@type = :server
|
47
|
+
@host = $~[1]
|
48
|
+
else
|
49
|
+
raise IRCParser::Error.new(source), 'source is not a user mask or server name'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Public: Whether this source represents a user.
|
54
|
+
def is_user?
|
55
|
+
return @type == :user
|
56
|
+
end
|
57
|
+
|
58
|
+
# Public: Whether this source represents a server.
|
59
|
+
def is_server?
|
60
|
+
return @type == :server
|
61
|
+
end
|
62
|
+
|
63
|
+
# Public: The name by which this source can be identified.
|
64
|
+
def name
|
65
|
+
return is_user? ? @nick : @host
|
66
|
+
end
|
67
|
+
|
68
|
+
# Public: serialises this source to the serialised form.
|
69
|
+
def to_s
|
70
|
+
return is_user? ? "#{@nick}!#{@user}@#{@host}" : @host
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# IRCParser - Internet Relay Chat Message Parser
|
2
|
+
#
|
3
|
+
# Copyright (C) 2015 Peter "SaberUK" Powell <petpow@saberuk.com>
|
4
|
+
#
|
5
|
+
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
|
+
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
7
|
+
# in all copies.
|
8
|
+
#
|
9
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
10
|
+
# SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
11
|
+
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
13
|
+
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
14
|
+
# OF THIS SOFTWARE.
|
15
|
+
|
16
|
+
$LOAD_PATH.unshift "#{Dir.pwd}/lib"
|
17
|
+
|
18
|
+
require 'ircparser'
|
19
|
+
require 'minitest/autorun'
|
20
|
+
|
21
|
+
describe IRCParser::Message do
|
22
|
+
describe 'when checking a valid message with tags and a source' do
|
23
|
+
before do
|
24
|
+
@text = '@tag1=value1;tag2;vendor1/tag3=value2;vendor2/tag4 :irc.example.com COMMAND param1 param2 :param3 param3'
|
25
|
+
@message = IRCParser::Message.parse @text
|
26
|
+
end
|
27
|
+
it 'should consist of the correct components' do
|
28
|
+
tags = { 'tag1' => 'value1', 'tag2' => nil, 'vendor1/tag3' => 'value2', 'vendor2/tag4' => nil }
|
29
|
+
parameters = [ 'param1', 'param2', 'param3 param3' ]
|
30
|
+
|
31
|
+
@message.tags.must_equal tags
|
32
|
+
@message.source.wont_be_nil
|
33
|
+
@message.source.host.must_equal 'irc.example.com'
|
34
|
+
@message.command.must_equal 'COMMAND'
|
35
|
+
@message.parameters.must_equal parameters
|
36
|
+
end
|
37
|
+
it 'should serialise back to the same text' do
|
38
|
+
@message.to_s.must_equal @text
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'when checking a valid message with a source but no tags' do
|
43
|
+
before do
|
44
|
+
@text = ':irc.example.com COMMAND param1 param2 :param3 param3'
|
45
|
+
@message = IRCParser::Message.parse @text
|
46
|
+
end
|
47
|
+
it 'should consist of the correct components' do
|
48
|
+
parameters = [ 'param1', 'param2', 'param3 param3' ]
|
49
|
+
|
50
|
+
@message.tags.must_be_empty
|
51
|
+
@message.source.wont_be_nil
|
52
|
+
@message.source.host.must_equal 'irc.example.com'
|
53
|
+
@message.command.must_equal 'COMMAND'
|
54
|
+
@message.parameters.must_equal parameters
|
55
|
+
end
|
56
|
+
it 'should serialise back to the same text' do
|
57
|
+
@message.to_s.must_equal @text
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'when checking a valid message with tags but no source' do
|
62
|
+
before do
|
63
|
+
@text = '@tag1=value1;tag2;vendor1/tag3=value2;vendor2/tag4 COMMAND param1 param2 :param3 param3'
|
64
|
+
@message = IRCParser::Message.parse @text
|
65
|
+
end
|
66
|
+
it 'should consist of the correct components' do
|
67
|
+
tags = { 'tag1' => 'value1', 'tag2' => nil, 'vendor1/tag3' => 'value2', 'vendor2/tag4' => nil }
|
68
|
+
parameters = [ 'param1', 'param2', 'param3 param3' ]
|
69
|
+
|
70
|
+
@message.tags.must_equal tags
|
71
|
+
@message.source.must_be_nil
|
72
|
+
@message.command.must_equal 'COMMAND'
|
73
|
+
@message.parameters.must_equal parameters
|
74
|
+
end
|
75
|
+
it 'should serialise back to the same text' do
|
76
|
+
@message.to_s.must_equal @text
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'when checking a valid message with tags but no source' do
|
81
|
+
before do
|
82
|
+
@text = '@tag1=value1;tag2;vendor1/tag3=value2;vendor2/tag4 COMMAND param1 param2 :param3 param3'
|
83
|
+
@message = IRCParser::Message.parse @text
|
84
|
+
end
|
85
|
+
it 'should consist of the correct components' do
|
86
|
+
tags = { 'tag1' => 'value1', 'tag2' => nil, 'vendor1/tag3' => 'value2', 'vendor2/tag4' => nil }
|
87
|
+
parameters = [ 'param1', 'param2', 'param3 param3' ]
|
88
|
+
|
89
|
+
@message.tags.must_equal tags
|
90
|
+
@message.source.must_be_nil
|
91
|
+
@message.command.must_equal 'COMMAND'
|
92
|
+
@message.parameters.must_equal parameters
|
93
|
+
end
|
94
|
+
it 'should serialise back to the same text' do
|
95
|
+
@message.to_s.must_equal @text
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
describe 'when checking a valid message with no tags, source or parameters' do
|
101
|
+
before do
|
102
|
+
@text = 'COMMAND'
|
103
|
+
@message = IRCParser::Message.parse @text
|
104
|
+
end
|
105
|
+
it 'should consist of the correct components' do
|
106
|
+
@message.tags.must_be_empty
|
107
|
+
@message.source.must_be_nil
|
108
|
+
@message.command.must_equal 'COMMAND'
|
109
|
+
@message.parameters.must_be_empty
|
110
|
+
end
|
111
|
+
it 'should serialise back to the same text' do
|
112
|
+
@message.to_s.must_equal @text
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe 'when checking we can handle tag values properly' do
|
117
|
+
before do
|
118
|
+
@escaped = '\\\\\:\s\r\n'
|
119
|
+
@unescaped = "\\;\s\r\n"
|
120
|
+
@text = "@foo=#{@escaped} COMMAND"
|
121
|
+
end
|
122
|
+
it 'should escape correctly' do
|
123
|
+
tags = { 'foo' => @unescaped }
|
124
|
+
message = IRCParser::Message.new command: 'COMMAND', tags: tags
|
125
|
+
message.to_s.must_equal @text
|
126
|
+
end
|
127
|
+
it 'should unescape correctly' do
|
128
|
+
message = IRCParser::Message.parse @text
|
129
|
+
#message.tags['foo'].must_equal @unescaped
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
data/test/test_source.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# IRCParser - Internet Relay Chat Message Parser
|
2
|
+
#
|
3
|
+
# Copyright (C) 2015 Peter "SaberUK" Powell <petpow@saberuk.com>
|
4
|
+
#
|
5
|
+
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without
|
6
|
+
# fee is hereby granted, provided that the above copyright notice and this permission notice appear
|
7
|
+
# in all copies.
|
8
|
+
#
|
9
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
10
|
+
# SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
11
|
+
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
13
|
+
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
14
|
+
# OF THIS SOFTWARE.
|
15
|
+
|
16
|
+
$LOAD_PATH.unshift "#{Dir.pwd}/lib"
|
17
|
+
|
18
|
+
require 'ircparser'
|
19
|
+
require 'minitest/autorun'
|
20
|
+
|
21
|
+
describe IRCParser::Source do
|
22
|
+
describe 'when checking a valid server source' do
|
23
|
+
before do
|
24
|
+
@text = 'irc.example.com'
|
25
|
+
@source = IRCParser::Source.new @text
|
26
|
+
end
|
27
|
+
it 'should consist of the correct components' do
|
28
|
+
@source.nick.must_be_nil
|
29
|
+
@source.user.must_be_nil
|
30
|
+
@source.host.must_equal 'irc.example.com'
|
31
|
+
end
|
32
|
+
it 'should be a server not a user' do
|
33
|
+
@source.is_server?.must_equal true
|
34
|
+
@source.is_user?.must_equal false
|
35
|
+
end
|
36
|
+
it 'should serialise back to the same text' do
|
37
|
+
@source.to_s.must_equal @text
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'when checking a valid user source' do
|
42
|
+
before do
|
43
|
+
@text = 'nick!user@host'
|
44
|
+
@source = IRCParser::Source.new @text
|
45
|
+
end
|
46
|
+
it 'should consist of the correct components' do
|
47
|
+
@source.nick.must_equal 'nick'
|
48
|
+
@source.user.must_equal 'user'
|
49
|
+
@source.host.must_equal 'host'
|
50
|
+
end
|
51
|
+
it 'should be a user not a server' do
|
52
|
+
@source.is_server?.must_equal false
|
53
|
+
@source.is_user?.must_equal true
|
54
|
+
end
|
55
|
+
it 'should serialise back to the same text' do
|
56
|
+
@source.to_s.must_equal @text
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'when checking an invalid server source' do
|
61
|
+
it 'should throw an IRCParser::Error' do
|
62
|
+
proc { IRCParser::Source.new 'test' }.must_raise IRCParser::Error
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'when checking an invalid user source' do
|
67
|
+
it 'should throw an IRCParser::Error when components are missing' do
|
68
|
+
proc { IRCParser::Source.new 'nick!@' }.must_raise IRCParser::Error
|
69
|
+
proc { IRCParser::Source.new '!user@' }.must_raise IRCParser::Error
|
70
|
+
proc { IRCParser::Source.new '!@host' }.must_raise IRCParser::Error
|
71
|
+
proc { IRCParser::Source.new 'nick!user@' }.must_raise IRCParser::Error
|
72
|
+
proc { IRCParser::Source.new 'nick!@host' }.must_raise IRCParser::Error
|
73
|
+
proc { IRCParser::Source.new '!user@host' }.must_raise IRCParser::Error
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ircparser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter "SaberUK" Powell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.6.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.6.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tomdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.5
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.5
|
41
|
+
description: A standards compliant parser for the IRCv3.2 message format.
|
42
|
+
email: petpow@saberuk.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/ircparser.rb
|
48
|
+
- lib/ircparser/error.rb
|
49
|
+
- lib/ircparser/message.rb
|
50
|
+
- lib/ircparser/source.rb
|
51
|
+
- test/test_message.rb
|
52
|
+
- test/test_source.rb
|
53
|
+
homepage: https://github.com/SaberUK/ircparser
|
54
|
+
licenses:
|
55
|
+
- ISC
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.4.6
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: An IRCv3.2 message parser.
|
77
|
+
test_files: []
|