diff --git a/Gemfile b/Gemfile index 50546d3..ad7daa7 100644 --- a/Gemfile +++ b/Gemfile @@ -4,4 +4,9 @@ source "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } +gem "rake" gem "eventmachine" + +group :test do + gem "minitest" +end diff --git a/lib/osc-ruby/bundle.rb b/lib/osc-ruby/bundle.rb index c801349..0111948 100644 --- a/lib/osc-ruby/bundle.rb +++ b/lib/osc-ruby/bundle.rb @@ -23,24 +23,24 @@ def to_a def encode_timetag(t) case t - when nil # immediately - t1 = 0 - t2 = 1 - when Numeric - t1, t2 = construct_timetag(t) - when Time - t1, t2 = construct_timetag(t.to_ntp) - else - raise(ArgumentError, 'invalid time') - end - [t1, t2].pack('N2') + when nil # immediately + t1 = 0 + t2 = 1 + when Numeric + t1, t2 = construct_timetag(t) + when Time + t1, t2 = construct_timetag(t.to_ntp) + else + raise(ArgumentError, 'invalid time') end + [t1, t2].pack('N2') + end - def construct_timetag(time) - t1, fr = time.divmod(1) - t2 = (fr * (2**32)).to_i + def construct_timetag(time) + t1, fr = time.divmod(1) + t2 = (fr * (2**32)).to_i - [t1, t2] - end + [t1, t2] end end +end diff --git a/lib/osc-ruby/osc_packet.rb b/lib/osc-ruby/osc_packet.rb index 3f3d08c..6118dc2 100644 --- a/lib/osc-ruby/osc_packet.rb +++ b/lib/osc-ruby/osc_packet.rb @@ -53,28 +53,28 @@ def initialize(string) "s" => lambda{ OSCString.new(get_string)}, "b" => lambda{ OSCBlob.new(get_blob)} } - end + end - def get_bundle_messages - bundle_messages = [] + def get_bundle_messages + bundle_messages = [] - until @packet.eof? - l = @packet.getn(4).unpack('N')[0] - bundle_messages << @packet.getn(l) + until @packet.eof? + l = @packet.getn(4).unpack('N')[0] + bundle_messages << @packet.getn(l) + end + bundle_messages end - bundle_messages - end - def get_string - result = '' - until (c = @packet.getc) == string_delemeter - result << c - end - @packet.skip_padding - result - end + def get_string + result = '' + until ((c = @packet.getc) == string_delemeter) + result << c + end + @packet.skip_padding + result + end - def get_timestamp + def get_timestamp #TODO: refactor this so a mortal can figure it out t1 = @packet.getn(4).unpack('N')[0] t2 = @packet.getn(4).unpack('N')[0] @@ -90,8 +90,7 @@ def get_timestamp end def get_arguments - if @packet.getc == ?, - + if (@packet.getc == ?,) tags = get_string args = [] diff --git a/spec/unit/address_pattern_spec.rb b/spec/unit/address_pattern_spec.rb index d03b25a..c16a489 100644 --- a/spec/unit/address_pattern_spec.rb +++ b/spec/unit/address_pattern_spec.rb @@ -15,79 +15,79 @@ it "should match anything if the pattern is nil" do ap = OSC::AddressPattern.new(nil) - ap.match?("/some/nonsense").must_equal(true) - ap.match?("/completely.different").must_equal(true) + _(ap.match?("/some/nonsense")).must_equal(true) + _(ap.match?("/completely.different")).must_equal(true) end it "should match based on a regex" do ap = OSC::AddressPattern.new(/hi/) - ap.match?('/hi').must_equal(true) - ap.match?('/hidden').must_equal(true) + _(ap.match?('/hi')).must_equal(true) + _(ap.match?('/hidden')).must_equal(true) - ap.match?('/bye').must_equal(false) + _(ap.match?('/bye')).must_equal(false) end it "should return a regex if the pattern is a string" do ap = OSC::AddressPattern.new("/hi") - ap.match?('/hi').must_equal(true) + _(ap.match?('/hi')).must_equal(true) - ap.match?(' /hi').must_equal(false) - ap.match?('/ahi').must_equal(false) - ap.match?('/hidden').must_equal(false) - ap.match?('/bye').must_equal(false) + _(ap.match?(' /hi')).must_equal(false) + _(ap.match?('/ahi')).must_equal(false) + _(ap.match?('/hidden')).must_equal(false) + _(ap.match?('/bye')).must_equal(false) end it "should match with question mark" do ap = OSC::AddressPattern.new("/h?l") - ap.match?('/hal').must_equal(true) - ap.match?('/hel').must_equal(true) - ap.match?('/hil').must_equal(true) - ap.match?('/hol').must_equal(true) - ap.match?('/hul').must_equal(true) - ap.match?('/hub').must_equal(false) + _(ap.match?('/hal')).must_equal(true) + _(ap.match?('/hel')).must_equal(true) + _(ap.match?('/hil')).must_equal(true) + _(ap.match?('/hol')).must_equal(true) + _(ap.match?('/hul')).must_equal(true) + _(ap.match?('/hub')).must_equal(false) end it "should match with *" do ap = OSC::AddressPattern.new("/believ*d") - ap.match?('/believd').must_equal(true) - ap.match?('/believed').must_equal(true) - ap.match?('/believeeed').must_equal(true) - ap.match?('/believaeeeioud').must_equal(true) - ap.match?('/believaeeeioud').must_equal(true) + _(ap.match?('/believd')).must_equal(true) + _(ap.match?('/believed')).must_equal(true) + _(ap.match?('/believeeed')).must_equal(true) + _(ap.match?('/believaeeeioud')).must_equal(true) + _(ap.match?('/believaeeeioud')).must_equal(true) end it "should match with []" do ap = OSC::AddressPattern.new("/believ[aeiou]d") - ap.match?('/believad').must_equal(true) - ap.match?('/believed').must_equal(true) - ap.match?('/believid').must_equal(true) - ap.match?('/believod').must_equal(true) - ap.match?('/believud').must_equal(true) - ap.match?('/believkd').must_equal(false) + _(ap.match?('/believad')).must_equal(true) + _(ap.match?('/believed')).must_equal(true) + _(ap.match?('/believid')).must_equal(true) + _(ap.match?('/believod')).must_equal(true) + _(ap.match?('/believud')).must_equal(true) + _(ap.match?('/believkd')).must_equal(false) end it "should match with [!]" do ap = OSC::AddressPattern.new("/believ[!aeiou]d") - ap.match?('/believad').must_equal(false) - ap.match?('/believed').must_equal(false) - ap.match?('/believid').must_equal(false) - ap.match?('/believod').must_equal(false) - ap.match?('/believud').must_equal(false) - ap.match?('/believkd').must_equal(true) - ap.match?('/believzd').must_equal(true) + _(ap.match?('/believad')).must_equal(false) + _(ap.match?('/believed')).must_equal(false) + _(ap.match?('/believid')).must_equal(false) + _(ap.match?('/believod')).must_equal(false) + _(ap.match?('/believud')).must_equal(false) + _(ap.match?('/believkd')).must_equal(true) + _(ap.match?('/believzd')).must_equal(true) end it "should match with {}" do ap = OSC::AddressPattern.new("/{hi,bye}") - ap.match?('/hi').must_equal(true) - ap.match?('/bye').must_equal(true) - ap.match?('/greetings').must_equal(false) + _(ap.match?('/hi')).must_equal(true) + _(ap.match?('/bye')).must_equal(true) + _(ap.match?('/greetings')).must_equal(false) end end \ No newline at end of file diff --git a/spec/unit/message_builder_spec.rb b/spec/unit/message_builder_spec.rb index d00d248..23cf416 100644 --- a/spec/unit/message_builder_spec.rb +++ b/spec/unit/message_builder_spec.rb @@ -7,27 +7,27 @@ it "encodes just the address" do mesg = @builder.with_address("/hi") - mesg.build.encode.must_equal binary_string("/hi\000,\000\000\000") + _(mesg.build.encode).must_equal binary_string("/hi\000,\000\000\000") end it "encodes single int values" do mesg = @builder.with_address("/hi"). with_int(33) - mesg.build.encode.must_equal binary_string("/hi\000,i\000\000\000\000\000!") + _(mesg.build.encode).must_equal binary_string("/hi\000,i\000\000\000\000\000!") end it "encodes single string values" do mesg = @builder.with_address("/hi"). with_string("hello") - mesg.build.encode.must_equal binary_string("/hi\000,s\000\000hello\000\000\000") + _(mesg.build.encode).must_equal binary_string("/hi\000,s\000\000hello\000\000\000") end it "encodes single float values" do mesg = @builder.with_address("/hi"). with_float(3.14159) - mesg.build.encode.must_equal binary_string("/hi\000,f\000\000@I\017\320") + _(mesg.build.encode).must_equal binary_string("/hi\000,f\000\000@I\017\320") end it "encodes multiple floats" do @@ -35,7 +35,7 @@ with_float(3.14159). with_float(4.5) - mesg.build.encode.must_equal [47, 104, 105, 0, 44, 102, 102, 0, 64, 73, 15, 208, 64, 144, 0, 0].pack("C*") + _(mesg.build.encode).must_equal [47, 104, 105, 0, 44, 102, 102, 0, 64, 73, 15, 208, 64, 144, 0, 0].pack("C*") end def binary_string(string) diff --git a/spec/unit/message_spec.rb b/spec/unit/message_spec.rb index 7317940..5536ecb 100644 --- a/spec/unit/message_spec.rb +++ b/spec/unit/message_spec.rb @@ -15,42 +15,42 @@ describe "basic traits" do it "should have no arguments if you define none" do m = OSC::Message.new("/hi") - m.to_a.must_equal([]) + _(m.to_a).must_equal([]) end it "should accept int arguments" do m = OSC::Message.new("/hi", 42) - m.to_a.must_equal([42]) - m.tags.must_equal("i") + _(m.to_a).must_equal([42]) + _(m.tags).must_equal("i") end it "should accept string arguments" do m = OSC::Message.new("/hi", "42") - m.to_a.must_equal(["42"]) - m.tags.must_equal("s") + _(m.to_a).must_equal(["42"]) + _(m.tags).must_equal("s") end it "should accept float arguments" do m = OSC::Message.new("/hi", 42.001) - m.to_a.must_equal([42.001]) - m.tags.must_equal("f") + _(m.to_a).must_equal([42.001]) + _(m.tags).must_equal("f") end end describe "message output encoding" do it "integer arguments output binary/ascii string" do m = OSC::Message.new("/hi", 42).encode - m.encoding.to_s.must_equal("ASCII-8BIT") + _(m.encoding.to_s).must_equal("ASCII-8BIT") end it "string arguments output binary/ascii string" do m = OSC::Message.new("/hi", "42").encode - m.encoding.to_s.must_equal("ASCII-8BIT") + _(m.encoding.to_s).must_equal("ASCII-8BIT") end it "float arguments output binary/ascii string" do m = OSC::Message.new("/hi", 3.14159).encode - m.encoding.to_s.must_equal("ASCII-8BIT") + _(m.encoding.to_s).must_equal("ASCII-8BIT") end end @@ -66,8 +66,8 @@ it "should know equality" do @message2 = @builder.build - @message.object_id.wont_equal(@message2.object_id) - @message.must_equal(@message2) + _(@message.object_id).wont_equal(@message2.object_id) + _(@message).must_equal(@message2) end end end \ No newline at end of file diff --git a/spec/unit/network_packet_spec.rb b/spec/unit/network_packet_spec.rb index 16b219e..f406893 100644 --- a/spec/unit/network_packet_spec.rb +++ b/spec/unit/network_packet_spec.rb @@ -8,30 +8,30 @@ end it "should know if it's at the end of the stream" do - @empty.eof?.must_equal(true) + _(@empty.eof?).must_equal(true) end it "should know the remainder in the stream" do - @simple.rem.must_equal(3) + _(@simple.rem).must_equal(3) end it "should be able to skip positions" do @simple.skip(1) - @simple.rem.must_equal(2) + _(@simple.rem).must_equal(2) end it "should be able to get a character from the stream" do - @simple.getc.must_equal(?a) - @simple.getc.must_equal(?b) - @simple.getc.must_equal(?c) - @simple.eof?.must_equal(true) + _(@simple.getc).must_equal(?a) + _(@simple.getc).must_equal(?b) + _(@simple.getc).must_equal(?c) + _(@simple.eof?).must_equal(true) end it "should be able to get a number of characters from the stream" do - @simple.getn(3).must_equal("abc") + _(@simple.getn(3)).must_equal("abc") end it "outputs characters with ASCII/BINARY encoding" do - @simple.getc.encoding.to_s.must_equal("ASCII-8BIT") + _(@simple.getc.encoding.to_s).must_equal("ASCII-8BIT") end end diff --git a/spec/unit/osc_complex_packets_spec.rb b/spec/unit/osc_complex_packets_spec.rb index e3c5978..b3fdbd8 100644 --- a/spec/unit/osc_complex_packets_spec.rb +++ b/spec/unit/osc_complex_packets_spec.rb @@ -9,31 +9,31 @@ end it "should have three messages" do - @messages.size.must_equal(3) + _(@messages.size).must_equal(3) end it "should have the propper address for the messages" do 3.times do |i| - @messages[i].address.must_equal("/tuio/2Dobj") + _(@messages[i].address).must_equal("/tuio/2Dobj") end end it "should have a first message with two strings" do args = @messages[0].to_a - args[0].must_equal("source") - args[1].must_equal("simulator") + _(args[0]).must_equal("source") + _(args[1]).must_equal("simulator") end it "should have a second message with one string" do args = @messages[1].to_a - args[0].must_equal("alive") + _(args[0]).must_equal("alive") end it "should have a third message with a string and an int" do args = @messages[2].to_a - args[0].must_equal("fseq") - args[1].must_equal(-1) + _(args[0]).must_equal("fseq") + _(args[1]).must_equal(-1) end end \ No newline at end of file diff --git a/spec/unit/osc_packet_unknown_type_spec.rb b/spec/unit/osc_packet_unknown_type_spec.rb index 6f8cfe3..5618ff8 100644 --- a/spec/unit/osc_packet_unknown_type_spec.rb +++ b/spec/unit/osc_packet_unknown_type_spec.rb @@ -5,8 +5,6 @@ class OSC::BadType < OSC::OSCInt32; def tag() 'Z'; end end sent_msg = OSC::Message.new("/badtype", OSC::BadType.new(42)) - lambda do - OSC::OSCPacket.messages_from_network(sent_msg.encode) - end.must_raise OSC::UnknownType + _ {OSC::OSCPacket.messages_from_network(sent_msg.encode)}.must_raise OSC::UnknownType end end \ No newline at end of file diff --git a/spec/unit/osc_simple_packets_spec.rb b/spec/unit/osc_simple_packets_spec.rb index c90f92a..8957734 100644 --- a/spec/unit/osc_simple_packets_spec.rb +++ b/spec/unit/osc_simple_packets_spec.rb @@ -24,28 +24,28 @@ sent_msg = @builder.build msg = OSC::OSCPacket.messages_from_network(sent_msg.encode) - msg.first.address.must_equal(@address) + _(msg.first.address).must_equal(@address) end it "should decode the int arg of a simple message from the network data" do sent_msg = @builder.with_int(@first_int).build msg = OSC::OSCPacket.messages_from_network(sent_msg.encode) - msg.first.to_a.must_equal([@first_int]) + _(msg.first.to_a).must_equal([@first_int]) end it "should decode two int args" do sent_msg = @builder.with_int(@first_int ).with_int( @second_int).build msg = OSC::OSCPacket.messages_from_network(sent_msg.encode) - msg.first.to_a.must_equal([@first_int, @second_int]) + _(msg.first.to_a).must_equal([@first_int, @second_int]) end it "should decode address with float arg" do sent_msg = @builder.with_float(@first_float).build msg = OSC::OSCPacket.messages_from_network(sent_msg.encode) - msg.first.to_a[0].must_be_close_to(@first_float, 0.001) + _(msg.first.to_a[0]).must_be_close_to(@first_float, 0.001) end @@ -54,15 +54,15 @@ msg = OSC::OSCPacket.messages_from_network(sent_msg.encode) args = msg.first.to_a - args.first.must_be_close_to(@first_float, 0.001) - args[1].must_be_close_to(@second_float, 0.001) + _(args.first).must_be_close_to(@first_float, 0.001) + _(args[1]).must_be_close_to(@second_float, 0.001) end it "should decode address with string arg" do sent_msg = @builder.with_string(@first_string).build msg = OSC::OSCPacket.messages_from_network(sent_msg.encode) - msg.first.to_a.must_equal([@first_string]) + _(msg.first.to_a).must_equal([@first_string]) end it "should decode address with multiple string args" do @@ -70,8 +70,8 @@ msg = OSC::OSCPacket.messages_from_network(sent_msg.encode) args = msg.first.to_a - args[0].must_equal(@first_string) - args[1].must_equal(@second_string) + _(args[0]).must_equal(@first_string) + _(args[1]).must_equal(@second_string) end @@ -85,9 +85,9 @@ args = msg.first.to_a - args[0].must_equal(@first_int) - args[1].must_be_close_to(@second_float, 0.001) - args[2].must_equal(@first_string) + _(args[0]).must_equal(@first_int) + _(args[1]).must_be_close_to(@second_float, 0.001) + _(args[2]).must_equal(@first_string) end it "should decode messages with blobs" do @@ -97,7 +97,7 @@ msg = OSC::OSCPacket.messages_from_network(sent_msg.encode) args = msg.first.to_a - args.first.must_equal(@first_blob) + _(args.first).must_equal(@first_blob) end it "should decode messages with double64 types" do @@ -107,6 +107,6 @@ msg = OSC::OSCPacket.messages_from_network(sent_msg.encode) args = msg.first.to_a - args.first.must_be_close_to(pi, 0.001) + _(args.first).must_be_close_to(pi, 0.001) end end \ No newline at end of file