mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-22 13:25:00 +00:00
test: Add tests for ensure_hash_prefix and color initialization
This commit is contained in:
parent
59eabf03a6
commit
81d39e9bde
1 changed files with 62 additions and 0 deletions
|
@ -34,6 +34,43 @@ class TestInputOutput(unittest.TestCase):
|
|||
io = InputOutput(fancy_input=False)
|
||||
self.assertFalse(io.pretty)
|
||||
|
||||
def test_color_initialization(self):
|
||||
"""Test that color values are properly initialized with # prefix"""
|
||||
# Test with hex colors without #
|
||||
io = InputOutput(
|
||||
user_input_color="00cc00",
|
||||
tool_error_color="FF2222",
|
||||
tool_warning_color="FFA500",
|
||||
assistant_output_color="0088ff",
|
||||
pretty=True
|
||||
)
|
||||
|
||||
# Check that # was added to hex colors
|
||||
self.assertEqual(io.user_input_color, "#00cc00")
|
||||
self.assertEqual(io.tool_error_color, "#FF2222")
|
||||
self.assertEqual(io.tool_warning_color, "#FFA500") # Already had #
|
||||
self.assertEqual(io.assistant_output_color, "#0088ff")
|
||||
|
||||
# Test with named colors (should be unchanged)
|
||||
io = InputOutput(
|
||||
user_input_color="blue",
|
||||
tool_error_color="red",
|
||||
pretty=True
|
||||
)
|
||||
|
||||
self.assertEqual(io.user_input_color, "blue")
|
||||
self.assertEqual(io.tool_error_color, "red")
|
||||
|
||||
# Test with pretty=False (should not modify colors)
|
||||
io = InputOutput(
|
||||
user_input_color="00cc00",
|
||||
tool_error_color="FF2222",
|
||||
pretty=False
|
||||
)
|
||||
|
||||
self.assertIsNone(io.user_input_color)
|
||||
self.assertIsNone(io.tool_error_color)
|
||||
|
||||
def test_dumb_terminal(self):
|
||||
with patch.dict(os.environ, {"TERM": "dumb"}):
|
||||
io = InputOutput(fancy_input=True)
|
||||
|
@ -393,6 +430,31 @@ class TestInputOutputMultilineMode(unittest.TestCase):
|
|||
io.prompt_ask("Test prompt?")
|
||||
self.assertTrue(io.multiline_mode) # Should be restored
|
||||
|
||||
def test_ensure_hash_prefix(self):
|
||||
"""Test that ensure_hash_prefix correctly adds # to valid hex colors"""
|
||||
from aider.io import ensure_hash_prefix
|
||||
|
||||
# Test valid hex colors without #
|
||||
self.assertEqual(ensure_hash_prefix("000"), "#000")
|
||||
self.assertEqual(ensure_hash_prefix("fff"), "#fff")
|
||||
self.assertEqual(ensure_hash_prefix("F00"), "#F00")
|
||||
self.assertEqual(ensure_hash_prefix("123456"), "#123456")
|
||||
self.assertEqual(ensure_hash_prefix("abcdef"), "#abcdef")
|
||||
self.assertEqual(ensure_hash_prefix("ABCDEF"), "#ABCDEF")
|
||||
|
||||
# Test hex colors that already have #
|
||||
self.assertEqual(ensure_hash_prefix("#000"), "#000")
|
||||
self.assertEqual(ensure_hash_prefix("#123456"), "#123456")
|
||||
|
||||
# Test invalid inputs (should return unchanged)
|
||||
self.assertEqual(ensure_hash_prefix(""), "")
|
||||
self.assertEqual(ensure_hash_prefix(None), None)
|
||||
self.assertEqual(ensure_hash_prefix("red"), "red") # Named color
|
||||
self.assertEqual(ensure_hash_prefix("12345"), "12345") # Wrong length
|
||||
self.assertEqual(ensure_hash_prefix("1234567"), "1234567") # Wrong length
|
||||
self.assertEqual(ensure_hash_prefix("xyz"), "xyz") # Invalid hex chars
|
||||
self.assertEqual(ensure_hash_prefix("12345g"), "12345g") # Invalid hex chars
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue