diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-06-02 21:30:10 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-06-02 21:30:10 +0000 |
commit | d5c6ce5b1c2f67920bb9499d7f79ed0a5a75ced2 (patch) | |
tree | 4b074b7616446436e451c46ca0ae0cae5275e0f1 /test/test_duplicate.rb | |
parent | 77f0be59a45d9ed6dd5f87c8cff90da90a17e421 (diff) | |
download | rpatricia-d5c6ce5b1c2f67920bb9499d7f79ed0a5a75ced2.tar.gz |
update Patricia.new for optional IPv6 support
IPv4 is still the default and will likely remain so indefinitely.
Diffstat (limited to 'test/test_duplicate.rb')
-rw-r--r-- | test/test_duplicate.rb | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/test/test_duplicate.rb b/test/test_duplicate.rb index c50a211..c6ddc1c 100644 --- a/test/test_duplicate.rb +++ b/test/test_duplicate.rb @@ -8,21 +8,42 @@ class TestDuplicate < Test::Unit::TestCase t = Patricia.new t.add('127.0.0.0/8', tmp) t2 = t.dup + assert_equal :AF_INET, t2.family assert_equal 1, t2.num_nodes assert_equal tmp.object_id, t2.match_best('127.0.0.1').data.object_id t2.add('10.0.0.0/8', zz = []) assert_equal 2, t2.num_nodes assert_equal 1, t.num_nodes - oldout = $stdout - begin - $stdout = stringio = StringIO.new - t2.show_nodes - puts "--" - t.show_nodes - ensure - $stdout = oldout - end - p stringio.string + tio = StringIO.new + t.show_nodes(tio) + assert_equal "node: 127.0.0.0/8\n", tio.string + + t2io = StringIO.new + t2.show_nodes(t2io) + assert_equal("node: 10.0.0.0/8\nnode: 127.0.0.0/8\n", t2io.string) + end + + def test_dup_ipv6 + tmp = {} + t = Patricia.new :AF_INET6 + t.add('1234:4321::/32', tmp) + t.add('2600:0102:a100::/43', tmp) + t2 = t.dup + assert_equal :AF_INET6, t2.family + assert_equal 2, t2.num_nodes + t2.add('::1/128', zz = []) + assert_equal 3, t2.num_nodes + assert_equal 2, t.num_nodes + + tio = StringIO.new + t.show_nodes(tio) + expect = "node: 1234:4321::/32\nnode: 2600:102:a100::/43\n" + assert_equal expect, tio.string + + t2io = StringIO.new + t2.show_nodes(t2io) + expect = "node: ::1/128\nnode: 1234:4321::/32\nnode: 2600:102:a100::/43\n" + assert_equal expect, t2io.string end end |