Skip to content

Commit

Permalink
fixing indentation and minitest deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aberant committed Feb 17, 2020
1 parent 806885d commit a173bcc
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 122 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 16 additions & 16 deletions lib/osc-ruby/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 18 additions & 19 deletions lib/osc-ruby/osc_packet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -90,8 +90,7 @@ def get_timestamp
end

def get_arguments
if @packet.getc == ?,

if (@packet.getc == ?,)
tags = get_string
args = []

Expand Down
74 changes: 37 additions & 37 deletions spec/unit/address_pattern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions spec/unit/message_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@

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
mesg = @builder.with_address("/hi").
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)
Expand Down
24 changes: 12 additions & 12 deletions spec/unit/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
18 changes: 9 additions & 9 deletions spec/unit/network_packet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit a173bcc

Please sign in to comment.