rpatricia.git  about / heads / tags
see http://www.goto.info.waseda.ac.jp/~tatsuya/rpatricia/
blob c6ddc1c0161a8d509b847a913bf85631769cf55f 1302 bytes (raw)
$ git show ipv6:test/test_duplicate.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
require 'test/unit'
require 'rpatricia'
require 'stringio'

class TestDuplicate < Test::Unit::TestCase
  def test_dup
    tmp = {}
    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

    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

git clone https://yhbt.net/rpatricia.git