def test_cpln_variable(self): content, positions = unmark_text( dedent("""\ @nice-blue: #5B83AD; @light-blue: @<1>nice-blue + #111; #header { @nested-color: white; color: @<2>light-blue; } #footer { color: @<3> } @<4> """)) self.assertCompletionsAre(markup_text(content, pos=positions[1]), [("variable", "light-blue"), ("variable", "nice-blue")]) self.assertCompletionsAre(markup_text(content, pos=positions[2]), [("variable", "light-blue"), ("variable", "nested-color"), ("variable", "nice-blue")]) self.assertCompletionsAre(markup_text(content, pos=positions[3]), [("variable", "light-blue"), ("variable", "nice-blue")]) self.assertCompletionsDoNotInclude( markup_text(content, pos=positions[4]), [("variable", "light-blue"), ("variable", "nice-blue")])
def test_complete_property_values_complex2(self): # completions for complex style of propery-values name = "css-complete-property-values" # XXX - Talk to Eric #content, positions = unmark_text(dedent("""\ # <p style=" # background: <1>url('../img/header <2>tab.gif') /* <3>comment: <4>'abc <5>xyz' <6>*/ <7>600px <8>no-r; # " /> #""")) content, positions = unmark_text( dedent("""\ <p style=" background: <1> /* <3>comment: <4>'abc <5>xyz' <6>*/ <7>600px <8>no-r; " /> """)) values = set(CSS_ATTR_DICT['background']) for i in (1, 7, 8): self.assertTriggerMatches(markup_text(content, pos=positions[i]), name=name) # Remove these values, as they are already in the property list v = values.copy() if i == 7 or i == 8: v.discard('url(') self.assertCompletionsInclude( markup_text(content, pos=positions[i]), [("value", x) for x in v]) for i in range(3, 7): self.assertTriggerDoesNotMatch(markup_text(content, pos=positions[i]), name=name)
def test_no_completions(self): content, positions = unmark_text(dedent("""\ <div id="<1>"> <div class="<2>"> """)) self.assertCompletionsAre(markup_text(content, pos=positions[1]), None) self.assertCompletionsAre(markup_text(content, pos=positions[2]), None)
def test_complete_property_values_complex2(self): # completions for complex style of propery-values name = "css-complete-property-values" # XXX - Talk to Eric # content, positions = unmark_text(dedent("""\ # <p style=" # background: <1>url('../img/header <2>tab.gif') /* <3>comment: <4>'abc <5>xyz' <6>*/ <7>600px <8>no-r; # " /> #""")) content, positions = unmark_text(dedent("""\ <p style=" background: <1> /* <3>comment: <4>'abc <5>xyz' <6>*/ <7>600px <8>no-r; " /> """)) values = set(CSS_ATTR_DICT['background']) for i in (1, 7, 8): self.assertTriggerMatches(markup_text(content, pos=positions[i]), name=name) # Remove these values, as they are already in the property list v = values.copy() if i == 7 or i == 8: v.discard('url(') self.assertCompletionsInclude( markup_text(content, pos=positions[i]), [("value", x) for x in v]) for i in range(3, 7): self.assertTriggerDoesNotMatch( markup_text(content, pos=positions[i]), name=name)
def test_cpln_variable(self): content, positions = unmark_text(dedent("""\ @nice-blue: #5B83AD; @light-blue: @<1>nice-blue + #111; #header { @nested-color: white; color: @<2>light-blue; } #footer { color: @<3> } @<4> """)) self.assertCompletionsAre(markup_text(content, pos=positions[1]), [("variable", "light-blue"), ("variable", "nice-blue")]) self.assertCompletionsAre(markup_text(content, pos=positions[2]), [("variable", "light-blue"), ("variable", "nested-color"), ("variable", "nice-blue")]) self.assertCompletionsAre(markup_text(content, pos=positions[3]), [("variable", "light-blue"), ("variable", "nice-blue")]) self.assertCompletionsDoNotInclude(markup_text(content, pos=positions[4]), [("variable", "light-blue"), ("variable", "nice-blue")])
def test_cpln_variable(self): content, positions = unmark_text(dedent("""\ $font-stack: Helvetica, sans-serif; $primary-color: #333; body { font: 100% $<1>font-stack; color: $<2>primary-color; } #main { $width: 5em; width: $<3>width; } #sidebar { width: $<4>; } """)) for i in range(1, 2): self.assertCompletionsAre(markup_text(content, pos=positions[i]), [("variable", "font-stack"), ("variable", "primary-color")]) self.assertCompletionsAre(markup_text(content, pos=positions[3]), [("variable", "font-stack"), ("variable", "primary-color"), ("variable", "width")]) self.assertCompletionsAre(markup_text(content, pos=positions[4]), [("variable", "font-stack"), ("variable", "primary-color")])
def test_cpln_variable(self): content, positions = unmark_text( dedent("""\ $font-stack: Helvetica, sans-serif; $primary-color: #333; body { font: 100% $<1>font-stack; color: $<2>primary-color; } #main { $width: 5em; width: $<3>width; } #sidebar { width: $<4>; } """)) for i in xrange(1, 2): self.assertCompletionsAre(markup_text(content, pos=positions[i]), [("variable", "font-stack"), ("variable", "primary-color")]) self.assertCompletionsAre(markup_text(content, pos=positions[3]), [("variable", "font-stack"), ("variable", "primary-color"), ("variable", "width")]) self.assertCompletionsAre(markup_text(content, pos=positions[4]), [("variable", "font-stack"), ("variable", "primary-color")])
def test_no_completions(self): content, positions = unmark_text( dedent("""\ <div id="<1>"> <div class="<2>"> """)) self.assertCompletionsAre(markup_text(content, pos=positions[1]), None) self.assertCompletionsAre(markup_text(content, pos=positions[2]), None)
def test_string_literals(self): content, positions = unmark_text(dedent(""" literal = "hello" literal.<1>e """)) self.assertCompletionsInclude(markup_text(content, positions[1]), [("function", "encode")]) self.assertCompletionsDoNotInclude(markup_text(content, positions[1]), [("function", "decode")])
def test_string_literals(self): content, positions = unmark_text( dedent(""" literal = "hello" literal.<1>e """)) self.assertCompletionsInclude(markup_text(content, positions[1]), [("function", "encode")]) self.assertCompletionsDoNotInclude(markup_text(content, positions[1]), [("function", "decode")])
def test_pseudo_retrigger(self): content, positions = unmark_text(dedent(""" .cursor font-weight: bold .cursor:<1>h<2>ov """)) pseudo_results = [("pseudo-class", s) for s in ("active", "visited", "link", "hover", "first-child")] self.assertCompletionsInclude(markup_text(content, pos=positions[1]), pseudo_results) self.assertNoTrigger(markup_text(content, pos=positions[2]))
def test_xpcom_classes_array_cplns(self): content, positions = unmark_text(dedent("""\ var observerCls = Components.classes["<1>@mozilla.org/observer-service;1"]; observerCls.<2>; """)) self.assertCompletionsInclude(markup_text(content, pos=positions[1]), [("variable", "@mozilla.org/observer-service;1"), ("variable", "@mozilla.org/embedcomp/prompt-service;1")]) self.assertCompletionsInclude(markup_text(content, pos=positions[2]), [("function", "getService"), ("function", "createInstance")])
def test_xpcom_classes_array_cplns(self): content, positions = unmark_text( dedent("""\ var observerCls = Components.classes["<1>@mozilla.org/observer-service;1"]; observerCls.<2>; """)) self.assertCompletionsInclude( markup_text(content, pos=positions[1]), [("variable", "@mozilla.org/observer-service;1"), ("variable", "@mozilla.org/embedcomp/prompt-service;1")]) self.assertCompletionsInclude(markup_text(content, pos=positions[2]), [("function", "getService"), ("function", "createInstance")])
def test_buffer_overrun(self): content, positions = unmark_text(dedent("""\ /* 101 'a's in the next line: */ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa <body> { background: <1>transparent <2>url('../img/header_tab.gif') <3>100% <4>-600px <5>no-repeat; font-family: <6>'Lucida Grande', <7>Verdana, <8>sans-serif; float: <9>left; } """)) name = "css-complete-property-values" self.assertTriggerMatches(markup_text(content, pos=positions[1]), name=name) self.assertCompletionsInclude(markup_text(content, pos=positions[2]), (('value', 'repeat-x'),))
def assertNoDuplicateDefns2(self, buf, pos): markedup_content = markup_text(buf.accessor.text, pos=pos) ctlr = _CaptureEvalController() trg = buf.defn_trg_from_pos(pos) actual_defns = buf.defns_from_trg(trg, ctlr=ctlr) if not actual_defns: self.fail("%s trigger resulted in no definitions when expecting " "to check for duplicate definitions:\n%s" % (buf.lang, indent(markedup_content))) count_from_defn_repr = {} for defn_repr in (repr(d) for d in actual_defns): if defn_repr not in count_from_defn_repr: count_from_defn_repr[defn_repr] = 0 count_from_defn_repr[defn_repr] += 1 defn_dupes = [(count, defn_repr) for defn_repr, count in count_from_defn_repr.items() if count > 1] self.failIf(defn_dupes, "unexpectedly got duplicate completions at the given position\n" " duplicates:\n%s\n" " eval log\n%s\n" " buffer:\n%s" % (indent('\n'.join('%d of %s' % d for d in defn_dupes)), indent('\n'.join('%5s: %s' % ( lvl, m) for lvl, m in ctlr.log)), indent(markedup_content)))
def test_railsenv_views_basic_realistic(self): test_dir = join(self.test_dir, "railsapp01", "app", "views", "layouts") main_filename = "add.rhtml" main_content, main_positions = \ unmark_text(self.adjust_content(dedent("""\ # Contrived: most layouts are implicit members of this class h = Act<1>ionView::<2>Base for<3>m_for "whatever".<4>pluralize """))) main_path = join(test_dir, main_filename) writefile(main_path, main_content) main_buf = self.mgr.buf_from_path(main_path) targets = [[ ("namespace", "ActionView"), ("namespace", "ActiveRecord"), ("namespace", "ActionController"), ], [ ("class", "Base"), ], [ ("function", "form_for"), ], [ ("function", "pluralize"), ]] for i in range(len(targets)): self.assertCompletionsInclude2(main_buf, main_positions[i + 1], targets[i]) ## Verify we don't get false hits self.assertCompletionsDoNotInclude( markup_text(main_content, pos=main_positions[i + 1]), targets[i])
def assertCompletionsAre2(self, buf, pos, completions, lang=None, implicit=True, env=None): if lang is None: lang = self.lang markedup_content = markup_text(buf.accessor.text, pos=pos) trg = buf.trg_from_pos(pos, implicit=implicit) self._assertCompletionsAre( markedup_content, buf, trg, completions, lang, implicit)
def test_ellipsis_literal(self): content, positions = unmark_text(dedent(""" var = ... "string".<1>e """)) self.assertCompletionsInclude(markup_text(content, positions[1]), [("function", "encode")])
def test_iterable_unpacking(self): content, positions = unmark_text(dedent(""" (a, *rest, b) = [1, 2, 3, 4] rest.<1>i """)) self.assertCompletionsInclude(markup_text(content, positions[1]), [("function", "insert")])
def assertNoDuplicateDefns2(self, buf, pos): markedup_content = markup_text(buf.accessor.text, pos=pos) ctlr = _CaptureEvalController() trg = buf.defn_trg_from_pos(pos) actual_defns = buf.defns_from_trg(trg, ctlr=ctlr) if not actual_defns: self.fail("%s trigger resulted in no definitions when expecting " "to check for duplicate definitions:\n%s" % (buf.lang, indent(markedup_content))) count_from_defn_repr = {} for defn_repr in (repr(d) for d in actual_defns): if defn_repr not in count_from_defn_repr: count_from_defn_repr[defn_repr] = 0 count_from_defn_repr[defn_repr] += 1 defn_dupes = [(count, defn_repr) for defn_repr, count in count_from_defn_repr.items() if count > 1] self.failIf( defn_dupes, "unexpectedly got duplicate completions at the given position\n" " duplicates:\n%s\n" " eval log\n%s\n" " buffer:\n%s" % (indent('\n'.join('%d of %s' % d for d in defn_dupes)), indent('\n'.join('%5s: %s' % (lvl, m) for lvl, m in ctlr.log)), indent(markedup_content)))
def test_buffer_overrun(self): content, positions = unmark_text( dedent("""\ /* 101 'a's in the next line: */ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa <body> { background: <1>transparent <2>url('../img/header_tab.gif') <3>100% <4>-600px <5>no-repeat; font-family: <6>'Lucida Grande', <7>Verdana, <8>sans-serif; float: <9>left; } """)) name = "css-complete-property-values" self.assertTriggerMatches(markup_text(content, pos=positions[1]), name=name) self.assertCompletionsInclude(markup_text(content, pos=positions[2]), (('value', 'repeat-x'), ))
def test_railsenv_views_basic_realistic(self): test_dir = join(self.test_dir, "railsapp01", "app", "views", "layouts") main_filename = "add.rhtml" main_content, main_positions = \ unmark_text(self.adjust_content(dedent("""\ # Contrived: most layouts are implicit members of this class h = Act<1>ionView::<2>Base for<3>m_for "whatever".<4>pluralize """))) main_path = join(test_dir, main_filename) writefile(main_path, main_content) main_buf = self.mgr.buf_from_path(main_path) targets = [ [("namespace", "ActionView"), ("namespace", "ActiveRecord"), ("namespace", "ActionController"), ], [("class", "Base"), ], [("function", "form_for"), ], [("function", "pluralize"), ] ] for i in range(len(targets)): self.assertCompletionsInclude2(main_buf, main_positions[i + 1], targets[i]) ## Verify we don't get false hits self.assertCompletionsDoNotInclude(markup_text(main_content, pos=main_positions[ i + 1]), targets[i])
def test_railsenv_controller_basic(self): test_dir = join(self.test_dir, "railsapp01", "app", "controllers") main_filename = "admin_controller.rb" main_content, main_positions = \ unmark_text(self.adjust_content(dedent("""\ class ApplicationController < ActionController::<1>Base ApplicationController.<2>after_filter :check_authentication, :except => [:signin] def signin self.<3>render(:layout, "sheep".<4>pluralize) end end """))) main_path = join(test_dir, main_filename) writefile(main_path, main_content) main_buf = self.mgr.buf_from_path(main_path) targets = [[("class", "Base"), ], [("function", "after_filter"), ], [("function", "render"), ], [("function", "pluralize"), ], ] for i in range(len(targets)): self.assertCompletionsInclude2(main_buf, main_positions[i + 1], targets[i]) ## Verify we don't get false hits self.assertCompletionsDoNotInclude(markup_text(main_content, pos=main_positions[ i + 1]), targets[i])
def test_rhtml_calltips(self): test_dir = join(self.test_dir, "railsapp01", "app", "views", "admin") main_filename = "list.rhtml" main_markup = dedent("""\ <h1>Listing titles</h1> <table> <% for title in @titles %> <tr> <td align='left'><%= link_to(<1> 'Show', :action => 'show', :id => title) %> <td align='left'><%= link_to_if <2>'Show', :action => 'show', :id => title) %> <td align='left'><%= <$>link<3> %> </td></tr></table> """) main_content, main_positions = unmark_text(main_markup) main_path = join(test_dir, main_filename) writefile(main_path, main_content) main_buf = self.mgr.buf_from_path(main_path) ''' self.assertCalltipIs2(main_buf, main_positions[1], dedent("""\ (name, options = {}, html_options = nil, *parameters_for_method_reference)""")) ''' self.assertCalltipIs2(main_buf, main_positions[2], dedent("""\ (condition, name, options = {}, html_options = {}, *parameters_for_method_reference, &block) Creates a link tag of the given name</tt> using a URL created by the set of <tt>options</tt> if <tt>condition is true, in which case only the name is returned. To specialize the default behavior, you can pass a block that accepts the name or the full argument list for link_to_unless (see the examples in link_to_unless).""")) self.assertNoPrecedingTrigger(markup_text(main_content, start_pos=main_positions[ 'start_pos'], pos=main_positions[3]))
def test_open(self): content, positions = unmark_text(dedent(""" f = open("/dev/null", "w") f.<1>w """)) self.assertCompletionsInclude(markup_text(content, positions[1]), [("function", "write")])
def test_railsenv_model_basic(self): test_dir = join(self.test_dir, "railsapp01", "app", "models") main_filename = "cart1.rb" main_content, main_positions = \ unmark_text(self.adjust_content(dedent("""\ class Cart < ActiveRecord::<1>Base Cart.<2>acts_as_list def octopus self.<3>insert_at(0) i = 4 print "you owe #{i.<4>gigabyte} dollars" end end """))) main_path = join(test_dir, main_filename) writefile(main_path, main_content) main_buf = self.mgr.buf_from_path(main_path) targets = [[("class", "Base"), ], [("function", "acts_as_list"), ], [("function", "insert_at"), ], [("function", "megabyte"), ], ] for i in range(len(targets)): self.assertCompletionsInclude2(main_buf, main_positions[i + 1], targets[i]) ## Verify we don't get false hits self.assertCompletionsDoNotInclude(markup_text(main_content, pos=main_positions[ i + 1]), targets[i])
def test_railsenv_views_basic_html_erb_suffix(self): test_dir = join(self.test_dir, "railsapp01", "app", "views", "layouts") main_filename = "add.html.erb" main_content, main_positions = \ unmark_text(self.adjust_content(dedent("""\ # Contrived: most layouts are implicit members of this class class Zoomoo < ActionView::<1>Base Zoomoo.<2>cache_template_extensions Zoomoo.new.<3>form_for "whatever".<4>pluralize end h = {'zounds' => 1, 'ok' => 2} h.<5>keys """))) main_path = join(test_dir, main_filename) writefile(main_path, main_content) main_buf = self.mgr.buf_from_path(main_path) targets = [[("class", "Base"), ], [("function", "cache_template_extensions"), ], [("function", "form_for"), ], [("function", "pluralize"), ], [("function", "stringify_keys!"), ], ] for i in range(len(targets)): self.assertCompletionsInclude2(main_buf, main_positions[i + 1], targets[i]) ## Verify we don't get false hits self.assertCompletionsDoNotInclude(markup_text(main_content, pos=main_positions[ i + 1]), targets[i])
def test_railsenv_model_toplevel_1(self): test_dir = join(self.test_dir, "railsapp01", "app", "models") main_filename = "cart1.rb" main_content, main_positions = \ unmark_text(self.adjust_content(dedent("""\ class Cart < ActiveRecord::<2>Base act<1>s_as_list end """))) main_path = join(test_dir, main_filename) writefile(main_path, main_content) main_buf = self.mgr.buf_from_path(main_path) pos_targets = [ ("function", "acts_as_list"), ("function", "acts_as_tree"), ("function", "acts_as_nested_set"), ] neg_targets = [ ("function", "add_child"), ] self.assertCompletionsInclude2(main_buf, main_positions[1], pos_targets) self.assertCompletionsDoNotInclude(markup_text(main_content, pos=main_positions[1]), neg_targets)
def test_railsenv_model_toplevel_context(self): test_dir = join(self.test_dir, "railsapp01", "app", "models") main_filename = "cart1.rb" main_content, main_positions = \ unmark_text(self.adjust_content(dedent("""\ class Cart < ActiveRecord::Base val<1> def switch des<2>troy end end """))) main_path = join(test_dir, main_filename) writefile(main_path, main_content) main_buf = self.mgr.buf_from_path(main_path) class_targets = [ ("function", "validate"), ("function", "validate_find_options"), ("function", "validate_on_create"), ("function", "validate_on_update"), ("function", "validates_acceptance_of"), ("function", "validates_associated"), ("function", "validates_confirmation_of"), ("function", "validates_each"), ("function", "validates_exclusion_of"), ("function", "validates_format_of"), ("function", "validates_inclusion_of"), ("function", "validates_length_of"), ("function", "validates_numericality_of"), ("function", "validates_presence_of"), ("function", "validates_size_of"), ("function", "validates_uniqueness_of"), ] inst_targets = [ ("function", "destroy"), ("function", "destroy_all"), ] self.assertCompletionsInclude2(main_buf, main_positions[1], class_targets) self.assertCompletionsInclude2(main_buf, main_positions[2], inst_targets) self.assertCompletionsDoNotInclude(markup_text(main_content, pos=main_positions[1]), inst_targets) self.assertCompletionsDoNotInclude(markup_text(main_content, pos=main_positions[2]), class_targets)
def test_open(self): content, positions = unmark_text( dedent(""" f = open("/dev/null", "w") f.<1>w """)) self.assertCompletionsInclude(markup_text(content, positions[1]), [("function", "write")])
def test_ellipsis_literal(self): content, positions = unmark_text( dedent(""" var = ... "string".<1>e """)) self.assertCompletionsInclude(markup_text(content, positions[1]), [("function", "encode")])
def assertCalltipIs2(self, buf, pos, calltip, implicit=True): """A variant of assertCalltipIs() where you pass in a Buffer instance instead of marked up content. Sometimes this is more convenient. """ trg = buf.trg_from_pos(pos, implicit=implicit) markedup_content = markup_text(buf.accessor.text, pos=trg.pos) self._assertCalltipIs(buf, trg, markedup_content, calltip, self.lang)
def test_iterable_unpacking(self): content, positions = unmark_text( dedent(""" (a, *rest, b) = [1, 2, 3, 4] rest.<1>i """)) self.assertCompletionsInclude(markup_text(content, positions[1]), [("function", "insert")])
def test_kw_only_args(self): content, positions = unmark_text(dedent(""" def func(*, kw): return "string" func().<1>s """)) self.assertCompletionsInclude(markup_text(content, positions[1]), [("function", "strip")])
def test_railsenv_model_toplevel_context(self): test_dir = join(self.test_dir, "railsapp01", "app", "models") main_filename = "cart1.rb" main_content, main_positions = \ unmark_text(self.adjust_content(dedent("""\ class Cart < ActiveRecord::Base val<1> def switch des<2>troy end end """))) main_path = join(test_dir, main_filename) writefile(main_path, main_content) main_buf = self.mgr.buf_from_path(main_path) class_targets = [ ("function", "validate"), ("function", "validate_find_options"), ("function", "validate_on_create"), ("function", "validate_on_update"), ("function", "validates_acceptance_of"), ("function", "validates_associated"), ("function", "validates_confirmation_of"), ("function", "validates_each"), ("function", "validates_exclusion_of"), ("function", "validates_format_of"), ("function", "validates_inclusion_of"), ("function", "validates_length_of"), ("function", "validates_numericality_of"), ("function", "validates_presence_of"), ("function", "validates_size_of"), ("function", "validates_uniqueness_of"), ] inst_targets = [ ("function", "destroy"), ("function", "destroy_all"), ] self.assertCompletionsInclude2(main_buf, main_positions[1], class_targets) self.assertCompletionsInclude2(main_buf, main_positions[2], inst_targets) self.assertCompletionsDoNotInclude( markup_text(main_content, pos=main_positions[1]), inst_targets) self.assertCompletionsDoNotInclude( markup_text(main_content, pos=main_positions[2]), class_targets)
def test_complete_scss_classes(self): content, positions = unmark_text(dedent("""\ .error { border: 1px #f00; background-color: #fdd; } .seriousError { @extend .<1>error; border-width: 3px; } .<2> """)) for i in xrange(1, 2): self.assertTriggerMatches(markup_text(content, pos=positions[i]), name="css-complete-class-names") self.assertCompletionsAre(markup_text(content, pos=positions[i]), [("class", "error"), ("class", "seriousError")])
def test_kw_only_args(self): content, positions = unmark_text( dedent(""" def func(*, kw): return "string" func().<1>s """)) self.assertCompletionsInclude(markup_text(content, positions[1]), [("function", "strip")])
def test_multi_selector_completions(self): content, positions = unmark_text( dedent("""\ <html> <head> <style type="text/css"> #header .foo, #footer .bar { } p .baz a { } </style> </head> <body> <div id="<1>"> <p class="<2>"> """)) self.assertCompletionsAre(markup_text(content, pos=positions[1]), [("id", "footer"), ("id", "header")]) self.assertCompletionsAre(markup_text(content, pos=positions[2]), [("class", "bar"), ("class", "baz"), ("class", "foo")])
def test_complete_scss_classes(self): content, positions = unmark_text( dedent("""\ .error { border: 1px #f00; background-color: #fdd; } .seriousError { @extend .<1>error; border-width: 3px; } .<2> """)) for i in xrange(1, 2): self.assertTriggerMatches(markup_text(content, pos=positions[i]), name="css-complete-class-names") self.assertCompletionsAre(markup_text(content, pos=positions[i]), [("class", "error"), ("class", "seriousError")])
def test_nonlocal(self): content, positions = unmark_text(dedent(""" global_var = "string" def func(): nonlocal global_var global_var = global_var return global_var func().<1>s """)) self.assertCompletionsInclude(markup_text(content, positions[1]), [("function", "strip")])
def test_multi_selector_completions(self): content, positions = unmark_text(dedent("""\ <html> <head> <style type="text/css"> #header .foo, #footer .bar { } p .baz a { } </style> </head> <body> <div id="<1>"> <p class="<2>"> """)) self.assertCompletionsAre(markup_text(content, pos=positions[1]), [("id", "footer"), ("id", "header")]) self.assertCompletionsAre(markup_text(content, pos=positions[2]), [("class", "bar"), ("class", "baz"), ("class", "foo")])
def test_complete_nested(self): if self.lang != 'Less': return # SCSS inherits this test case; ignore content, positions = unmark_text( dedent("""\ .test { .testClass { .<1> } } """)) self.assertCompletionsAre(markup_text(content, pos=positions[1]), [("class", "test"), ("class", "testClass")])
def assertCompletionsDoNotInclude2(self, buf, pos, completions, implicit=True): """A version of assertCompletionsDoNotInclude() where you pass in a Buffer instance instead of marked up content. Sometimes this is more convenient. """ trg = buf.trg_from_pos(pos, implicit=implicit) if trg is None: markedup_content = markup_text(buf.accessor.text, pos=pos) self.fail("given position is not a %s trigger point, " "expected completions to exclude %r:\n%s" % (buf.lang, completions, indent(markedup_content))) self._assertCompletionsDoNotInclude(buf, trg, completions)
def assertCompletionsInclude2(self, buf, pos, completions, implicit=True): """A version of assertCompletionsInclude() where you pass in a Buffer instance instead of marked up content. Sometimes this is more convenient. """ trg = buf.trg_from_pos(pos, implicit=implicit) if trg is None: markedup_content = markup_text(buf.accessor.text, pos=pos) self.fail("given position is not a %s trigger point, " "expected completions to include %r:\n%s" % (buf.lang, completions, indent(markedup_content))) self._assertCompletionsInclude(buf, trg, completions)
def test_xpcom_returns(self): content, positions = unmark_text(dedent("""\ var url = Components.classes["@mozilla.org/network/standard-url;1"] .createInstance(Components.interfaces.nsIURL); var uri = url.<1>clone(); uri.<2>; """)) self.assertCompletionsInclude(markup_text(content, pos=positions[1]), [("variable", "spec"), ("variable", "scheme"), ("function", "clone"), ("variable", "query"), ("function", "getCommonBaseSpec")]) # clone should return a nsIURI object self.assertCompletionsInclude(markup_text(content, pos=positions[2]), [("variable", "spec"), ("variable", "scheme"), ("function", "clone")]) self.assertCompletionsDoNotInclude(markup_text(content, pos=positions[2]), [("variable", "query"), ("function", "getCommonBaseSpec")])
def test_complete_nested(self): if self.lang != 'Less': return # SCSS inherits this test case; ignore content, positions = unmark_text(dedent("""\ .test { .testClass { .<1> } } """)) self.assertCompletionsAre(markup_text(content, pos=positions[1]), [("class", "test"), ("class", "testClass")])
def test_nonlocal(self): content, positions = unmark_text( dedent(""" global_var = "string" def func(): nonlocal global_var global_var = global_var return global_var func().<1>s """)) self.assertCompletionsInclude(markup_text(content, positions[1]), [("function", "strip")])
def test_xpcom_cplns(self): content, positions = unmark_text(dedent("""\ var observerSvc = Components.<1>classes["@mozilla.org/observer-service;1"].<2> getService(Components.interfaces.<3>nsIObserverService); observerSvc.<4>; observerSvc.addObserver(<5>); """)) self.assertCompletionsInclude(markup_text(content, pos=positions[1]), [("namespace", "classes"), ("namespace", "interfaces")]) self.assertCompletionsInclude(markup_text(content, pos=positions[2]), [("function", "createInstance"), ("function", "getService")]) self.assertCompletionsInclude(markup_text(content, pos=positions[3]), [("class", "nsIObserverService"), ("class", "nsIFile")]) self.assertCompletionsInclude(markup_text(content, pos=positions[4]), [("function", "addObserver"), ("function", "notifyObservers")]) self.assertCalltipIs(markup_text(content, pos=positions[5]), "addObserver(in nsIObserver, in String, in Boolean)")
def test_xpcom_returns(self): content, positions = unmark_text( dedent("""\ var url = Components.classes["@mozilla.org/network/standard-url;1"] .createInstance(Components.interfaces.nsIURL); var uri = url.<1>clone(); uri.<2>; """)) self.assertCompletionsInclude(markup_text(content, pos=positions[1]), [("variable", "spec"), ("variable", "scheme"), ("function", "clone"), ("variable", "query"), ("function", "getCommonBaseSpec")]) # clone should return a nsIURI object self.assertCompletionsInclude(markup_text(content, pos=positions[2]), [("variable", "spec"), ("variable", "scheme"), ("function", "clone")]) self.assertCompletionsDoNotInclude( markup_text(content, pos=positions[2]), [("variable", "query"), ("function", "getCommonBaseSpec")])
def test_xpcom_full_expression_cplns_bug80581(self): content, positions = unmark_text(dedent("""\ var ko_prefSvc = Components.classes["@activestate.com/koPrefService;1"] .getService(Components.interfaces.koIPrefService); ko_prefSvc.<1>; var ko_gPrefs = Components.classes["@activestate.com/koPrefService;1"] .getService(Components.interfaces.koIPrefService) .prefs; ko_gPrefs.<2>; """)) self.assertCompletionsInclude(markup_text(content, pos=positions[1]), [("variable", "prefs"), ("function", "saveState")]) self.assertCompletionsDoNotInclude(markup_text(content, pos=positions[1]), [("variable", "type"), ("function", "serialize")]) self.assertCompletionsInclude(markup_text(content, pos=positions[2]), [("variable", "inheritFrom"), ("function", "hasPref")]) self.assertCompletionsDoNotInclude(markup_text(content, pos=positions[2]), [("variable", "prefs"), ("function", "saveState")])
def test_xpcom_full_expression_cplns_bug80581(self): content, positions = unmark_text( dedent("""\ var ko_prefSvc = Components.classes["@activestate.com/koPrefService;1"] .getService(Components.interfaces.koIPrefService); ko_prefSvc.<1>; var ko_gPrefs = Components.classes["@activestate.com/koPrefService;1"] .getService(Components.interfaces.koIPrefService) .prefs; ko_gPrefs.<2>; """)) self.assertCompletionsInclude(markup_text(content, pos=positions[1]), [("variable", "prefs"), ("function", "saveState")]) self.assertCompletionsDoNotInclude( markup_text(content, pos=positions[1]), [("variable", "type"), ("function", "serialize")]) self.assertCompletionsInclude(markup_text(content, pos=positions[2]), [("variable", "type"), ("function", "serialize")]) self.assertCompletionsDoNotInclude( markup_text(content, pos=positions[2]), [("variable", "prefs"), ("function", "saveState")])
def test_xpcom_cplns(self): content, positions = unmark_text( dedent("""\ var observerSvc = Components.<1>classes["@mozilla.org/observer-service;1"].<2> getService(Components.interfaces.<3>nsIObserverService); observerSvc.<4>; observerSvc.addObserver(<5>); """)) self.assertCompletionsInclude(markup_text(content, pos=positions[1]), [("namespace", "classes"), ("namespace", "interfaces")]) self.assertCompletionsInclude(markup_text(content, pos=positions[2]), [("function", "createInstance"), ("function", "getService")]) self.assertCompletionsInclude(markup_text(content, pos=positions[3]), [("class", "nsIObserverService"), ("class", "nsIFile")]) self.assertCompletionsInclude(markup_text(content, pos=positions[4]), [("function", "addObserver"), ("function", "notifyObservers")]) self.assertCalltipIs( markup_text(content, pos=positions[5]), "addObserver(in nsIObserver, in String, in Boolean)")
def test_complete_less_classes(self): content, positions = unmark_text( dedent("""\ @base: #f938ab; .box-shadow(@style, @c) when (iscolor(@c)) { -webkit-box-shadow: @style @c; box-shadow: @style @c; } .<1>box-shadow(@style, @alpha: 50%) when (isnumber(@alpha)) { .<2>box-shadow(@style, rgba(0, 0, 0, @alpha)); } .box { color: saturate(@base, 5%); border-color: lighten(@base, 30%); div { .<3>box-shadow(0 0 5px, 30%) } } """)) for i in xrange(1, 3): self.assertTriggerMatches(markup_text(content, pos=positions[i]), name="css-complete-class-names") self.assertCompletionsAre(markup_text(content, pos=positions[i]), [("class", "box"), ("class", "box-shadow")])
def test_query_interface_2(self): content, positions = unmark_text( dedent("""\ var aFile = Components.classes["@mozilla.org/file/local;1"].createInstance(); if (aFile) { aFile.QueryInterface(Components.interfaces.nsIFile); // Should now know that this supports nsIFile aFile.<1>; } """)) self.assertCompletionsInclude(markup_text(content, pos=positions[1]), [("variable", "followLinks"), ("variable", "path"), ("function", "clone"), ("function", "exists"), ("function", "initWithPath")])
def _assertCompletionsInclude(self, buf, trg, completions): markedup_content = markup_text(buf.accessor.text, pos=trg.pos) if isinstance(buf, CitadelBuffer): buf.unload() # remove any entry from CIDB to ensure clean test ctlr = _CaptureEvalController() actual_completions = buf.cplns_from_trg(trg, ctlr=ctlr) missing_completions = [c for c in completions if c not in (actual_completions or [])] self.failIf(missing_completions, "%s completions at the given position did not " "include all expected values\n" " missing: %r\n" " expected all of: %r\n" " got: %r\n" " eval log:\n%s\n" " buffer:\n%s" % (buf.lang, missing_completions, completions, actual_completions, indent('\n'.join('%5s: %s' % (lvl, m) for lvl, m in ctlr.log)), indent(markedup_content)))
def test_railsenv_views_basic_html_erb_suffix(self): test_dir = join(self.test_dir, "railsapp01", "app", "views", "layouts") main_filename = "add.html.erb" main_content, main_positions = \ unmark_text(self.adjust_content(dedent("""\ # Contrived: most layouts are implicit members of this class class Zoomoo < ActionView::<1>Base Zoomoo.<2>cache_template_extensions Zoomoo.new.<3>form_for "whatever".<4>pluralize end h = {'zounds' => 1, 'ok' => 2} h.<5>keys """))) main_path = join(test_dir, main_filename) writefile(main_path, main_content) main_buf = self.mgr.buf_from_path(main_path) targets = [ [ ("class", "Base"), ], [ ("function", "cache_template_extensions"), ], [ ("function", "form_for"), ], [ ("function", "pluralize"), ], [ ("function", "stringify_keys!"), ], ] for i in range(len(targets)): self.assertCompletionsInclude2(main_buf, main_positions[i + 1], targets[i]) ## Verify we don't get false hits self.assertCompletionsDoNotInclude( markup_text(main_content, pos=main_positions[i + 1]), targets[i])
def _assertCompletionsDoNotInclude(self, buf, trg, completions): markedup_content = markup_text(buf.accessor.text, pos=trg.pos) if isinstance(buf, CitadelBuffer): buf.unload() # remove any entry from CIDB to ensure clean test ctlr = _CaptureEvalController() actual_completions = buf.cplns_from_trg(trg, ctlr=ctlr) completions_that_shouldnt_be_there = [ c for c in (actual_completions or []) if c in completions ] self.failIf(completions_that_shouldnt_be_there, "%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" " eval log:\n%s\n" " buffer:\n%s" % (buf.lang, completions_that_shouldnt_be_there, completions, actual_completions, indent('\n'.join('%5s: %s' % (lvl, m) for lvl, m in ctlr.log)), indent(markedup_content)))