Repository: codespell-project/codespell

Issue:
Missing capitalization with more than one suggested fix
With this example file:
```sh
$ cat > file
Abourt time!
$ 
```
Here is the current output:
```
file:1: Abourt ==> Abort, about
```
Here is the output I would expect:
```
file:1: Abourt ==> Abort, About
```
Note the missing capitalization of the second (and subsequent) suggested fix `about`.


Discussion:

Resolving patch:
diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py
--- a/codespell_lib/_codespell.py
+++ b/codespell_lib/_codespell.py
@@ -495,7 +495,7 @@ def is_text_file(filename):
 
 def fix_case(word, fixword):
     if word == word.capitalize():
-        return fixword.capitalize()
+        return ', '.join(w.strip().capitalize() for w in fixword.split(','))
     elif word == word.upper():
         return fixword.upper()
     # they are both lower case
@@ -528,7 +528,7 @@ def ask_for_word_fix(line, wrongword, misspelling, interactivity):
         # we ask the user which word to use
 
         r = ''
-        opt = list(map(lambda x: x.strip(), misspelling.data.split(',')))
+        opt = [w.strip() for w in misspelling.data.split(',')]
         while not r:
             print("%s Choose an option (blank for none): " % line, end='')
             for i in range(len(opt)):


Test patch:
diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py
--- a/codespell_lib/tests/test_basic.py
+++ b/codespell_lib/tests/test_basic.py
@@ -393,6 +393,63 @@ def test_case_handling(tmpdir, capsys):
         assert f.read().decode('utf-8') == 'this has an ASCII error'
 
 
+def _helper_test_case_handling_in_fixes(tmpdir, capsys, reason):
+    d = str(tmpdir)
+
+    with open(op.join(d, 'dictionary.txt'), 'w') as f:
+        if reason:
+            f.write('adoptor->adopter, adaptor, reason\n')
+        else:
+            f.write('adoptor->adopter, adaptor,\n')
+    dictionary_name = f.name
+
+    # the mispelled word is entirely lowercase
+    with open(op.join(d, 'bad.txt'), 'w') as f:
+        f.write('early adoptor\n')
+    code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
+    # all suggested fixes must be lowercase too
+    assert 'adopter, adaptor' in stdout
+    # the reason, if any, must not be modified
+    if reason:
+        assert 'reason' in stdout
+
+    # the mispelled word is capitalized
+    with open(op.join(d, 'bad.txt'), 'w') as f:
+        f.write('Early Adoptor\n')
+    code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
+    # all suggested fixes must be capitalized too
+    assert 'Adopter, Adaptor' in stdout
+    # the reason, if any, must not be modified
+    if reason:
+        assert 'reason' in stdout
+
+    # the mispelled word is entirely uppercase
+    with open(op.join(d, 'bad.txt'), 'w') as f:
+        f.write('EARLY ADOPTOR\n')
+    code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
+    # all suggested fixes must be uppercase too
+    assert 'ADOPTER, ADAPTOR' in stdout
+    # the reason, if any, must not be modified
+    if reason:
+        assert 'reason' in stdout
+
+    # the mispelled word mixes lowercase and uppercase
+    with open(op.join(d, 'bad.txt'), 'w') as f:
+        f.write('EaRlY AdOpToR\n')
+    code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
+    # all suggested fixes should be lowercase
+    assert 'adopter, adaptor' in stdout
+    # the reason, if any, must not be modified
+    if reason:
+        assert 'reason' in stdout
+
+
+def test_case_handling_in_fixes(tmpdir, capsys):
+    """Test that the case of fixes is similar to the mispelled word."""
+    _helper_test_case_handling_in_fixes(tmpdir, capsys, reason=False)
+    _helper_test_case_handling_in_fixes(tmpdir, capsys, reason=True)
+
+
 def test_context(tmpdir, capsys):
     """Test context options."""
     d = str(tmpdir)