Beispiel #1
0
    def test_xpath_evaluation(self):
        test_xml = "<Root>\n<Tag/>\n<Tag/>\n</Root>"
        self.stub_vim_buffer(0, test_xml)
        a.evaluate_xpath(1, 0, "//Tag")
        self.assertEqual("setloclist(0, [], 'r')", VimModuleStub.evaluated[0])

        self.assertEqual("setloclist(0, [{" +
                         "'bufnr': 1, " +
                         "'text': \"Results for: " + 
                         "//Tag\"" +
                         "}], 'a')",
                         VimModuleStub.evaluated[1])
        
        self.assertEqual("setloclist(0, [{" +
                         "'bufnr': 1, " +
                         "'lnum': 2, " +
                         "'text': \"<Tag>\", " +
                         "}], 'a')",
                         VimModuleStub.evaluated[2])
        
        self.assertEqual("setloclist(0, [{" +
                         "'bufnr': 1, " +
                         "'lnum': 3, " +
                         "'text': \"<Tag>\", " +
                         "}], 'a')",
                         VimModuleStub.evaluated[3])
Beispiel #2
0
    def test_xpath_which_doesnt_return_a_line_number(self):
        text_xml = "<Root><Tag/></Root>"
        self.stub_vim_buffer(0, text_xml)

        a.evaluate_xpath(1, 0, "'test string'")

        self.assertEqual(
            "setloclist(0, [{" + "'bufnr': 1, " +
            "'text': \"string: test string\", " + "}], 'a')",
            VimModuleStub.evaluated[2])
    def test_xpath_which_doesnt_return_a_line_number(self):
        text_xml = "<Root><Tag/></Root>"
        self.stub_vim_buffer(0, text_xml)

        a.evaluate_xpath(0, 0, "'test string'")

        self.assertEqual("setloclist(0, [{" +
                         "'bufnr': 0, " +
                         "'text': 'string: test string', " +
                         "}], 'a')",
                         VimModuleStub.evaluated[1])
Beispiel #4
0
    def test_xpath_with_undefined_namespace_errors(self):
        test_xml = "<Root xmlns:ns='test.org'><ns:Tag/></Root>"
        self.stub_vim_buffer(0, test_xml)

        a.evaluate_xpath(1, 0, '//vimns:Tag')

        self.assertEqual(
            "setloclist(0, [{" + "'bufnr': 1, " + "'type': 'E', " +
            "'text': \"XPath evaluation error: " +
            "undefined namespace prefix\"" + "}], 'a')",
            VimModuleStub.evaluated[2])
    def test_xpath_with_undefined_namespace_errors(self):
        test_xml = "<Root xmlns:ns='test.org'><ns:Tag/></Root>"
        self.stub_vim_buffer(0, test_xml)

        a.evaluate_xpath(0, 0, '//vimns:Tag')

        self.assertEqual("setloclist(0, [{" +
                         "'bufnr': 0, " +
                         "'type': 'E', " +
                         "'text': 'XPath evaluation error: " + 
                         "undefined namespace prefix'" +
                         "}], 'a')",
                         VimModuleStub.evaluated[1])
Beispiel #6
0
    def test_escaping_in_evaluation_result(self):
        test_xml = "<Root><Tag>With apo's in result</Tag>"
        test_xml += "<Tag>\"and some quotes\"</Tag></Root>"
        self.stub_vim_buffer(0, test_xml)

        a.evaluate_xpath(1, 0, "//Tag")

        self.assertEqual(
            "setloclist(0, [{" + "'bufnr': 1, " + "'lnum': 1, " +
            "'text': \"<Tag>: With apo's in result\", " + "}], 'a')",
            VimModuleStub.evaluated[2])

        self.assertEqual(
            "setloclist(0, [{" + "'bufnr': 1, " + "'lnum': 1, " +
            "'text': \"<Tag>: \\\"and some quotes\\\"\", " + "}], 'a')",
            VimModuleStub.evaluated[3])
Beispiel #7
0
    def test_xpath_evaluation(self):
        test_xml = "<Root>\n<Tag/>\n<Tag/>\n</Root>"
        self.stub_vim_buffer(0, test_xml)
        a.evaluate_xpath(1, 0, "//Tag")
        self.assertEqual("setloclist(0, [], 'r')", VimModuleStub.evaluated[0])

        self.assertEqual(
            "setloclist(0, [{" + "'bufnr': 1, " + "'text': \"Results for: " +
            "//Tag\"" + "}], 'a')", VimModuleStub.evaluated[1])

        self.assertEqual(
            "setloclist(0, [{" + "'bufnr': 1, " + "'lnum': 2, " +
            "'text': \"<Tag>\", " + "}], 'a')", VimModuleStub.evaluated[2])

        self.assertEqual(
            "setloclist(0, [{" + "'bufnr': 1, " + "'lnum': 3, " +
            "'text': \"<Tag>\", " + "}], 'a')", VimModuleStub.evaluated[3])
Beispiel #8
0
    def test_escaping_in_evaluation_result(self):
        test_xml = "<Root><Tag>With apo's in result</Tag>"
        test_xml += "<Tag>\"and some quotes\"</Tag></Root>"
        self.stub_vim_buffer(0, test_xml)

        a.evaluate_xpath(1, 0, "//Tag")

        self.assertEqual("setloclist(0, [{" +
                         "'bufnr': 1, " +
                         "'lnum': 1, " +
                         "'text': \"<Tag>: With apo's in result\", " +
                         "}], 'a')",
                         VimModuleStub.evaluated[2])

        self.assertEqual("setloclist(0, [{" +
                         "'bufnr': 1, " +
                         "'lnum': 1, " +
                         "'text': \"<Tag>: \\\"and some quotes\\\"\", " +
                         "}], 'a')",
                         VimModuleStub.evaluated[3])
 def test_empty_buffer(self):
     self.stub_vim_buffer(0, "")
     a.evaluate_xpath(0, 0, "//*")
Beispiel #10
0
 def test_empty_buffer(self):
     self.stub_vim_buffer(0, "")
     a.evaluate_xpath(1, 0, "//*")