diff --git a/tests/rules/test_quoted_strings.py b/tests/rules/test_quoted_strings.py index 9c81d82..9d0b7e1 100644 --- a/tests/rules/test_quoted_strings.py +++ b/tests/rules/test_quoted_strings.py @@ -453,3 +453,35 @@ class QuotedTestCase(RuleTestCase): '- "0o800"\n', conf, problem1=(9, 3), problem2=(10, 3)) + + def test_allow_quoted_quotes(self): + for quote_type in ['single', 'double']: + for required in ['true', 'false', 'only-when-needed']: + for allow_quoted_quotes in ['true', 'false']: + conf = ('quoted-strings: {quote-type: %s,\n' + ' required: %s,\n' + ' allow-quoted-quotes: %s}\n') % ( + quote_type, required, allow_quoted_quotes) + + wrong_token_style = "'" if quote_type == 'double' else '"' + right_token_style = '"' if quote_type == 'double' else "'" + + # 'fooX' value is in square brackets to avoid + # 'redundantly quoted' error + # in 'required: only-when-needed' mode + yaml_to_check = ('---\n' + # `foo1: "[barbaz]"` `foo1: '[barbaz]'` + 'foo1: %(w)c[barbaz]%(w)c\n' + # `foo1: "[bar'baz]"` `foo1: '[bar"baz]'` + 'foo2: %(w)c[bar%(r)cbaz]%(w)c\n' + ) % {'w': wrong_token_style, + 'r': right_token_style} + + if allow_quoted_quotes == 'false': + self.check(yaml_to_check, + conf, + problem1=(2, 7), + problem2=(3, 7)) + else: + self.check(yaml_to_check, + conf, problem1=(2, 7))