コード例 #1
0
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))
コード例 #2
0
ファイル: vim_adaptor.py プロジェクト: actionshrimp/vim-xpath
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))
コード例 #3
0
    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"])
コード例 #4
0
    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)
コード例 #5
0
    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"])
コード例 #6
0
    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"])
コード例 #7
0
    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"])
コード例 #8
0
    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)
コード例 #9
0
    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"])
コード例 #10
0
    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"])