diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb
index 657df79..53dc2ad 100644
--- a/lib/oga/xpath/evaluator.rb
+++ b/lib/oga/xpath/evaluator.rb
@@ -457,6 +457,23 @@ module Oga
return nodes
end
+ ##
+ # Processes the `text()` type test. This matches only text nodes.
+ #
+ # @param [Oga::XPath::Node] ast_node
+ # @param [Oga::XML::NodeSet] context
+ # @return [Oga::XML::NodeSet]
+ #
+ def on_type_test_text(ast_node, context)
+ nodes = XML::NodeSet.new
+
+ context.each do |node|
+ nodes << node if node.is_a?(XML::Text)
+ end
+
+ return nodes
+ end
+
##
# Returns a node set containing all the child nodes of the given set of
# nodes.
diff --git a/spec/oga/xpath/evaluator/type_tests/node_spec.rb b/spec/oga/xpath/evaluator/type_tests/node_spec.rb
index 79e912c..180caaf 100644
--- a/spec/oga/xpath/evaluator/type_tests/node_spec.rb
+++ b/spec/oga/xpath/evaluator/type_tests/node_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Oga::XPath::Evaluator do
- context 'node type test' do
+ context 'node() tests' do
before do
@document = parse('foo')
@evaluator = described_class.new(@document)
diff --git a/spec/oga/xpath/evaluator/type_tests/text_spec.rb b/spec/oga/xpath/evaluator/type_tests/text_spec.rb
new file mode 100644
index 0000000..40825f7
--- /dev/null
+++ b/spec/oga/xpath/evaluator/type_tests/text_spec.rb
@@ -0,0 +1,42 @@
+require 'spec_helper'
+
+describe Oga::XPath::Evaluator do
+ context 'text() tests' do
+ before do
+ @document = parse('foobar')
+ @evaluator = described_class.new(@document)
+ end
+
+ context 'matching text nodes' do
+ before do
+ @set = @evaluator.evaluate('a/text()')
+ end
+
+ it_behaves_like :node_set, :length => 1
+
+ example 'return a Text instance' do
+ @set[0].is_a?(Oga::XML::Text).should == true
+ end
+
+ example 'return the "foo" text node' do
+ @set[0].text.should == 'foo'
+ end
+ end
+
+ context 'matching nested text nodes' do
+ before do
+ @set = @evaluator.evaluate('a/b/text()')
+ end
+
+ it_behaves_like :node_set, :length => 1
+
+ example 'return a Text instance' do
+ @set[0].is_a?(Oga::XML::Text).should == true
+ end
+
+ example 'return the "bar" text node' do
+ @set[0].text.should == 'bar'
+ end
+ end
+ end
+end