示例#1
0
 def test_completion(self):
     spinner = AsyncSpinner(self, callback=partial(setattr, self, "trg"))
     with spinner:
         self.buf.trg_from_pos(self.positions[1], True, spinner)
     self.assertIsNotNone(self.trg)
     self.assertEqual(self.trg.form, TRG_FORM_CPLN)
     # don't really care about the rest of the internals of the trigger
     # as long as it actually works...
     spinner = AsyncSpinner(self)
     with spinner:
         handler = UIHandler(spinner)
         self.buf.async_eval_at_trg(self.trg, handler,
                                    Ci.koICodeIntelBuffer.EVAL_SILENT)
     self.assertIn(UIHandler.AutoCompleteInfo("sys", "module"),
                   handler.completions)
示例#2
0
 def test_calltip(self):
     spinner = AsyncSpinner(self, callback=partial(setattr, self, "trg"))
     with spinner:
         self.buf.preceding_trg_from_pos(self.positions[2],
                                         self.positions[3], spinner)
     self.assertIsNotNone(self.trg)
     self.assertEqual(self.trg.form, TRG_FORM_CALLTIP)
     spinner = AsyncSpinner(self)
     with spinner:
         handler = UIHandler(spinner)
         self.buf.async_eval_at_trg(self.trg, handler,
                                    Ci.koICodeIntelBuffer.EVAL_SILENT)
     calltip, calltip_pos = unmark_text(dedent("""
         pformat(object, <1>indent=1<2>, width=80, depth=None)
         Format a Python object into a pretty-printed representation.
         """).strip())
     self.assertEqual(handler.calltip, calltip)
     with spinner:
         positions = []
         def callback(start, end):
             positions[:] = [start, end]
         spinner.callback = callback
         self.buf.get_calltip_arg_range(self.trg.pos,
                                        calltip,
                                        self.positions[3],
                                        spinner)
     self.assertEquals(positions, [calltip_pos[1], calltip_pos[2]],
                       "Unexpected calltip range positions; should cover "
                       "second argument")
示例#3
0
 def test_unicode_in_defn(self):
     self.doc.buffer, self.positions = unmark_text(dedent(u"""
         #Ůɳíčóďé<3>
         my $pCnt = 0;<1>
         # Some filler text to make sure we do not accidentally find the
         # previous definition
         $p<2>Cnt++;
         """).strip())
     self.assertGreater(self.positions[3], len("#Unicode"),
                        "Unicode positions are character positions "
                        "instead of byte positions")
     spinner = AsyncSpinner(self, callback=partial(setattr, self, "trg"))
     with spinner:
         self.buf.defn_trg_from_pos(self.positions[2], spinner)
     self.assertIsNotNone(self.trg)
     self.assertEqual(self.trg.form, TRG_FORM_DEFN)
     handler = UIHandler(spinner)
     with spinner:
         spinner.callback = None
         self.buf.async_eval_at_trg(self.trg, handler,
                                    Ci.koICodeIntelBuffer.EVAL_SILENT)
     self.assertEqual(len(handler.defns), 1)
     self.assertEqual(handler.defns[0].lang, "Perl")
     self.assertEqual(handler.defns[0].name, "$pCnt")
     self.assertEqual([handler.defns[0].line],
                      lines_from_pos(self.doc.buffer, [self.positions[1]]))
     self.assertEqual(handler.defns[0].ilk, "variable")
示例#4
0
 def assertCompletionsDoNotInclude(self,
                                   markedup_content,
                                   completions,
                                   implicit=True):
     """Check that the given completions are NOT found
     @param markedup_content Content with a <|> marking
     @param completions List of expected completions; each item is a tuple of
         (type, completion string)
     @param implicit Whether the trigger should be implicit
     """
     actual_completions = self._doEval(markedup_content,
                                       implicit=implicit).completions
     extra_completions = set()
     for typ, cpln in completions:
         if UIHandler.AutoCompleteInfo(cpln, typ) in actual_completions:
             extra_completions.add((typ, cpln))
     self.failIf(
         extra_completions and True,
         "%s completions at the given position included "
         "some unexpected values\n"
         "  shouldn't have had these: %r\n"
         "  expected none of:         %r\n"
         "  got:                      %r\n"
         "  buffer:\n%s" %
         (self.language, list(extra_completions), completions, [
             (cpln.type, cpln.completion) for cpln in actual_completions
         ], indent(markedup_content)))
示例#5
0
 def assertCompletionsInclude(self,
                              markedup_content,
                              completions,
                              implicit=True):
     """Check that the given completions are found
     @param markedup_content Content with a <|> marking
     @param completions List of expected completions; each item is a tuple of
         (type, completion string)
     @param implicit Whether the trigger should be implicit
     """
     actual_completions = self._doEval(markedup_content,
                                       implicit=implicit).completions
     missing_completions = set()
     for typ, cpln in completions:
         if UIHandler.AutoCompleteInfo(cpln, typ) not in actual_completions:
             missing_completions.add((typ, cpln))
     self.failIf(
         missing_completions and True,
         "%s completions at the given position did not "
         "include all expected values\n"
         "  missing:         %r\n"
         "  expected all of: %r\n"
         "  got:             %r\n"
         "  buffer:\n%s" %
         (self.language, list(missing_completions), completions, [
             (cpln.type, cpln.completion) for cpln in actual_completions
         ], indent(markedup_content)))
示例#6
0
 def _doEval(self, markedup_content, lang=None, implicit=True):
     self.doc.buffer, self.positions = unmark_text(
         dedent(markedup_content).strip())
     spinner = AsyncSpinner(self, callback=partial(setattr, self, "trg"))
     with spinner:
         self.buf.trg_from_pos(self.positions["pos"], implicit, spinner)
     self.assertIsNotNone(self.trg)
     # don't really care about the rest of the internals of the trigger
     # as long as it actually works...
     spinner = AsyncSpinner(self)
     with spinner:
         handler = UIHandler(spinner)
         self.buf.async_eval_at_trg(self.trg, handler,
                                    Ci.koICodeIntelBuffer.EVAL_SILENT)
     return handler
示例#7
0
 def test_completion_stale(self):
     """Test that we ignore stale triggers"""
     spinner = AsyncSpinner(self, callback=partial(setattr, self, "trg"))
     with spinner:
         self.buf.trg_from_pos(self.positions[1], True, spinner)
     self.assertIsNotNone(self.trg)
     self.assertEqual(self.trg.form, TRG_FORM_CPLN)
     self.doc.buffer += "\n#Modified buffer"
     # don't really care about the rest of the internals of the trigger
     # as long as it actually works...
     spinner = AsyncSpinner(self, timeout=None)
     with spinner:
         handler = UIHandler(spinner)
         self.buf.async_eval_at_trg(self.trg, handler,
                                    Ci.koICodeIntelBuffer.EVAL_SILENT)
     self.assertEquals(handler.completions, [])
示例#8
0
 def test_defn(self):
     spinner = AsyncSpinner(self, callback=partial(setattr, self, "trg"))
     with spinner:
         self.buf.defn_trg_from_pos(self.positions[3], spinner)
     self.assertIsNotNone(self.trg)
     self.assertEqual(self.trg.form, TRG_FORM_DEFN)
     handler = UIHandler(spinner)
     with spinner:
         spinner.callback = None
         self.buf.async_eval_at_trg(self.trg, handler,
                                    Ci.koICodeIntelBuffer.EVAL_SILENT)
     self.assertEqual(len(handler.defns), 1)
     self.assertEqual(handler.defns[0].lang, "Python")
     self.assertEqual(handler.defns[0].name, "indent")
     self.assertEqual([handler.defns[0].line],
                      lines_from_pos(self.doc.buffer, [self.positions[5]]))
     self.assertEqual(handler.defns[0].ilk, "variable")