Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nokogiri::XML::Node#line= #1918

Merged
merged 1 commit into from Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions ext/nokogiri/xml_node.c
Expand Up @@ -1332,6 +1332,25 @@ static VALUE line(VALUE self)
return INT2NUM(xmlGetLineNo(node));
}

/*
* call-seq:
* line=(num)
*
* Sets the line for this Node. num must be less than 65535.
*/
static VALUE set_line(VALUE self, VALUE num)
{
xmlNodePtr node;
Data_Get_Struct(self, xmlNode, node);

int value = NUM2INT(num);
if (value < 65535) {
node->line = value;
}

return num;
}

/*
* call-seq:
* add_namespace_definition(prefix, href)
Expand Down Expand Up @@ -1728,6 +1747,7 @@ void init_xml_node()
rb_define_method(klass, "create_external_subset", create_external_subset, 3);
rb_define_method(klass, "pointer_id", pointer_id, 0);
rb_define_method(klass, "line", line, 0);
rb_define_method(klass, "line=", set_line, 1);
rb_define_method(klass, "content", get_native_content, 0);
rb_define_method(klass, "native_content=", set_native_content, 1);
rb_define_method(klass, "lang", get_lang, 0);
Expand Down
8 changes: 8 additions & 0 deletions test/xml/test_node.rb
Expand Up @@ -1222,6 +1222,14 @@ def test_line
assert_equal 2, node.line
end

def test_set_line
skip "Only supported with libxml2" unless Nokogiri.uses_libxml?
document = Nokogiri::XML::Document.new
node = document.create_element('a')
node.line = 54321
assert_equal 54321, node.line
end

def test_xpath_results_have_document_and_are_decorated
x = Module.new do
def awesome! ; end
Expand Down