Class RPath::RPathTest
In: lib/r_path.rb
Parent: Test::Unit::TestCase

Methods

Public Instance methods

[Source]

# File lib/r_path.rb, line 186
      def assert_rpath ( re, ref, ref_match=[] )
        ref1, my1, ref2, my2 = assert_rpath_base(re, ref, ref_match)
        assert_equal(ref1, my1, 'trees are not equal')
        assert_equal(ref2, my2, 'match datas are not equal')
      end

[Source]

# File lib/r_path.rb, line 179
      def assert_rpath_base ( re, ref, ref_match=[] )
        select = @tree.rpath_select_match_data(re)
        my = []
        select.map { |x, *a| my << a unless a.empty? }
        [ref.flatten, select.map { |a| a.first }, ref_match, my]
      end

[Source]

# File lib/r_path.rb, line 192
      def assert_rpath_set ( re, ref, ref_match=[] )
        ref1, my1, ref2, my2 = assert_rpath_base(re, ref, ref_match)
        assert_equal(ref1.to_set, my1.to_set, 'trees are not equal')
        assert_equal(ref2.to_set, my2.to_set, 'match datas are not equal')
      end

[Source]

# File lib/r_path.rb, line 198
      def setup
        @tree = {
          'Name' => 'Foo',
          'FirstName' => 'Bar',
          'Emails' => {
            'home' => 'foo312@coldmail.com',
            'work' => 'bfoo@staff.com',
            'edu' =>  'bar.foo@school.edu'
          },
          'Phones' => ['101', '202', '203'],
          'Deep' => { 'A' => { 'B' => ['1', 2, 'a', '3'], 'C' => '4' } },
          'users' => [
            {
              'name' => 'Sea',
              'tel' => '111'
            },
            {
              'name' => 'Sex',
              'tel' => '222'
            },
            {
              'name' => 'Sun',
              'tel' => '333'
            },
            {
              'foo' => 'SeSe',
              'tel' => '222'
            },
          ]
        }
      end

[Source]

# File lib/r_path.rb, line 274
      def test_example
        foo = { :home => 'here',       :email => 'foo@foo.com' }
        bar = { :home => "bar's home", :email => 'bar@foo.bar' }
        baz = { :home => 'nowhere',    :email => 'baz@bar.com' }
        @tree = {
          :A => {
            :AA  => { :AAA => 'foo' },
            'AB' => [ :AB1, 2, 'a b 3' ],
          },
          :B => {
            'foo' => foo,
            'bar' => bar,
            'baz' => baz
          }
        }

        assert_rpath('/A/AA/AAA/', ['foo'])

        assert_rpath('/^A$/^AA$/^AAA$/', ['foo'])

        assert_rpath('/A/AA//', ['foo'])
        assert_rpath('///AAA/', ['foo'])

        assert_rpath('/B//home/nowhere', ['nowhere'])

        assert_rpath('/B//()home/nowhere', [baz])

        assert_rpath_set('/B//()home/ere', [foo, baz])

        assert_rpath_set('/B//()home/(.*)', [foo, bar, baz],
                         [['here'], ["bar's home"], ['nowhere']])

        assert_rpath_set('/B//()home/!ere', [bar])
        assert_rpath_set('\N/B//()home/ere', [@tree[:A][:AA], foo, bar, baz]) # FIXME strange
      end

[Source]

# File lib/r_path.rb, line 310
      def test_match_data
        assert_rpath('^N(a)me', ['Foo'], [['a']])
        assert_rpath('N(a)m(e)', ['Foo', 'Bar'], [["a", "e"], ["a", "e"]])
        assert_rpath('/(.*)/(.*o.*)/(.*com.*)',
                     ["foo312@coldmail.com", "bfoo@staff.com"],
                     [["Emails", "home", "foo312@coldmail.com"],
                      ["Emails", "work", "bfoo@staff.com"]])
        assert_rpath('/users/name/Se([ax])', ["Sea", "Sex"], [["a"], ["x"]])
      end

[Source]

# File lib/r_path.rb, line 320
      def test_rpath
        assert_nothing_raised { @tree.rpath('/A/AA/AAA/') { |x|  } }
      end

[Source]

# File lib/r_path.rb, line 230
      def test_simple
        assert_rpath('Name', ['Foo', 'Bar'])
        assert_rpath('^Name', ['Foo'])
        assert_rpath('tName', ['Bar'])
        assert_rpath('Emails/home', ["foo312@coldmail.com"])
        assert_rpath('Emails/edu', ["bar.foo@school.edu"])
        assert_rpath('Name/home', [])
        assert_rpath('Phone/101', ['101'])
        assert_rpath('Phone/\d0\d', ["101", "202", "203"])
        assert_rpath('Phone/20\d', ["202", "203"])
        assert_rpath('Deep/\d', [])
        assert_rpath('Deep/A', [{"B"=>["1", 2, "a", "3"], "C"=>"4"}])
        assert_rpath('Deep/.*/\d', [])
        assert_rpath('Deep//\d', [])
        assert_rpath('Deep///\d', ['1', '2', '3', '4'])

        assert_rpath('Name/Foo', ['Foo'])
        assert_rpath('Name/Foo/Bar', [])
        assert_rpath('/E/o/com', ["foo312@coldmail.com", "bfoo@staff.com"])
        assert_rpath('//o/com', ["foo312@coldmail.com", "bfoo@staff.com"])

        assert_rpath('///Se', ["Sea", "Sex", "SeSe"])

        assert_rpath('//a/Se', ["Sea", "Sex"])
        assert_rpath('/users/name/Se[ax]', ["Sea", "Sex"])
        assert_rpath('/users/!name/', ["111", "222", "333", "222", "SeSe"])
        assert_rpath('/users/!(name|tel)/', ["SeSe"])
        assert_rpath('/!users/!(name|tel)/![S@]', ["1", "2", "a", "3", "4"])
        assert_rpath('/users//S[eu].', ["Sea", "Sex", 'Sun', 'SeSe'])
        assert_rpath('/users//S[eu].$', ["Sea", "Sex", 'Sun'])

        assert_rpath('//()a/Sea', ['name' => 'Sea', 'tel' => '111'])

        assert_rpath('//()a/Se', [{"name"=>"Sea", "tel"=>"111"},
                                  {"name"=>"Sex", "tel"=>"222"}])

        assert_rpath('//()a/()Se', [{"name"=>"Sea", "tel"=>"111"}, 'Sea',
                                  {"name"=>"Sex", "tel"=>"222"}, 'Sex'])

        assert_rpath('/()/()a/()Se', [@tree, {"name"=>"Sea", "tel"=>"111"}, 'Sea',
                                   @tree, {"name"=>"Sex", "tel"=>"222"}, 'Sex'])
        assert_rpath('Emails/!edu', ["foo312@coldmail.com", "bfoo@staff.com"])
      end

[Validate]