Пример #1
0
 def test_trailing_whitespace(self):
     self.assertEquals(
         [html_linter.TrailingWhitespaceMessage(
             line=1, column=4, whitespace=' ')],
         html_linter.HTML5Linter('foo \n').messages
     )
     self.assertEquals(
         [html_linter.TrailingWhitespaceMessage(
             line=1, column=4, whitespace=' '),
          html_linter.TrailingWhitespaceMessage(
             line=2, column=5, whitespace='  ')],
         html_linter.HTML5Linter('foo \nbarz  \n').messages
     )
     self.assertEquals(
         [html_linter.TrailingWhitespaceMessage(
             line=1, column=4, whitespace='\t \t'),
          html_linter.TabMessage(line=1, column=4),
          html_linter.TabMessage(line=1, column=6)],
         html_linter.HTML5Linter('foo\t \t\r').messages
     )
     # Only complaint before a newline
     self.assertEquals(
         [],
         html_linter.HTML5Linter('a  ').messages
     )
Пример #2
0
 def test_tabs(self):
     self.assertEquals([html_linter.TabMessage(line=1, column=3)],
                       html_linter.HTML5Linter('  \t\t').messages)
     self.assertEquals([
         html_linter.TabMessage(line=1, column=3),
         html_linter.TabMessage(line=2, column=1)
     ],
                       html_linter.HTML5Linter('  \ta\n\ta').messages)
Пример #3
0
    def test_indentation(self):
        self.assertEquals(
            [html_linter.IndentationMessage(
                line=2, column=1, indent=3, max_indent=2)],
            html_linter.HTML5Linter('<div>\n   <a>').messages
        )
        # If we indented by something that is not a multiple of two, we
        # normalize it to a multiple of two so to minimize subsequent
        # false positives.
        self.assertEquals(
            [html_linter.IndentationMessage(
                line=2, column=1, indent=1, max_indent=2)],
            html_linter.HTML5Linter('<div>\n <a>\n</div>').messages
        )
        self.assertEquals(
            [html_linter.IndentationMessage(
                line=2, column=1, indent=1, max_indent=4)],
            html_linter.HTML5Linter('  <a></a>\n </div>\n<div>').messages
        )
        # If we indented by something greater than the maximum allowed we
        # normalize it to the previous maximum.
        self.assertEquals(
            [html_linter.IndentationMessage(
                line=2, column=1, indent=3, max_indent=2)],
            html_linter.HTML5Linter('<a></a>\n   </div>\n    <div>').messages
        )
        # This case should raise two warnings, because the first indentation is
        # normalized to 2 spaces and the second is 6 spaces.
        self.assertEquals(
            [html_linter.IndentationMessage(
                line=2, column=1, indent=3, max_indent=2),
             html_linter.IndentationMessage(
                line=3, column=1, indent=6, max_indent=4)],
            html_linter.HTML5Linter('<a></a>\n   </div>\n      <div>').messages
        )

        self.assertEquals(
            [],
            html_linter.HTML5Linter('<div>\n  <a>').messages
        )
        # Tabs are replaced by two spaces, so we are only getting the Tab error.
        self.assertEquals(
            [html_linter.TabMessage(line=2, column=1)],
            html_linter.HTML5Linter('<div>\n\t<a>').messages
        )