Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #151 from gaffneyc/master

Improvements to LineProtocol and have it autoload.
  • Loading branch information...
commit 2a3ab8e883aaa60b1a0223e6183055d234d6bdbf 2 parents 11ef5f9 + 36b9fa7
Aman Gupta tmm1 authored
1  lib/em/protocols.rb
View
@@ -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
4 lib/em/protocols/line_protocol.rb
View
@@ -15,8 +15,8 @@ module LineProtocol
def receive_data data
(@buf ||= '') << data
- while line = @buf.slice!(/(.*)\r?\n/)
- receive_line(line)
+ while @buf.slice!(/(.*?)\r?\n/)
+ receive_line($1)
end
end
33 tests/test_line_protocol.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.