diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 00:38:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 00:38:50 +0000 |
commit | 09e7b47bad7e7310a6f52bdc20e9a9f251e79769 (patch) | |
tree | c93d189c1318902b8f1e5333d7ee34a1e9db9a34 /tests/rules/test_common.py | |
parent | Initial commit. (diff) | |
download | yamllint-09e7b47bad7e7310a6f52bdc20e9a9f251e79769.tar.xz yamllint-09e7b47bad7e7310a6f52bdc20e9a9f251e79769.zip |
Adding upstream version 1.33.0.upstream/1.33.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/rules/test_common.py')
-rw-r--r-- | tests/rules/test_common.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/rules/test_common.py b/tests/rules/test_common.py new file mode 100644 index 0000000..196b419 --- /dev/null +++ b/tests/rules/test_common.py @@ -0,0 +1,43 @@ +# 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) |