@@ -393,6 +393,63 @@ def test_case_handling(tmpdir, capsys):
393393 assert f .read ().decode ('utf-8' ) == 'this has an ASCII error'
394394
395395
396+ def _helper_test_case_handling_in_fixes (tmpdir , capsys , reason ):
397+ d = str (tmpdir )
398+
399+ with open (op .join (d , 'dictionary.txt' ), 'w' ) as f :
400+ if reason :
401+ f .write ('adoptor->adopter, adaptor, reason\n ' )
402+ else :
403+ f .write ('adoptor->adopter, adaptor,\n ' )
404+ dictionary_name = f .name
405+
406+ # the mispelled word is entirely lowercase
407+ with open (op .join (d , 'bad.txt' ), 'w' ) as f :
408+ f .write ('early adoptor\n ' )
409+ code , stdout , _ = cs .main ('-D' , dictionary_name , f .name , std = True )
410+ # all suggested fixes must be lowercase too
411+ assert 'adopter, adaptor' in stdout
412+ # the reason, if any, must not be modified
413+ if reason :
414+ assert 'reason' in stdout
415+
416+ # the mispelled word is capitalized
417+ with open (op .join (d , 'bad.txt' ), 'w' ) as f :
418+ f .write ('Early Adoptor\n ' )
419+ code , stdout , _ = cs .main ('-D' , dictionary_name , f .name , std = True )
420+ # all suggested fixes must be capitalized too
421+ assert 'Adopter, Adaptor' in stdout
422+ # the reason, if any, must not be modified
423+ if reason :
424+ assert 'reason' in stdout
425+
426+ # the mispelled word is entirely uppercase
427+ with open (op .join (d , 'bad.txt' ), 'w' ) as f :
428+ f .write ('EARLY ADOPTOR\n ' )
429+ code , stdout , _ = cs .main ('-D' , dictionary_name , f .name , std = True )
430+ # all suggested fixes must be uppercase too
431+ assert 'ADOPTER, ADAPTOR' in stdout
432+ # the reason, if any, must not be modified
433+ if reason :
434+ assert 'reason' in stdout
435+
436+ # the mispelled word mixes lowercase and uppercase
437+ with open (op .join (d , 'bad.txt' ), 'w' ) as f :
438+ f .write ('EaRlY AdOpToR\n ' )
439+ code , stdout , _ = cs .main ('-D' , dictionary_name , f .name , std = True )
440+ # all suggested fixes should be lowercase
441+ assert 'adopter, adaptor' in stdout
442+ # the reason, if any, must not be modified
443+ if reason :
444+ assert 'reason' in stdout
445+
446+
447+ def test_case_handling_in_fixes (tmpdir , capsys ):
448+ """Test that the case of fixes is similar to the mispelled word."""
449+ _helper_test_case_handling_in_fixes (tmpdir , capsys , reason = False )
450+ _helper_test_case_handling_in_fixes (tmpdir , capsys , reason = True )
451+
452+
396453def test_context (tmpdir , capsys ):
397454 """Test context options."""
398455 d = str (tmpdir )
0 commit comments