Ticket #155: nested-id-selection-fails.patch

File nested-id-selection-fails.patch, 1.0 kB (added by philodespotos, 4 months ago)
  • test/test_parser.rb

    diff --git a/test/test_parser.rb b/test/test_parser.rb
    index 4c77adf..1c57285 100644
    a b  
    383383    assert (doc/"//t:sam").size > 0 # at least this should probably work 
    384384    # assert (doc/"//sam").size > 0  # this would be nice  
    385385  end 
     386 
     387  def test_nested_id_selection 
     388    chunk = <<-END 
     389      <div id="a"><div id="c"></div></div> 
     390      <div id="b"></div> 
     391    END 
     392    doc = Hpricot(chunk) 
     393    assert_equal 1, (doc / '#a #c').length 
     394    assert_equal 0, (doc / '#a #b').length 
     395    assert_equal 0, (doc / '#c #b').length 
     396    assert_equal 0, (doc / '#b #a').length 
     397  end 
     398 
     399  def test_id_selection_within_elements 
     400    chunk = <<-END 
     401      <div id="a"><div id="c"></div></div> 
     402      <div id="b"></div> 
     403    END 
     404    doc = Hpricot(chunk) 
     405    assert_equal 1, (doc / '#a' / '#c').length 
     406    assert_equal 0, (doc / '#a' / '#b').length 
     407    assert_equal 0, (doc / '#c' / '#b').length 
     408    assert_equal 0, (doc / '#b' / '#a').length 
     409  end 
    386410end