mirror of
https://github.com/adrienverge/yamllint.git
synced 2024-11-26 01:20:15 -06:00
7a7d98c96a
Instead of iterating over lines and tokens (and find comments between tokens in the comment rules), add a new `Comment` type and set rules with `type = 'comment'`.
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright (C) 2016 Adrien Vergé
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import unittest
|
|
|
|
import yaml
|
|
|
|
from yamllint.rules.common import get_line_indent
|
|
|
|
|
|
class CommonTestCase(unittest.TestCase):
|
|
def test_get_line_indent(self):
|
|
tokens = list(yaml.scan('a: 1\n'
|
|
'b:\n'
|
|
' - c: [2, 3, {d: 4}]\n'))
|
|
|
|
self.assertEqual(tokens[3].value, 'a')
|
|
self.assertEqual(tokens[5].value, '1')
|
|
self.assertEqual(tokens[7].value, 'b')
|
|
self.assertEqual(tokens[13].value, 'c')
|
|
self.assertEqual(tokens[16].value, '2')
|
|
self.assertEqual(tokens[18].value, '3')
|
|
self.assertEqual(tokens[22].value, 'd')
|
|
self.assertEqual(tokens[24].value, '4')
|
|
|
|
for i in (3, 5):
|
|
self.assertEqual(get_line_indent(tokens[i]), 0)
|
|
for i in (7,):
|
|
self.assertEqual(get_line_indent(tokens[i]), 0)
|
|
for i in (13, 16, 18, 22, 24):
|
|
self.assertEqual(get_line_indent(tokens[i]), 2)
|