diff --git a/test/test_parser.rb b/test/test_parser.rb
index 4c77adf..1c57285 100644
--- a/test/test_parser.rb
+++ b/test/test_parser.rb
@@ -383,4 +383,28 @@ class TestParser < Test::Unit::TestCase
     assert (doc/"//t:sam").size > 0 # at least this should probably work
     # assert (doc/"//sam").size > 0  # this would be nice 
   end
+
+  def test_nested_id_selection
+    chunk = <<-END
+      <div id="a"><div id="c"></div></div>
+      <div id="b"></div>
+    END
+    doc = Hpricot(chunk)
+    assert_equal 1, (doc / '#a #c').length
+    assert_equal 0, (doc / '#a #b').length
+    assert_equal 0, (doc / '#c #b').length
+    assert_equal 0, (doc / '#b #a').length
+  end
+
+  def test_id_selection_within_elements
+    chunk = <<-END
+      <div id="a"><div id="c"></div></div>
+      <div id="b"></div>
+    END
+    doc = Hpricot(chunk)
+    assert_equal 1, (doc / '#a' / '#c').length
+    assert_equal 0, (doc / '#a' / '#b').length
+    assert_equal 0, (doc / '#c' / '#b').length
+    assert_equal 0, (doc / '#b' / '#a').length
+  end
 end
