summaryrefslogtreecommitdiffstats
path: root/tests/rules/test_octal_values.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 00:38:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 00:38:50 +0000
commit09e7b47bad7e7310a6f52bdc20e9a9f251e79769 (patch)
treec93d189c1318902b8f1e5333d7ee34a1e9db9a34 /tests/rules/test_octal_values.py
parentInitial commit. (diff)
downloadyamllint-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_octal_values.py')
-rw-r--r--tests/rules/test_octal_values.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/rules/test_octal_values.py b/tests/rules/test_octal_values.py
new file mode 100644
index 0000000..be5b039
--- /dev/null
+++ b/tests/rules/test_octal_values.py
@@ -0,0 +1,80 @@
+# 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/>.
+
+from tests.common import RuleTestCase
+
+
+class OctalValuesTestCase(RuleTestCase):
+ rule_id = 'octal-values'
+
+ def test_disabled(self):
+ conf = ('octal-values: disable\n'
+ 'new-line-at-end-of-file: disable\n'
+ 'document-start: disable\n')
+ self.check('user-city: 010', conf)
+ self.check('user-city: 0o10', conf)
+
+ def test_implicit_octal_values(self):
+ conf = ('octal-values:\n'
+ ' forbid-implicit-octal: true\n'
+ ' forbid-explicit-octal: false\n'
+ 'new-line-at-end-of-file: disable\n'
+ 'document-start: disable\n')
+ self.check('after-tag: !custom_tag 010', conf)
+ self.check('user-city: 010', conf, problem=(1, 15))
+ self.check('user-city: abc', conf)
+ self.check('user-city: 010,0571', conf)
+ self.check("user-city: '010'", conf)
+ self.check('user-city: "010"', conf)
+ self.check('user-city:\n'
+ ' - 010', conf, problem=(2, 8))
+ self.check('user-city: [010]', conf, problem=(1, 16))
+ self.check('user-city: {beijing: 010}', conf, problem=(1, 25))
+ self.check('explicit-octal: 0o10', conf)
+ self.check('not-number: 0abc', conf)
+ self.check('zero: 0', conf)
+ self.check('hex-value: 0x10', conf)
+ self.check('number-values:\n'
+ ' - 0.10\n'
+ ' - .01\n'
+ ' - 0e3\n', conf)
+ self.check('with-decimal-digits: 012345678', conf)
+ self.check('with-decimal-digits: 012345679', conf)
+
+ def test_explicit_octal_values(self):
+ conf = ('octal-values:\n'
+ ' forbid-implicit-octal: false\n'
+ ' forbid-explicit-octal: true\n'
+ 'new-line-at-end-of-file: disable\n'
+ 'document-start: disable\n')
+ self.check('user-city: 0o10', conf, problem=(1, 16))
+ self.check('user-city: abc', conf)
+ self.check('user-city: 0o10,0571', conf)
+ self.check("user-city: '0o10'", conf)
+ self.check('user-city:\n'
+ ' - 0o10', conf, problem=(2, 9))
+ self.check('user-city: [0o10]', conf, problem=(1, 17))
+ self.check('user-city: {beijing: 0o10}', conf, problem=(1, 26))
+ self.check('implicit-octal: 010', conf)
+ self.check('not-number: 0oabc', conf)
+ self.check('zero: 0', conf)
+ self.check('hex-value: 0x10', conf)
+ self.check('number-values:\n'
+ ' - 0.10\n'
+ ' - .01\n'
+ ' - 0e3\n', conf)
+ self.check('user-city: "010"', conf)
+ self.check('with-decimal-digits: 0o012345678', conf)
+ self.check('with-decimal-digits: 0o012345679', conf)