YUKI Hiroshi
null+****@clear*****
Thu Apr 30 11:20:06 JST 2015
YUKI Hiroshi 2015-04-30 11:20:06 +0900 (Thu, 30 Apr 2015) New Revision: ad741fa4e230497ef32077d9bbc6ca371d75c1e5 https://github.com/droonga/droonga-engine/commit/ad741fa4e230497ef32077d9bbc6ca371d75c1e5 Message: Add more tests for Address Modified files: test/unit/test_address.rb Modified: test/unit/test_address.rb (+111 -10) =================================================================== --- test/unit/test_address.rb 2015-04-30 11:17:24 +0900 (4664c57) +++ test/unit/test_address.rb 2015-04-30 11:20:06 +0900 (645d433) @@ -1,4 +1,4 @@ -# Copyright (C) 2014 Droonga Project +# Copyright (C) 2014-2015 Droonga Project # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -28,19 +28,80 @@ class AddressTest < Test::Unit::TestCase Droonga::Address.parse(string) end - def test_full - assert_equal(address("192.168.0.1", 2929, "droonga", "local_name"), - parse("192.168.0.1:2929/droonga.local_name")) + data(:full => { + :input => "node29:2929/droonga.local_name", + :host => "node29", + :port => 2929, + :tag => "droonga", + :local_name => "local_name", + }, + :ip_address => { + :input => "192.168.0.1:2929/droonga.local_name", + :host => "192.168.0.1", + :port => 2929, + :tag => "droonga", + :local_name => "local_name", + }, + :internal_name => { + :input => "node29:2929/droonga.\#1", + :host => "node29", + :port => 2929, + :tag => "droonga", + :local_name => "#1", + }, + :no_local_name => { + :input => "node29:2929/droonga", + :host => "node29", + :port => 2929, + :tag => "droonga", + :local_name => nil, + }) + def test_success(data) + assert_equal(address(data[:host], data[:port], data[:tag], + data[:local_name]), + parse(data[:input])) end - def test_internal_name - assert_equal(address("192.168.0.1", 2929, "droonga", "#1"), - parse("192.168.0.1:2929/droonga.\#1")) + data(:no_host => ":2929/droonga", + :no_port => "192.168.0.1/droonga", + :no_tag => "192.168.0.1:2929", + :blank => "", + :nil => nil) + def test_fail(input) + assert_raise(ArgumentError) do + parse(input) + end + end + end + + class AttributeTest < self + def test_attributes + address = address("192.168.0.1", 2929, "droonga", "000") + assert_equal({:host => "192.168.0.1", + :port => 2929, + :tag => "droonga", + :local_name => "000"}, + {:host => address.host, + :port => address.port, + :tag => address.tag, + :local_name => address.local_name}) + end + end + + class ComparisonTest < self + def test_address_vs_string + string = "192.168.0.1:2929/droonga.000" + address = address("192.168.0.1", 2929, "droonga", "000") + assert_true(address == string) end - def test_no_name - assert_equal(address("192.168.0.1", 2929, "droonga", nil), - parse("192.168.0.1:2929/droonga")) + #XXX This is a confusable behavior. It seems should be true + # but actually false, so you have to be careful when you + # compare string with Address. + def test_string_vs_address + string = "192.168.0.1:2929/droonga.000" + address = address("192.168.0.1", 2929, "droonga", "000") + assert_false(string == address) end end @@ -49,5 +110,45 @@ class AddressTest < Test::Unit::TestCase assert_equal("192.168.0.1:2929/droonga", address("192.168.0.1", 2929, "droonga", "000").node) end + + data(:full => { + :expected => "192.168.0.1:2929/droonga.000", + :host => "192.168.0.1", + :port => 2929, + :tag => "droonga", + :local_name => "000", + }, + :no_local_name => { + :expected => "192.168.0.1:2929/droonga", + :host => "192.168.0.1", + :port => 2929, + :tag => "droonga", + :local_name => nil, + }) + def test_string(data) + assert_equal(data[:expected], + address(data[:host], data[:port], data[:tag], + data[:local_name]).to_s) + end + + data(:full => { + :expected => ["192.168.0.1", 2929, "droonga", "000"], + :host => "192.168.0.1", + :port => 2929, + :tag => "droonga", + :local_name => "000", + }, + :no_local_name => { + :expected => ["192.168.0.1", 2929, "droonga", nil], + :host => "192.168.0.1", + :port => 2929, + :tag => "droonga", + :local_name => nil, + }) + def test_array(data) + assert_equal(data[:expected], + address(data[:host], data[:port], data[:tag], + data[:local_name]).to_a) + end end end -------------- next part -------------- HTML����������������������������... Download