pidgin2adium 3.3.0 → 4.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -3
  3. data/.rspec +1 -0
  4. data/.simplecov +5 -0
  5. data/.travis.yml +12 -0
  6. data/Gemfile +6 -1
  7. data/LICENSE +17 -17
  8. data/NEWS.md +89 -0
  9. data/README.md +60 -0
  10. data/Rakefile +5 -23
  11. data/bin/pidgin2adium +19 -90
  12. data/lib/pidgin2adium.rb +4 -136
  13. data/lib/pidgin2adium/adium_chat_file_creator.rb +64 -0
  14. data/lib/pidgin2adium/file_finder.rb +23 -0
  15. data/lib/pidgin2adium/runner.rb +23 -0
  16. data/lib/pidgin2adium/version.rb +1 -1
  17. data/pidgin2adium.gemspec +25 -21
  18. data/spec/features/parse_pidgin_log_file_spec.rb +50 -0
  19. data/spec/fixtures/input/input.html +3 -0
  20. data/spec/fixtures/output.xml +5 -0
  21. data/spec/pidgin2adium/adium_chat_file_creator_spec.rb +89 -0
  22. data/spec/pidgin2adium/file_finder_spec.rb +63 -0
  23. data/spec/spec_helper.rb +17 -59
  24. metadata +96 -89
  25. data/.autotest +0 -28
  26. data/ChangeLog +0 -79
  27. data/Manifest.txt +0 -18
  28. data/README.rdoc +0 -122
  29. data/config/website.yml +0 -2
  30. data/ext/balance_tags_c/balance_tags_c.c +0 -198
  31. data/ext/balance_tags_c/extconf.rb +0 -4
  32. data/lib/pidgin2adium/log_converter.rb +0 -71
  33. data/lib/pidgin2adium/log_file.rb +0 -100
  34. data/lib/pidgin2adium/log_parser.rb +0 -2
  35. data/lib/pidgin2adium/message.rb +0 -2
  36. data/lib/pidgin2adium/messages/all.rb +0 -5
  37. data/lib/pidgin2adium/messages/auto_reply_message.rb +0 -11
  38. data/lib/pidgin2adium/messages/event.rb +0 -17
  39. data/lib/pidgin2adium/messages/message.rb +0 -39
  40. data/lib/pidgin2adium/messages/status_message.rb +0 -17
  41. data/lib/pidgin2adium/messages/xml_message.rb +0 -40
  42. data/lib/pidgin2adium/parsers/all.rb +0 -3
  43. data/lib/pidgin2adium/parsers/basic_parser.rb +0 -456
  44. data/lib/pidgin2adium/parsers/html_log_parser.rb +0 -125
  45. data/lib/pidgin2adium/parsers/text_log_parser.rb +0 -39
  46. data/spec/balance_tags_c_extn_spec.rb +0 -47
  47. data/spec/basic_parser_spec.rb +0 -219
  48. data/spec/html_log_parser_spec.rb +0 -150
  49. data/spec/log_converter_spec.rb +0 -48
  50. data/spec/log_file_spec.rb +0 -176
  51. data/spec/logfiles/2006-12-21.223606.txt +0 -3
  52. data/spec/logfiles/2008-01-15.071445-0500PST.htm +0 -5
  53. data/spec/logfiles/2008-01-15.071445-0500PST.html +0 -5
  54. data/spec/pidgin2adium_spec.rb +0 -252
  55. data/spec/spec.opts +0 -1
  56. data/spec/test-output/README.md +0 -1
  57. data/spec/test-output/html_log_output.xml +0 -6
  58. data/spec/test-output/text_log_output.xml +0 -4
  59. data/spec/text_log_parser_spec.rb +0 -42
  60. data/tasks/extconf.rake +0 -8
  61. data/tasks/extconf/balance_tags_c.rake +0 -47
@@ -1,125 +0,0 @@
1
- # HtmlLogParser class, a subclass of BasicParser.
2
- # Used for parse()ing HTML logs.
3
-
4
- require 'balance_tags_c'
5
-
6
- module Pidgin2Adium
7
- class HtmlLogParser < BasicParser
8
- def initialize(src_path, user_aliases, force_conversion = false)
9
- super(src_path, user_aliases, force_conversion)
10
- @timestamp_rx = '\(((?:\d{4}-\d{2}-\d{2} )?\d{1,2}:\d{1,2}:\d{1,2}(?: [AP]M)?)\)'
11
-
12
- # @line_regex matches a line in an HTML log file other than the
13
- # first time matches on either "2008-11-17 14:12" or "14:12"
14
- # @line_regex match obj:
15
- # 0: timestamp, extended or not
16
- # 1: screen name or alias, if alias set
17
- # 2: "&lt;AUTO-REPLY&gt;" or nil
18
- # 3: message body
19
- # The ":" is optional to allow for strings like "(17:12:21) <b>***Gabe B-W</b> is confused<br/>"
20
- @line_regex = /#{@timestamp_rx} ?<b>(.+?) ?(&lt;AUTO-REPLY&gt;)?:?<\/b> ?(.+)<br ?\/>/o
21
- # @line_regex_status matches a status line
22
- # @line_regex_status match obj:
23
- # 0: timestamp
24
- # 1: status message
25
- @line_regex_status = /#{@timestamp_rx} ?<b> (.+)<\/b><br ?\/>/o
26
- end
27
-
28
- # Returns a cleaned string.
29
- # Removes the following tags from _text_:
30
- # * html
31
- # * body
32
- # * font
33
- # * a with no innertext, e.g. <a href="blah"></a>
34
- # And removes the following style declarations:
35
- # * color: #000000 (just turns text black)
36
- # * font-family
37
- # * font-size
38
- # * background
39
- # * em (really it's changed to <span style="font-style: italic;">)
40
- # Since each <span> has only one style declaration, spans with these
41
- # declarations are removed (but the text inside them is preserved).
42
- def cleanup(text)
43
- # Sometimes this is in there. I don't know why.
44
- text.gsub!(%r{&lt;/FONT HSPACE='\d'>}, '')
45
- # We can remove <font> safely since Pidgin and Adium both show bold
46
- # using <span style="font-weight: bold;"> except Pidgin uses single
47
- # quotes while Adium uses double quotes.
48
- text.gsub!(/<\/?(?:html|body|font)(?: .+?)?>/, '') # very important!
49
-
50
- text.tr!("\r", '')
51
- # Remove empty lines
52
- text.gsub!("\n\n", "\n")
53
-
54
- # Remove newlines that end the file, since they screw up the
55
- # newline -> <br/> conversion
56
- text.gsub!(/\n\Z/, '')
57
-
58
- # Replace newlines with "<br/>" unless they end a chat line.
59
- # This must go after we remove <font> tags.
60
- text.gsub!(/\n(?!#{@timestamp_rx})/, '<br/>')
61
-
62
- # These empty links are sometimes appended to every line in a chat,
63
- # for some weird reason. Remove them.
64
- text.gsub!(%r{<a href=['"].+?['"]>\s*?</a>}, '')
65
-
66
- # Replace single quotes inside tags with double quotes so we can
67
- # easily change single quotes to entities.
68
- # For spans, removes a space after the final declaration if it exists.
69
- text.gsub!(/<span style='([^']+?;) ?'>/, '<span style="\1">')
70
- text.gsub!(/([a-z]+=)'(.+?)'/, '\1"\2"')
71
- =begin
72
- text.gsub!(/<a href='(.+?)'>/, '<a href="\1">')
73
- text.gsub!(/<img src='([^']+?)'/, '<img src="\1"')
74
- text.gsub!(/ alt='([^']+?)'/, ' alt="\1"')
75
- =end
76
- text.gsub!("'", '&apos;')
77
-
78
- # This actually does match stuff, but doesn't group it correctly. :(
79
- # text.gsub!(%r{<span style="((?:.+?;)+)">(.*?)</span>}) do |s|
80
- text.gsub!(%r{<span style="(.+?)">(.*?)</span>}) do |s|
81
- # Remove empty spans.
82
- next if $2 == ''
83
-
84
- # style = style declaration
85
- # innertext = text inside <span>
86
- style, innertext = $1, $2
87
- # TODO: replace double quotes with "&quot;", but only outside tags; may still be tags inside spans
88
- # innertext.gsub!("")
89
-
90
- styleparts = style.split(/; ?/)
91
- styleparts.map! do |p|
92
- if p[0,5] == 'color'
93
- if p.include?('color: #000000')
94
- next
95
- elsif p =~ /(color: #[0-9a-fA-F]{6})(>.*)?/
96
- # Regarding the bit with the ">", sometimes this happens:
97
- # <span style="color: #000000>today;">today was busy</span>
98
- # Then p = "color: #000000>today"
99
- # Or it can end in ">;", with no text before the semicolon.
100
- # So keep the color but remove the ">" and anything following it.
101
- next($1)
102
- end
103
- else
104
- # don't remove font-weight
105
- case p
106
- when /^font-family/ then next
107
- when /^font-size/ then next
108
- when /^background/ then next
109
- end
110
- end
111
- end.compact!
112
- unless styleparts.empty?
113
- style = styleparts.join('; ')
114
- innertext = "<span style=\"#{style};\">#{innertext}</span>"
115
- end
116
- innertext
117
- end
118
- # Pidgin uses <em>, Adium uses <span>
119
- if text.gsub!('<em>', '<span style="font-style: italic;">')
120
- text.gsub!('</em>', '</span>')
121
- end
122
- return text
123
- end
124
- end # END HtmlLogParser class
125
- end
@@ -1,39 +0,0 @@
1
- # TextLogParser class, a subclass of BasicParser.
2
- # Used for parse()ing text logs.
3
-
4
- module Pidgin2Adium
5
- class TextLogParser < BasicParser
6
- def initialize(src_path, user_aliases, force_conversion = false)
7
- super(src_path, user_aliases, force_conversion)
8
- @timestamp_rx = '\((\d{1,2}:\d{1,2}:\d{1,2})\)'
9
-
10
- # @line_regex matches a line in a TXT log file other than the first
11
- # @line_regex matchdata:
12
- # 0: timestamp
13
- # 1: screen name or alias, if alias set
14
- # 2: "<AUTO-REPLY>" or nil
15
- # 3: message body
16
- @line_regex = /#{@timestamp_rx} (.*?) ?(<AUTO-REPLY>)?: (.*)/o
17
- # @line_regex_status matches a status line
18
- # @line_regex_status matchdata:
19
- # 0: timestamp
20
- # 1: status message
21
- @line_regex_status = /#{@timestamp_rx} ([^:]+)/o
22
- end
23
-
24
- def cleanup(text)
25
- text.tr!("\r", '')
26
- # Escape entities since this will be in XML
27
- text.gsub!('&', '&amp;') # escape '&' first
28
- text.gsub!('<', '&lt;')
29
- text.gsub!('>', '&gt;')
30
- text.gsub!('"', '&quot;')
31
- text.gsub!("'", '&apos;')
32
- # Replace newlines with "<br/>" unless they end a chat line.
33
- # Add the <br/> after converting to &lt; etc so we
34
- # don't escape the tag.
35
- text.gsub!(/\n(?!(#{@timestamp_rx}|\Z))/, '<br/>')
36
- return text
37
- end
38
- end # END TextLogParser class
39
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'ext', 'balance_tags_c'))
4
- require "balance_tags_c"
5
-
6
- describe "BalanceTagsCExtension" do
7
- describe "text without tags" do
8
- it "should be left untouched" do
9
- text = "Foo bar baz, this is my excellent test text!"
10
- Pidgin2Adium.balance_tags_c(text).should == text
11
- end
12
- end
13
-
14
- describe "text with tags" do
15
- it "should be balanced correctly" do
16
- Pidgin2Adium.balance_tags_c('<p><b>this is unbalanced!').should == "<p><b>this is unbalanced!</b></p>"
17
- end
18
-
19
- # Make sure it doesn't segfault
20
- it "should be balanced correctly when run many times" do
21
- text = <<-LATIN
22
- Sequi unde et nobis ipsum. Expedita temporibus aut adipisci debitis
23
- porro ducimus. Dignissimos est tenetur vero error voluptatem quidem
24
- ducimus. Sapiente non occaecati omnis non provident sint ut. Repellat
25
- laudantium quis aperiam ad fugit accusantium placeat itaque. Quia
26
- velit voluptatem sint aliquid rem quam occaecati doloremque. Eos
27
- provident ut suscipit reprehenderit mollitia. Non vitae voluptatem
28
- laudantium quis a et. In libero voluptas aliquam.Veniam minima
29
- consequatur quod. Voluptatem quibusdam ut consequatur et ratione
30
- repellat. Iusto est aspernatur consequatur ex nostrum voluptas
31
- voluptas et. Rerum voluptas et veritatis ratione voluptates ut iusto
32
- ut. Aspernatur sed molestiae sint eveniet asperiores mollitia qui.
33
- Rerum laudantium architecto soluta. Earum qui ut vel corporis ullam
34
- doloribus voluptatem. Nemo quo recusandae ut. Deleniti vel ea qui ut
35
- perferendis. Est dolor ducimus voluptatem nemo quis et animi
36
- reprehenderit. Laudantium voluptas adipisci alias. Ut aut soluta
37
- repellat consequuntur quidem. Deserunt voluptatem eum eveniet cum.Quia
38
- consectetur at ut quisquam occaecati et sint. Sint voluptatem quaerat
39
- qui molestiae ratione voluptatem. Autem labore quos perferendis enim
40
- fuga deleniti recusandae. Aut libero quo cum autem voluptatem.
41
- LATIN
42
- 2_000.times do
43
- Pidgin2Adium.balance_tags_c("<p><b>#{text}").should == "<p><b>#{text}</b></p>"
44
- end
45
- end
46
- end
47
- end
@@ -1,219 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "BasicParser" do
4
- it "should include Pidgin2Adium" do
5
- Pidgin2Adium::BasicParser.included_modules.include?(Pidgin2Adium).should be_true
6
- end
7
-
8
- describe "#parse" do
9
- it "should return false" do
10
- bp = Pidgin2Adium::BasicParser.new(@text_logfile_path,
11
- @aliases)
12
- bp.parse().should be_false
13
- end
14
- end
15
-
16
- describe "#create_adium_time" do
17
- before(:each) do
18
- @first_line_time = "4/18/2007 11:02:00 AM"
19
- @time = "2007-08-20 12:33:13"
20
- @minimal_time = "04:22:05 AM"
21
- @minimal_time_2 = "04:22:05"
22
- @invalid_time = "Hammer time!"
23
-
24
- # Use HTML logfile because it has an explicit timezone (-0500), so we
25
- # don't have to calculate it out.
26
- @bp = Pidgin2Adium::BasicParser.new(@html_logfile_path,
27
- @aliases)
28
- end
29
-
30
- it "should parse a first line time correctly" do
31
- time = @bp.create_adium_time(@first_line_time)
32
- time.should =~ /2007-04-18T11:02:00[-+]\d{2}:00/
33
- end
34
-
35
- it "should parse a normal time correctly" do
36
- time = @bp.create_adium_time(@time)
37
- time.should =~ /2007-08-20T12:33:13[-+]\d{2}:00/
38
- end
39
-
40
- it "should parse a minimal time correctly" do
41
- time = @bp.create_adium_time(@minimal_time)
42
- time.should =~ /2008-01-15T04:22:05[-+]\d{2}:00/
43
- end
44
-
45
- it "should parse a minimal time without AM/PM correctly" do
46
- time = @bp.create_adium_time(@minimal_time_2)
47
- time.should =~ /2008-01-15T04:22:05[-+]\d{2}:00/
48
- end
49
-
50
- it "should return an array of nils for an invalid time" do
51
- time = @bp.create_adium_time(@invalid_time)
52
- time.should be_nil
53
- end
54
- end
55
-
56
- describe "#pre_parse!" do
57
- it "should raise an error for an invalid first line" do
58
- bp = Pidgin2Adium::BasicParser.new(
59
- File.join(@current_dir,
60
- "logfiles",
61
- "invalid-first-line.txt"),
62
- @aliases)
63
- lambda do
64
- bp.pre_parse!()
65
- end.should raise_error(Pidgin2Adium::InvalidFirstLineError)
66
- end
67
-
68
- it "should return true when everything can be parsed" do
69
- bp = Pidgin2Adium::BasicParser.new(@html_logfile_path,
70
- @aliases)
71
- bp.pre_parse!.should be_true
72
- end
73
-
74
- describe "correctly setting variables" do
75
- before do
76
- @bp = Pidgin2Adium::BasicParser.new(@html_logfile_path, @aliases)
77
- @bp.pre_parse!()
78
- end
79
-
80
- it "should correctly set @service" do
81
- @bp.instance_variable_get('@service').should == 'aim'
82
- end
83
-
84
- it "should correctly set user_SN" do
85
- @bp.instance_variable_get('@user_SN').should == 'othersn'
86
- end
87
-
88
- it "should correctly set partner_SN" do
89
- @bp.instance_variable_get('@partner_SN').should == 'aolsystemmsg'
90
- end
91
-
92
- it "should correctly set basic_time_info" do
93
- @bp.instance_variable_get('@basic_time_info').should == {:year=>2008, :mon=>1, :mday=>15}
94
- end
95
-
96
- it "should correctly set adium_chat_time_start" do
97
- @bp.instance_variable_get('@adium_chat_time_start').should == '2008-01-15T07:14:45-05:00'
98
- end
99
- end
100
- end
101
-
102
- describe "#get_sender_by_alias" do
103
- before(:each) do
104
- @my_alias = "Gabe B-W"
105
- @my_SN = "awesomesn" # normalized from "awesome SN"
106
-
107
- @partner_alias = "Leola Farber III"
108
- @partner_SN = "BUDDY_PERSON" # not normalized
109
- # Use text logfile since it has aliases set up.
110
- @bp = Pidgin2Adium::BasicParser.new(@text_logfile_path,
111
- @my_alias)
112
- end
113
-
114
- it "should return my SN when passed my alias" do
115
- @bp.get_sender_by_alias(@my_alias).should == @my_SN
116
- end
117
-
118
- it "should return my SN when passed my alias with an action" do
119
- @bp.get_sender_by_alias("***#{@my_alias}").should == @my_SN
120
- end
121
-
122
- it "should return partner's SN when passed partner's alias" do
123
- @bp.get_sender_by_alias(@partner_alias).should == @partner_SN
124
- end
125
- end
126
-
127
- describe "#create_msg" do
128
- before(:each) do
129
- body = "Your screen name (otherSN) is now signed into " +
130
- "AOL(R) Instant Messenger (TM) in 2 locations. " +
131
- "To sign off the other location(s), reply to this message " + "with the number 1. Click " +
132
- "<a href='http://www.aim.com/password/routing.adp'>here</a> " +
133
- "for more information."
134
- @matches = ['2008-01-15T07.14.45-05:00', # time
135
- 'AOL System Msg', # alias
136
- nil, # not an auto-reply
137
- body # message body
138
- ]
139
- @auto_reply_matches = @matches.dup
140
- @auto_reply_matches[2] = '<AUTO-REPLY>'
141
-
142
- @bp = Pidgin2Adium::BasicParser.new(@text_logfile_path,
143
- "Gabe B-W")
144
- end
145
-
146
-
147
- it "should return XMLMessage class for a normal message" do
148
- @bp.create_msg(@matches).should
149
- be_instance_of(Pidgin2Adium::XMLMessage)
150
- end
151
-
152
- it "should return AutoReplyMessage class for an auto reply" do
153
- @bp.create_msg(@auto_reply_matches).should
154
- be_instance_of(Pidgin2Adium::AutoReplyMessage)
155
- end
156
-
157
- it "should return nil if the time is nil" do
158
- @matches[0] = nil
159
- @bp.create_msg(@matches).should be_nil
160
- end
161
- end
162
-
163
- describe "#create_status_or_event_msg" do
164
- before(:each) do
165
- # not yet converted to Adium format
166
- @time = "2007-08-20 12:33:13"
167
- @alias = "Gabe B-W"
168
- @status_map = {
169
- "#{@alias} logged in." => 'online',
170
- "#{@alias} logged out." => 'offline',
171
- "#{@alias} has signed on." => 'online',
172
- "#{@alias} has signed off." => 'offline',
173
- "#{@alias} has gone away." => 'away',
174
- "#{@alias} is no longer away." => 'available',
175
- "#{@alias} has become idle." => 'idle',
176
- "#{@alias} is no longer idle." => 'available'
177
- }
178
-
179
- # Small subset of all events
180
- @libpurple_event_msg = "Starting transfer of cute kitties.jpg from Gabe B-W"
181
- @event_msg = "You missed 8 messages from Gabe B-W because they were too large"
182
- @event_type = 'chat-error'
183
-
184
- @ignored_event_msg = "Gabe B-W is now known as gbw.<br/>"
185
-
186
- @bp = Pidgin2Adium::BasicParser.new(@html_logfile_path,
187
- @alias)
188
- end
189
-
190
- it "should map statuses correctly" do
191
- @status_map.each do |message, status|
192
- return_value = @bp.create_status_or_event_msg([@time,
193
- message])
194
- return_value.should be_instance_of(Pidgin2Adium::StatusMessage)
195
- return_value.status.should == status
196
- end
197
- end
198
-
199
- it "should map libpurple events correctly" do
200
- return_val = @bp.create_status_or_event_msg([@time,
201
- @libpurple_event_msg])
202
- return_val.should be_instance_of(Pidgin2Adium::Event)
203
- return_val.event_type.should == 'libpurpleEvent'
204
- end
205
-
206
- it "should map non-libpurple events correctly" do
207
- return_val = @bp.create_status_or_event_msg([@time,
208
- @event_msg])
209
- return_val.should be_instance_of(Pidgin2Adium::Event)
210
- return_val.event_type.should == @event_type
211
- end
212
-
213
- it "should return nil for ignored events" do
214
- return_val = @bp.create_status_or_event_msg([@time,
215
- @ignored_event_msg])
216
- return_val.should be_nil
217
- end
218
- end
219
- end
@@ -1,150 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "HtmlLogParser" do
4
- before(:each) do
5
- # @year, @am, and @pm are not required. @time is.
6
- # So @year + @time is a valid time,
7
- # as is @time, and @year + @time + @am.
8
- @year = '2007-10-28 '
9
- @time = '4:46:20'
10
- @am = ' AM'
11
- @pm = ' PM'
12
- @hlp = Pidgin2Adium::HtmlLogParser.new(@html_logfile_path,
13
- @aliases)
14
- @clean = "clean"
15
- end
16
-
17
- it "should have Pidgin2Adium.balance_tags_c available" do
18
- Pidgin2Adium.should respond_to(:balance_tags_c)
19
- end
20
-
21
- describe "#cleanup" do
22
- it "should remove html, body, and font tags" do
23
- dirty_text = %Q{<html><body type="ichat"><font color="red">#{@clean}</font></body></html>}
24
- @hlp.cleanup(dirty_text).should == @clean
25
- end
26
-
27
- it "should remove those weird <FONT HSPACE> tags" do
28
- dirty = %Q{&lt;/FONT HSPACE='2'>#{@clean}}
29
- @hlp.cleanup(dirty).should == @clean
30
- end
31
-
32
- it "should remove \\r" do
33
- dirty = [@clean, @clean, @clean].join("\r")
34
- @hlp.cleanup(dirty).should == @clean * 3
35
- end
36
-
37
- it "should remove empty lines" do
38
- dirty = "#{@clean}\n\n"
39
- @hlp.cleanup(dirty).should == @clean
40
- end
41
-
42
- it "should replace newlines with <br/>" do
43
- dirty = "\n#{@clean}"
44
- @hlp.cleanup(dirty).should == "<br/>#{@clean}"
45
- end
46
-
47
- it "should remove empty links" do
48
- dirty = %Q{<a href="awesomelink"> </a>#{@clean}}
49
- dirty += %Q{<a href='awesomelink'></a>#{@clean}}
50
- @hlp.cleanup(dirty).should == @clean + @clean
51
- end
52
-
53
- describe "with <span>s" do
54
- it "should remove font-family" do
55
- dirty = %Q{<span style='font-family: Helvetica;'>#{@clean}</span>}
56
- @hlp.cleanup(dirty).should == @clean
57
- end
58
-
59
- it "should remove font-size" do
60
- dirty = %Q{<span style="font-size: 6;">#{@clean}</span>}
61
- @hlp.cleanup(dirty).should == @clean
62
- end
63
-
64
- it "should remove background" do
65
- dirty = %Q{<span style="background: #00afaf;">#{@clean}</span>}
66
- @hlp.cleanup(dirty).should == @clean
67
- end
68
-
69
- it "should remove color=#00000" do
70
- dirty = %Q{<span style="color: #000000;">#{@clean}</span>}
71
- @hlp.cleanup(dirty).should == @clean
72
- end
73
-
74
- it "should not remove color != #00000" do
75
- dirty = %Q{<span style="color: #01ABcdef;">#{@clean}</span>}
76
- @hlp.cleanup(dirty).should == dirty
77
- end
78
-
79
- it "should remove improperly-formatted colors" do
80
- dirty = %Q{<span style="color: #0;">#{@clean}</span>}
81
- @hlp.cleanup(dirty).should == @clean
82
- end
83
-
84
- it "should replace <em> with italic font-style" do
85
- dirty = "<em>#{@clean}</em>"
86
- clean = %Q{<span style="font-style: italic;">#{@clean}</span>}
87
- @hlp.cleanup(dirty).should == clean
88
- end
89
-
90
- it "shouldn't modify clean text" do
91
- @hlp.cleanup(@clean).should == @clean
92
- end
93
-
94
- # This implicitly tests a lot of other things, but they've been tested
95
- # before this too.
96
- it "should remove a trailing space after style declaration and replace double quotes" do
97
- dirty_span_open = "<span style='color: #afaf00; font-size: 14pt; font-weight: bold; '>"
98
- # Replaced double quotes, removed space before ">"
99
- clean_span_open = '<span style="color: #afaf00;">'
100
- dirty = dirty_span_open + @clean + "</span>"
101
- @hlp.cleanup(dirty).should == clean_span_open + @clean + "</span>"
102
- end
103
- end
104
- end
105
-
106
- describe "#parse" do
107
- before(:each) do
108
- @logfile = @hlp.parse()
109
- end
110
-
111
- it "should return a LogFile instance" do
112
- @logfile.should be_instance_of(Pidgin2Adium::LogFile)
113
- end
114
-
115
- it "should return a LogFile with the correct number of chat_lines" do
116
- @logfile.chat_lines.size.should == 3
117
- end
118
-
119
- it "should return a LogFile with the correct message type" do
120
- @logfile.chat_lines.map{|x| x.class }.should == [Pidgin2Adium::XMLMessage] * 3
121
- end
122
-
123
- it "should return a LogFile with the correct data" do
124
- first_msg = @logfile.chat_lines[0]
125
- second_msg = @logfile.chat_lines[1]
126
- third_msg = @logfile.chat_lines[2]
127
-
128
- first_msg.sender.should == "aolsystemmsg"
129
- first_msg.buddy_alias.should == "AOL System Msg"
130
- # Use regex to ignore time zone
131
- first_msg.time.should =~ /^2008-01-15T07:14:45[-+]\d{2}:00$/
132
- # This fails due to balance_tags_c().
133
- good_body = %Q{Your screen name (otherSN) is now signed into AOL(R) Instant Messenger (TM) in 2 locations.} + " " +
134
- %Q{To sign off the other location(s), reply to this message with the number 1.} + " " +
135
- %Q{Click <a href="http://www.aim.com/password/routing.adp">here</a> for more information.}
136
- first_msg.body.should == good_body
137
-
138
- second_msg.sender.should == "othersn"
139
- second_msg.buddy_alias.should == "Gabe B-W"
140
- second_msg.time.should =~ /^2008-01-15T07:14:48[-+]\d{2}:00$/
141
- second_msg.body.should == "1"
142
-
143
- third_msg.sender.should == "aolsystemmsg"
144
- third_msg.buddy_alias.should == "AOL System Msg"
145
- # Use regex to ignore time zone
146
- third_msg.time.should =~ /^2008-01-15T07:14:48[-+]\d{2}:00$/
147
- third_msg.body.should == "Your other AIM sessions have been signed-off. You are now signed-on from 1 location(s)."
148
- end
149
- end
150
- end