def guess_prefixes(bufnr): try: xml = get_buffer_string(bufnr) prefixes = g.guess_prefixes(xml) outstr = "let l:ns_prefixes = {" for prefix in prefixes: outstr += '"{0}": "{1}",'.format(prefix, prefixes[prefix]) outstr += "}" vim.command(outstr) except Exception as e: vim.command('throw "{0}"'.format(e.msg))
def test_single_namespace_prefix_is_guessed(self): xml = read_sample_xml("single_namespace.xml") prefixes = namespace_prefix_guesser.guess_prefixes(xml) self.assertEqual("http://onlyPrefix.com", prefixes["onlyPrefix"])
def test_malformed_xml_throws_error(self): xml = read_sample_xml("malformed.xml") with self.assertRaises(namespace_prefix_guesser.PrefixGuessingError): prefixes = namespace_prefix_guesser.guess_prefixes(xml)
def test_first_node_depth_first_to_define_prefix_claims_it(self): xml = read_sample_xml("reused_namespace.xml") prefixes = namespace_prefix_guesser.guess_prefixes(xml) self.assertEqual("http://thirdurl.org", prefixes["another"])
def test_default_namespace_is_called_default(self): xml = read_sample_xml("namespaces.xml") prefixes = namespace_prefix_guesser.guess_prefixes(xml) self.assertEqual("http://someurl.org", prefixes["default"]) self.assertEqual("http://anotherurl.org", prefixes["ns"])