test: add test cases for YAML block scalar with inconsistent and insufficient indentation

This commit is contained in:
jwsong98
2025-05-22 02:29:05 +09:00
parent 20e69c3530
commit f10c389406

View File

@ -139,3 +139,82 @@ code_suggestions:
'improved_code': 'const router = createBrowserRouter([\n'
}]}
assert try_fix_yaml(review_text, first_key='code_suggestions', last_key='improved_code') == expected_output
def test_inconsistent_indentation_in_block_scalar_yaml(self):
"""
This test case represents a situation where the AI outputs the opening '{' with 5 spaces
(resulting in an inferred indent level of 5), while the closing '}' is output with only 4 spaces.
This inconsistency makes it impossible for the YAML parser to automatically determine the correct
indent level, causing a parsing failure.
The root cause may be the LLM miscounting spaces or misunderstanding the active block scalar context
while generating YAML output.
"""
review_text = '''\
code_suggestions:
- relevant_file: |
tsconfig.json
existing_code: |
{
"key1": "value1",
"key2": {
"subkey": "value"
}
}
'''
expected_json = '''\
{
"key1": "value1",
"key2": {
"subkey": "value"
}
}
'''
expected_output = {
'code_suggestions': [{
'relevant_file': 'tsconfig.json\n',
'existing_code': expected_json
}]
}
assert try_fix_yaml(review_text, first_key='code_suggestions', last_key='existing_code') == expected_output
def test_inconsistent_and_insufficient_indentation_in_block_scalar_yaml(self):
"""
This test case reproduces a YAML parsing failure where the block scalar content
generated by the AI includes inconsistent and insufficient indentation levels.
The root cause may be the LLM miscounting spaces or misunderstanding the active block scalar context
while generating YAML output.
"""
review_text = '''\
code_suggestions:
- relevant_file: |
tsconfig.json
existing_code: |
{
"key1": "value1",
"key2": {
"subkey": "value"
}
}
'''
expected_json = '''\
{
"key1": "value1",
"key2": {
"subkey": "value"
}
}
'''
expected_output = {
'code_suggestions': [{
'relevant_file': 'tsconfig.json\n',
'existing_code': expected_json
}]
}
assert try_fix_yaml(review_text, first_key='code_suggestions', last_key='existing_code') == expected_output