Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Improvements to LineProtocol and have it autoload. #151

Merged
merged 1 commit into from

3 participants

@gaffneyc

I've fixed 3 things with LineProtocol:

  • It no longer includes the new line characters when it calls receive_line
  • It now has some basic tests
  • It now gets autoloaded

Open Issue:
https://github.com/eventmachine/eventmachine/issues/issue/150

@ibc
ibc commented

Hi, this pull request (along with others) has been included in EventMachine-LE

@tmm1 tmm1 merged commit 2a3ab8e into eventmachine:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 5, 2011
  1. @gaffneyc

    Trim newline characters in LineProtocol and include it in autoload.

    gaffneyc authored
    Also added some basic tests for LineProtocol.
This page is out of date. Refresh to see the latest.
View
1  lib/em/protocols.rb
@@ -32,5 +32,6 @@ module Protocols
autoload :Postgres3, 'em/protocols/postgres3'
autoload :ObjectProtocol, 'em/protocols/object_protocol'
autoload :Socks4, 'em/protocols/socks4'
+ autoload :LineProtocol, 'em/protocols/line_protocol'
end
end
View
4 lib/em/protocols/line_protocol.rb
@@ -14,8 +14,8 @@ module LineProtocol
def receive_data data # :nodoc:
(@buf ||= '') << data
- while line = @buf.slice!(/(.*)\r?\n/)
- receive_line(line)
+ while @buf.slice!(/(.*?)\r?\n/)
+ receive_line($1)
end
end
View
33 tests/test_line_protocol.rb
@@ -0,0 +1,33 @@
+require 'em_test_helper'
+
+class TestLineProtocol < Test::Unit::TestCase
+ class LineProtocolTestClass
+ include EM::Protocols::LineProtocol
+
+ def lines
+ @lines ||= []
+ end
+
+ def receive_line(line)
+ lines << line
+ end
+ end
+
+ def setup
+ @proto = LineProtocolTestClass.new
+ end
+
+ def test_simple_split_line
+ @proto.receive_data("this is")
+ assert_equal([], @proto.lines)
+
+ @proto.receive_data(" a test\n")
+ assert_equal(["this is a test"], @proto.lines)
+ end
+
+ def test_simple_lines
+ @proto.receive_data("aaa\nbbb\r\nccc\nddd")
+ assert_equal(%w(aaa bbb ccc), @proto.lines)
+ end
+
+end
Something went wrong with that request. Please try again.