quoted-strings: Update test_allow_quoted_quotes()
Use explicit YAML blocks instead of loops. It allows easy and reliable visual check of what we expect for correct/wrong YAML code.
This commit is contained in:
@@ -455,33 +455,104 @@ class QuotedTestCase(RuleTestCase):
|
|||||||
problem1=(9, 3), problem2=(10, 3))
|
problem1=(9, 3), problem2=(10, 3))
|
||||||
|
|
||||||
def test_allow_quoted_quotes(self):
|
def test_allow_quoted_quotes(self):
|
||||||
for quote_type in ['single', 'double']:
|
conf = ('quoted-strings: {quote-type: single,\n'
|
||||||
for required in ['true', 'false', 'only-when-needed']:
|
' required: false,\n'
|
||||||
for allow_quoted_quotes in ['true', 'false']:
|
' allow-quoted-quotes: false}\n')
|
||||||
conf = ('quoted-strings: {quote-type: %s,\n'
|
self.check('---\n'
|
||||||
' required: %s,\n'
|
'foo1: "[barbaz]"\n' # fails
|
||||||
' allow-quoted-quotes: %s}\n') % (
|
'foo2: "[bar\'baz]"\n', # fails
|
||||||
quote_type, required, allow_quoted_quotes)
|
conf, problem1=(2, 7), problem2=(3, 7))
|
||||||
|
|
||||||
wrong_token_style = "'" if quote_type == 'double' else '"'
|
conf = ('quoted-strings: {quote-type: single,\n'
|
||||||
right_token_style = '"' if quote_type == 'double' else "'"
|
' required: false,\n'
|
||||||
|
' allow-quoted-quotes: true}\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'foo1: "[barbaz]"\n' # fails
|
||||||
|
'foo2: "[bar\'baz]"\n',
|
||||||
|
conf, problem1=(2, 7))
|
||||||
|
|
||||||
# 'fooX' value is in square brackets to avoid
|
conf = ('quoted-strings: {quote-type: single,\n'
|
||||||
# 'redundantly quoted' error
|
' required: true,\n'
|
||||||
# in 'required: only-when-needed' mode
|
' allow-quoted-quotes: false}\n')
|
||||||
yaml_to_check = ('---\n'
|
self.check('---\n'
|
||||||
# `foo1: "[barbaz]"` `foo1: '[barbaz]'`
|
'foo1: "[barbaz]"\n' # fails
|
||||||
'foo1: %(w)c[barbaz]%(w)c\n'
|
'foo2: "[bar\'baz]"\n', # fails
|
||||||
# `foo1: "[bar'baz]"` `foo1: '[bar"baz]'`
|
conf, problem1=(2, 7), problem2=(3, 7))
|
||||||
'foo2: %(w)c[bar%(r)cbaz]%(w)c\n'
|
|
||||||
) % {'w': wrong_token_style,
|
|
||||||
'r': right_token_style}
|
|
||||||
|
|
||||||
if allow_quoted_quotes == 'false':
|
conf = ('quoted-strings: {quote-type: single,\n'
|
||||||
self.check(yaml_to_check,
|
' required: true,\n'
|
||||||
conf,
|
' allow-quoted-quotes: true}\n')
|
||||||
problem1=(2, 7),
|
self.check('---\n'
|
||||||
problem2=(3, 7))
|
'foo1: "[barbaz]"\n' # fails
|
||||||
else:
|
'foo2: "[bar\'baz]"\n',
|
||||||
self.check(yaml_to_check,
|
conf, problem1=(2, 7))
|
||||||
conf, problem1=(2, 7))
|
|
||||||
|
conf = ('quoted-strings: {quote-type: single,\n'
|
||||||
|
' required: only-when-needed,\n'
|
||||||
|
' allow-quoted-quotes: false}\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'foo1: "[barbaz]"\n' # fails
|
||||||
|
'foo2: "[bar\'baz]"\n', # fails
|
||||||
|
conf, problem1=(2, 7), problem2=(3, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: single,\n'
|
||||||
|
' required: only-when-needed,\n'
|
||||||
|
' allow-quoted-quotes: true}\n')
|
||||||
|
self.check('---\n'
|
||||||
|
'foo1: "[barbaz]"\n' # fails
|
||||||
|
'foo2: "[bar\'baz]"\n',
|
||||||
|
conf, problem1=(2, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: double,\n'
|
||||||
|
' required: false,\n'
|
||||||
|
' allow-quoted-quotes: false}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n" # fails
|
||||||
|
"foo2: '[bar\"baz]'\n", # fails
|
||||||
|
conf, problem1=(2, 7), problem2=(3, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: double,\n'
|
||||||
|
' required: false,\n'
|
||||||
|
' allow-quoted-quotes: true}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n" # fails
|
||||||
|
"foo2: '[bar\"baz]'\n",
|
||||||
|
conf, problem1=(2, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: double,\n'
|
||||||
|
' required: true,\n'
|
||||||
|
' allow-quoted-quotes: false}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n" # fails
|
||||||
|
"foo2: '[bar\"baz]'\n", # fails
|
||||||
|
conf, problem1=(2, 7), problem2=(3, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: double,\n'
|
||||||
|
' required: true,\n'
|
||||||
|
' allow-quoted-quotes: true}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n" # fails
|
||||||
|
"foo2: '[bar\"baz]'\n",
|
||||||
|
conf, problem1=(2, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: double,\n'
|
||||||
|
' required: only-when-needed,\n'
|
||||||
|
' allow-quoted-quotes: false}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n" # fails
|
||||||
|
"foo2: '[bar\"baz]'\n", # fails
|
||||||
|
conf, problem1=(2, 7), problem2=(3, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: double,\n'
|
||||||
|
' required: only-when-needed,\n'
|
||||||
|
' allow-quoted-quotes: true}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n" # fails
|
||||||
|
"foo2: '[bar\"baz]'\n",
|
||||||
|
conf, problem1=(2, 7))
|
||||||
|
|
||||||
|
conf = ('quoted-strings: {quote-type: any}\n')
|
||||||
|
self.check("---\n"
|
||||||
|
"foo1: '[barbaz]'\n"
|
||||||
|
"foo2: '[bar\"baz]'\n",
|
||||||
|
conf)
|
||||||
|
|||||||
Reference in New Issue
Block a user