예제 #1
0
 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]))
예제 #2
0
 def test_do_not_close_html_img(self):
     # Raised by Alex Fernandez on komodo-beta about k4b1.
     html_content = dedent("""\
         <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
             "http://www.w3.org/TR/html4/strict.dtd">
         <html>
         <head> <title>my title</title> </head>
         <body>
             <p>blah blah...
             <img src="somefile.jpg" alt="blah">
             </<|>p>
         </body>
         </html>
     """)
     self.assertCompletionsDoNotInclude(html_content, [("element", "img>")])
     # invalid XHTML usage, without the xml declaration, it is treated like
     # html from a parser point of view, so close tags are handled differently
     html_content = dedent("""\
         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
         <html>
         <head> <title>my title</title> </head>
         <body>
             <p>blah blah...
             <img src="somefile.jpg" alt="blah">
             </<|>
     """)
     self.assertCompletionsDoNotInclude(html_content, [("element", "img>")])
예제 #3
0
    def test_complete_property_values(self):
        #        h1\n   border: <|>1px <|>solid <|>black;
        #        # implicit: one space
        # h1\n   border:   <|>...  # explicit: allow trig on multiple spaces
        name = "css-complete-property-values"
        self.assertTriggerMatches("h1\n   color: <|>",
                                  name=name, pos=13, form=TRG_FORM_CPLN)
        self.assertTriggerMatches("h1\n   color: <|>;",
                                  name=name, pos=13, form=TRG_FORM_CPLN)
        self.assertTriggerMatches("h1\n   border: blue <|>", name=name)
        self.assertTriggerMatches("h1\n   border: blue <|>;", name=name)
        # We implicitly trigger on multiple spaces
        self.assertTriggerMatches("h1\n   color: <|>", name=name)
        self.assertTriggerMatches("h1\n   color:    <|>", name=name)
        self.assertTriggerMatches("h1\n   color: <|>;", name=name)
        self.assertTriggerMatches("h1\n   color:    <|>;", name=name)
        # self.assertTriggerMatches("h1\n   color: rgb(255, 255, 255) <|>", name=name)
        ## Don't trigger inside braces
        # self.assertNoTrigger("h1\n   color: rgb(255, <|>")
        # self.assertNoTrigger("h1\n   color: rgb(255, 255, <|>255) white; ")
        # Don't trigger inside comments
        self.assertNoTrigger("/*h1\n   color: <|>")
        # assert no trig in string or URL
        self.assertNoTrigger('body\n   background: "../myimage.png: <|>"')

        # Special handling for the following content, it is handled differently
        # between straight CSS and UDL.
        css_content = dedent('body\n   background: url(myimage.png: <|>)')
        # This does trigger, as it does not yet know enough
        # information. It will not produce any cpln's though, test
        # it to make sure that is the case.
        self.assertTriggerMatches(css_content, name=name)
        self.assertCompletionsAre(css_content, None)

        css_content = dedent("""
            /* http://www.w3.org/TR/REC-CSS2/fonts.html#propdef-font-weight */
            h1\n   border: 1px solid black;
                font-weight /* hi */: <|> !important
        """)
        values = CSS_ATTR_DICT['font-weight']
        self.assertCompletionsAre(css_content, [("value", v) for v in values])

        # Specific bug tests
        #
        # Ensure semi-colan does not screw us up:
        #   http://bugs.activestate.com/show_bug.cgi?id=50368
        self.assertTriggerMatches(
            "h1\n   font-variable: s<|>mall-caps; ", name="css-complete-property-values")

        # Ensure already used property values do not get shown again:
        #   http://bugs.activestate.com/show_bug.cgi?id=48978
        css_content = dedent("""
            /* http://www.w3.org/TR/REC-CSS2/fonts.html#propdef-font-variant */
            h1\n   border: 1px solid black;
                font-variant: normal <|>; /* normal shouldn't be in CC list */
        """)
        values = CSS_ATTR_DICT['font-variant'][
            :]  # copy, so we don't modify it
        values.remove('normal')  # Should not be in the list
        self.assertCompletionsAre(css_content, [("value", v) for v in values])
예제 #4
0
    def test_trg_with_cuddled_tag_close(self):
        name = "xml-complete-tag-attrs"
        self.assertTriggerMatches(xmlprefix+"<tag <|>/>", name=name)
        self.assertTriggerMatches(xmlprefix+"<ns: <|>/>", name=name)
        self.assertTriggerMatches(xmlprefix+"<ns:tag <|>/>", name=name)
        self.assertTriggerMatches(
            xmlprefix+"<ns:tag attr1='val1' <|>/>", name=name)

        self.assertCompletionsInclude(dedent(xmlprefix+"""\
            <window xmlns:html="http://www.w3.org/1999/xhtml"
                    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
                <button <|>/>
            </window>
            """),
                                      [("attribute", "accesskey=")],
                                      lang="XUL")

        # bug 61777
        self.assertCompletionsInclude(dedent(xmlprefix+"""\
            <window xmlns:html="http://www.w3.org/1999/xhtml"
                    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
                <button <|>
            """),
                                      [("attribute", "label=")],
                                      lang="XUL")
예제 #5
0
    def test_railsenv_controller_find_peer(self):
        test_dir = join(self.test_dir, "railsapp01", "app", "controllers")
        adminc_filename = "admin_controller%s" % self.ext
        adminc_content, adminc_positions = \
            unmark_text(self.adjust_content(dedent("""\
            module AppBogus
                # to force a choice at point 2
            end
            class AdminController < <1>App<2>licationController
                aft<3>er_filter :check_authentication, :except => [:signin]
                AdminController.filter_parameter_logging(<6>'a', 'b')
                def open
                    exp<4>ires_in 10.seconds
                    self.<5>redirect_to("chumley")
                end
            end
        """)))
        manifest = [
            (join(test_dir, "application.rb"), dedent("""\
                class ApplicationController < ActionController::Base
                    def foo
                    end
                end
             """)),
            (adminc_filename, adminc_content),
        ]
        for file, content in manifest:
            path = join(test_dir, file)
            writefile(path, content)
        adminc_buf = self.mgr.buf_from_path(join(test_dir, adminc_filename))
        targets = [None,  # 0
                   None,  # 1
                   [("class", "ApplicationController"),  # 2
                    ("namespace", "AppBogus"),
                    ],
                   [("function", "after_filter"),  # 3
                    ],
                   [("function", "expires_in"),  # 4
                    ("function", "expires_now")
                    ],
                   [("function", "redirect_to"),  # 5
                    ("function", "session_enabled?"),
                    ],
                   ]

        # for i in range(2, 1 + len(targets)):
        for i in (2, 5):
            self.assertCompletionsInclude2(adminc_buf, adminc_positions[i],
                                           targets[i])
        self.assertCalltipIs2(adminc_buf, adminc_positions[6],
                              dedent("""\
    (*filter_words, &block) {|key, value| ...}
    Replace sensitive paramater data from the request log.
    Filters paramaters that have any of the arguments as a
    substring. Looks in all subhashes of the param hash for keys
    to filter. If a block is given, each key and value of the
    paramater hash and all subhashes is passed to it, the value
    or key can be replaced using String#replace or similar
    method."""))
예제 #6
0
 def test_controller_find_peer(self):
     dirs1 = [self.test_dir, "peers", "app"]
     test_controller_dir = join(*(dirs1 + ["controllers"]))
     test_model_dir = join(*(dirs1 + ["models"]))
     adminc_filename = join(test_controller_dir, "admin_controller.rb")
     book_path = join(test_model_dir, "book.rb")
     cart_path = join(test_model_dir, "cart.rb")
     adminc_content, adminc_positions = \
         unmark_text(self.adjust_content(dedent("""\
             class ApplicationController < ActionController::Base
                 def foo
                    x = Cart<5>.<1>new
                    x.<2>add_i<6>tem()
                    y = Boo<7>k.<3>new
                    y.<4>re<8>ad()
                 end
             end
     """)))
     manifest = [
         (cart_path, dedent("""\
              class Cart < ActiveRecord::Base
                def add_item(a)
                end
              end
          """)),
         (book_path, dedent("""\
              class Book < ActiveRecord::Base
                def read(a)
                end
              end
          """)),
         (adminc_filename, adminc_content),
     ]
     for path, content in manifest:
         writefile(path, content)
     adminc_buf = self.mgr.buf_from_path(adminc_filename)
     targets = [None,  # 0
                [("function", "new"),  # 1
                 ],
                [("function", "add_item"),  # 2
                 ],
                [("function", "new"),  # 3
                 ],
                [("function", "read"),  # 4
                 ],
                ]
     repl_path = 'models'
     fixed_cart_path = cart_path.replace('models', repl_path)
     fixed_book_path = book_path.replace('models', repl_path)
     self.assertDefnMatches2(adminc_buf, adminc_positions[5],
                             ilk="class", name="Cart", line=1, path=fixed_cart_path)
     self.assertDefnMatches2(adminc_buf, adminc_positions[6],
                             ilk="function", name="add_item", line=2, path=fixed_cart_path)
     self.assertDefnMatches2(adminc_buf, adminc_positions[7],
                             ilk="class", name="Book", line=1, path=fixed_book_path)
     self.assertDefnMatches2(adminc_buf, adminc_positions[8],
                             ilk="function", name="read", line=2, path=fixed_book_path)
예제 #7
0
 def test_xulclose(self):
     xml = dedent(xmlprefix+"""\
                  <hbox>
                     <splitter><grippy/></<|>
                   </hbox>""")
     self.assertCompletionsAre(xml, [('element', 'splitter>')])
     xml = dedent(xmlprefix+"""\
                  <xul:hbox  xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
                     <xul:splitter><xul:grippy/></<|>
                   </xul:hbox>""")
     self.assertCompletionsAre(xml, [('element', 'xul:splitter>')])
예제 #8
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")
예제 #9
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")
예제 #10
0
 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])
예제 #11
0
 def test_empty_css3_property_completions(self):
     content = dedent("""
         body {
             transition-property: <|>;
         }
     """)
     self.assertCompletionsAre(content, [])
예제 #12
0
 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)
예제 #13
0
    def test_model_sees_rails2_migrations_1(self):
        dirs1 = [self.test_dir, "bug75440", "app"]
        test_model_dir = join(*(dirs1 + ["models"]))
        book_path = join(test_model_dir, "book.rb")

        dirs2 = [self.test_dir, "bug75440", "db", "migrate"]
        migrate_dir = join(*dirs2)
        migrate_table_create_path = join(migrate_dir, "001_create_books_and_dishes.rb")
        model_content, model_positions = unmark_text(
            self.adjust_content(
                dedent(
                    """\
                 class Book < ActiveRecord::Base
                   def get_title(a)
                       return self.<1>title
                   end
                 end
        """
                )
            )
        )
        manifest = [(migrate_table_create_path, self.books_and_dishes_migration), (book_path, model_content)]
        for path, content in manifest:
            writefile(path, content)
        model_buf = self.mgr.buf_from_path(book_path)
        self.assertCompletionsInclude2(
            model_buf,
            model_positions[1],
            [("function", "title"), ("function", "author"), ("function", "publisher"), ("function", "isbn")],
        )
        self.assertCompletionsDoNotInclude2(
            model_buf,
            model_positions[1],
            [("function", "bet"), ("function", "manufacturer"), ("function", "created_at"), ("function", "updated_at")],
        )
예제 #14
0
 def test_basic(self):
     self.assertLex(dedent("""
         <html><head><title>foo</title><head> 
         <body>
         <SCE_UDL_TPL_OPERATOR><%</SCE_UDL_TPL_OPERATOR><SCE_UDL_SSL_COMMENTBLOCK># foo </SCE_UDL_SSL_COMMENTBLOCK><SCE_UDL_TPL_OPERATOR>%></SCE_UDL_TPL_OPERATOR>
         <body></html>
     """))
예제 #15
0
 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")])
예제 #16
0
 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")])
예제 #17
0
 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])
예제 #18
0
 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)
예제 #19
0
 def test_trg_prop_value_after_url(self):
     content = dedent("""
         body
             background: url("blah") <|>
     """)
     self.assertCompletionsInclude(content,
         [("value", "no-repeat")])
예제 #20
0
 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)
예제 #21
0
 def test_ellipsis_literal(self):
     content, positions = unmark_text(dedent("""
             var = ...
             "string".<1>e
         """))
     self.assertCompletionsInclude(markup_text(content, positions[1]),
                                   [("function", "encode")])
예제 #22
0
    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")])
예제 #23
0
    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")])
예제 #24
0
    def create(self):
        log.info("create db in `%s'", self.base_dir)
        self.acquire_lock()
        try:
            log.debug("fs-write: create db skeleton in '%s'", self.base_dir)
            try:
                os.makedirs(self.base_dir)
            except:  # in case we had a race somewhere
                if not isdir(self.base_dir):
                    raise
            open(join(self.base_dir, "README.txt"), "w").write(
                dedent(
                    """
                This is a database for the Code Intelligence system (a
                subsystem of SublimeCodeIntel). Do NOT modify anything in here
                unless you know what you are doing.

                See http://github.com/SublimeCodeIntel/SublimeCodeIntel for details.
            """
                )
            )
            open(join(self.base_dir, "VERSION"), "w").write(self.VERSION)
            config_file = join(self.base_dir, "config")
            if not exists(config_file):
                open(config_file, "w").write("{}")
            os.mkdir(join(self.base_dir, "db"))
        finally:
            self.release_lock()
예제 #25
0
 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])
예제 #26
0
 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])
예제 #27
0
 def test_no_trg_after_comment(self):
     self.assertTriggerMatches(dedent("""
             body
                 color: #036
                 /* fill in css declarations in here to test css autocomplete */
                 b<|>
         """),
         name="sass-complete-tag-or-property-names")
예제 #28
0
 def test_basic(self):
     self.assertLex(
         dedent("""
         <html><head><title>foo</title><head> 
         <body>
         <SCE_UDL_TPL_OPERATOR><%</SCE_UDL_TPL_OPERATOR><SCE_UDL_SSL_COMMENTBLOCK># foo </SCE_UDL_SSL_COMMENTBLOCK><SCE_UDL_TPL_OPERATOR>%></SCE_UDL_TPL_OPERATOR>
         <body></html>
     """))
예제 #29
0
 def test_attr_enum_cpln(self):
     self.assertCompletionsAre(
         dedent("""
             <?xml version="1.0"?>
             <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
             <html dir="<|>>
             </html>
         """), [("attribute_value", 'ltr'), ("attribute_value", 'rtl')])
     self.assertCompletionsAre(
         dedent("""
             <?xml version="1.0"?>
             <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
             <html dir='<|>>
             </html>
         """), [("attribute_value", "ltr"), ("attribute_value", "rtl")])
예제 #30
0
 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)
예제 #31
0
 def test_no_trg_after_comment(self):
     self.assertTriggerMatches(dedent("""
             body
                 color: #036
                 /* fill in css declarations in here to test css autocomplete */
                 b<|>
         """),
                               name="sass-complete-tag-or-property-names")
예제 #32
0
 def test_css3_transition_property_completions(self):
     content = dedent("""
         body {
             transition-property: <|>;
         }
     """)
     transitions = [("value", s) for s in ("all", "IDENT", "none", "<single-transition-property>")]
     self.assertCompletionsAre(content, transitions)
예제 #33
0
 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")])
예제 #34
0
 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")])
예제 #35
0
 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")])
예제 #36
0
 def test_completions_invalid_html(self):
     self.assertCompletionsInclude(
         dedent("""
             <html>
                 </foo>
                 <<|>
             </html>
         """),
         [("element", 'p'), ("element", 'div')])
예제 #37
0
파일: test_css.py 프로젝트: p4p3r/CodeIntel
 def test_css3_transition_property_completions(self):
     content = dedent("""
         body {
             transition-property: <|>;
         }
     """)
     transitions = [("value", s) for s in ("all", "IDENT", "none",
                                           "<single-transition-property>")]
     self.assertCompletionsAre(content, transitions)
예제 #38
0
 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]))
예제 #39
0
 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")])
예제 #40
0
 def test_completions_in_head_bug64997(self):
     raw_content = dedent("""\
         %s
         <html>
         <head>
         <<|>
     """)
     self._test_xhtml_completions_base_test(
         raw_content, [("element", "style")])
     self._test_html_completions_base_test(
         raw_content, [("element", "style")])
예제 #41
0
 def test_no_trg_after_comment(self):
     expected_trg_name = self.lang.lower(
     ) + "-complete-tag-or-property-names"
     self.assertTriggerMatches(dedent("""
             body {
                 color: #036;
                 /* fill in css declarations in here to test css autocomplete */
                 b<|>
             }
         """),
                               name=expected_trg_name)
예제 #42
0
 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")])
예제 #43
0
 def test_trg_at_sign(self):
     complete_variable = self.lang.lower() + "-complete-variable"
     self.assertTriggerMatches(".foo(@<|>) { /*...*/ };",
                               name=complete_variable)
     self.assertTriggerMatches("@foo: @<|>", name=complete_variable)
     self.assertTriggerMatches("@<|>", name="css-complete-at-rule")
     self.assertTriggerMatches(dedent("""
         .foo {
             @<|>
         }
     """),
                               name="css-complete-at-rule")
예제 #44
0
    def test_zend_view_hooks(self):
        test_dir = join(self.test_dir, "test_zend_view_hooks")
        content, positions = unmark_text(
            dedent("""\
            <?php if($this->values) { ?>
            <h3>You just submitted the following values:</h3>
            <ul>
              <?php foreach ($this->values as $value) :?>
              <li>
                <?= $this-><1>escape(<2>$value); ?>
              </li>
              <?php endforeach; ?>
            </ul>
            <?=
            $this->form; ?>
        """))
        phpExtraPaths = os.pathsep.join(self._ci_extra_path_dirs_)
        env = SimplePrefsEnvironment(phpExtraPaths=phpExtraPaths)

        # Test to make sure the zend hooks are only modifying the files
        # in the /view/scripts/ directories. We should *not* get the completions
        # for the above code.
        path = join(test_dir, "test_zend_view.phtml")
        writefile(path, content)
        buf = self.mgr.buf_from_path(path, lang=self.lang, env=env)
        buf.scan_if_necessary()
        self.assertCompletionsDoNotInclude2(buf, positions[1],
                                            [("function", "escape"),
                                             ("function", "render")])

        # Test to make sure the zend hooks are only modifying the ".phtml" files
        # in the /view/scripts/ directories. We should *not* get the completions
        # for the above code.
        path = join(test_dir, "test_zend_view.php")
        writefile(path, content)
        buf = self.mgr.buf_from_path(path, lang=self.lang, env=env)
        buf.scan_if_necessary()
        self.assertCompletionsDoNotInclude2(buf, positions[1],
                                            [("function", "escape"),
                                             ("function", "render")])

        # Now make sure we do get the completions on /view/scripts/ directories.
        path = join(test_dir, "views", "scripts", "test_zend_view.phtml")
        writefile(path, content)
        buf = self.mgr.buf_from_path(path, lang=self.lang, env=env)
        buf.scan_if_necessary()
        self.assertCompletionsInclude2(buf, positions[1],
                                       [("function", "escape"),
                                        ("function", "render")])
        # Make sure we do not get completions on the added "(render)" function.
        self.assertCompletionsDoNotInclude2(buf, positions[1], [
            ("function", "(render)"),
        ])
예제 #45
0
 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")])
예제 #46
0
 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")])
예제 #47
0
 def test_unicode(self):
     self.assertCompletionsInclude(
         dedent(u"""
             <!DOCTYPE html>
             <html>
                 <body>
                     <a title="\u2603">
                         \u2603\u2603\u2603
                     </a>
                     <<|>
                 </body>
             </html>
         """), [("element", "p")])
예제 #48
0
 def setUp(self):
     _BufferTestCaseBase.setUp(self)
     self.doc.buffer, self.positions = unmark_text(dedent(u"""
         # Ťĥíš ƒíłé ĥáš Ůɳíčóďé ťéхť ťó ťéšť ƀýťé νš čĥář ƿóšíťíóɳš
         def silly():
             indent = 4<5>
             import <1>pprint
             pprint.pformat(<2>obj, indent<3>, width, depth)
         def other_method():
             pass<6>
         def third_method():
             pass<7>
         """).strip())
예제 #49
0
 def test_trg_at_sign(self):
     """
     SCSS does not have @variables, so ensure all @ triggers are for
     at-rules.
     """
     self.assertTriggerMatches(".foo(@<|>) { /*...*/ };",
                               name="css-complete-at-rule")
     self.assertTriggerMatches("@<|>", name="css-complete-at-rule")
     self.assertTriggerMatches(dedent("""
         .foo {
             @<|>
         }
     """),
                               name="css-complete-at-rule")
예제 #50
0
    def test_trg_with_cuddled_tag_close(self):
        name = "xml-complete-tag-attrs"
        self.assertTriggerMatches(xmlprefix + "<tag <|>/>", name=name)
        self.assertTriggerMatches(xmlprefix + "<ns: <|>/>", name=name)
        self.assertTriggerMatches(xmlprefix + "<ns:tag <|>/>", name=name)
        self.assertTriggerMatches(xmlprefix + "<ns:tag attr1='val1' <|>/>",
                                  name=name)

        self.assertCompletionsInclude(dedent(xmlprefix + """\
            <window xmlns:html="http://www.w3.org/1999/xhtml"
                    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
                <button <|>/>
            </window>
            """), [("attribute", "accesskey=")],
                                      lang="XUL")

        # bug 61777
        self.assertCompletionsInclude(dedent(xmlprefix + """\
            <window xmlns:html="http://www.w3.org/1999/xhtml"
                    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
                <button <|>
            """), [("attribute", "label=")],
                                      lang="XUL")
예제 #51
0
 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]))
예제 #52
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
예제 #53
0
 def test_close_xhtml_img(self):
     xhtml_content = dedent("""<?xml version="1.0"?>
         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
         <html>
         <head> <title>my title</title> </head>
         <body>
             <p>blah blah...
             <img src="somefile.jpg" alt="blah">
             </<|>img>
             </p>
         </body>
         </html>
     """)
     self.assertCompletionsAre(xhtml_content, [("element", "img>")])
예제 #54
0
 def test_via_scan(self):
     content = dedent("""\
         class Blam1:
             def pow(self, bb):
                 "pow man!"
                 pass
             def pif(self, aa):
                 pass
         
         # FooHookHandler adds top-level "Foo" class.
         f = Foo()
         f.<|>foo
     """)
     self.assertCompletionsInclude(content, [("function", "foo")],
                                   lang="Python")
예제 #55
0
 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")])
예제 #56
0
 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'), ))
예제 #57
0
    def test_complete_property_values_complex(self):
        # completions for complex style of propery-values
        name = "css-complete-property-values"
        content, positions = unmark_text(
            dedent("""\
            <p style="
                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;
            " />
        """))
        values = set(CSS_ATTR_DICT['background'])
        for i in range(1, 6):
            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 == 1:
                v.difference_update(set(['no-repeat', 'url(']))
            elif i == 2:
                v.difference_update(set(['transparent', 'no-repeat']))
            elif i == 5:
                v.difference_update(set(['transparent', 'url(']))
            else:
                v.difference_update(set(['transparent', 'url(', 'no-repeat']))
            self.assertCompletionsInclude(
                markup_text(content, pos=positions[i]),
                [("value", x) for x in v])

        values = set(CSS_ATTR_DICT['font-family'])
        # Remove these values, as they are already in the property list
        values = values.difference(set(['sans-serif']))
        for i in range(6, 9):
            self.assertTriggerMatches(markup_text(content, pos=positions[i]),
                                      name=name)
            self.assertCompletionsInclude(
                markup_text(content, pos=positions[i]),
                [("value", v) for v in values])

        values = set(CSS_ATTR_DICT['float'])
        # Remove these values, as they are already in the property list
        values = values.difference(set(['left']))
        self.assertTriggerMatches(markup_text(content, pos=positions[9]),
                                  name=name)
        self.assertCompletionsInclude(markup_text(content, pos=positions[9]),
                                      [("value", v) for v in values])
예제 #58
0
 def test_should_be_input_inside_form(self):
     # though common use is for input to be anywhere, it *is not valid*
     # html as defined by w3c, thus the div tag
     content = dedent("""\
         <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
             "http://www.w3.org/TR/html4/strict.dtd">
         <html>
         <head> <title>my title</title> </head>
         <body>
             <form action="form_action.asp" method="get"><div>
             First name:
             <<|>
             </div></form>
         </body>
         </html>
     """)
     self.assertCompletionsInclude(content, [("element", "input")])
예제 #59
0
    def test_completions(self):
        doclet1 = dedent(xmlprefix+"""\
                         <c1>
                           <c2 a1="1" a2='1' a3='val'>
                             <e1 />
                             <e2 f1="1" f2 = '33' />""")

        self.assertCompletionsInclude(xmlprefix+"<!<|>",
            [("comment", "--")])
        self.assertCompletionsAre(xmlprefix+"<!<|>",
            [('doctype', 'DOCTYPE'), ('cdata', '[CDATA['), ('comment', '--')])
        from codeintel2.lang_xml import common_namespace_cplns
        self.assertCompletionsAre(xmlprefix+"<x xmlns:<|>", common_namespace_cplns)
        self.assertCompletionsAre(doclet1 + "</<|>", [('element', 'c2>')])
        self.assertCompletionsAre(doclet1 + "</c2  >  </<|>", [('element', 'c1>')])
        self.assertCompletionsAre(doclet1 + "<c3 a='1'>blah</c3></c2  >  </<|>", [('element', 'c1>')])
        self.assertCompletionsAre(doclet1 + "</c2  > </c1></<|>", None)
예제 #60
0
 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)